[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
| 9 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 11 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 16 | #include "base/json/json_writer.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 17 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 18 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 19 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 20 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 21 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 22 | #include "base/test/test_file_util.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 23 | #include "net/base/auth.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 24 | #include "net/base/capturing_net_log.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 25 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 26 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 27 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 28 | #include "net/base/load_timing_info.h" |
| 29 | #include "net/base/load_timing_info_test_util.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 30 | #include "net/base/net_log.h" |
| 31 | #include "net/base/net_log_unittest.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 32 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 33 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 34 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 35 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 36 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 37 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 38 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 39 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 40 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 41 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 42 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_ntlm.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 44 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 45 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 46 | #include "net/http/http_network_session_peer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 47 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 49 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 50 | #include "net/http/http_transaction_test_util.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 51 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 52 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 53 | #include "net/proxy/proxy_resolver.h" |
| 54 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 55 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 56 | #include "net/socket/client_socket_pool_manager.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 57 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 58 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 59 | #include "net/socket/socket_test_util.h" |
| 60 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 61 | #include "net/spdy/spdy_framer.h" |
| 62 | #include "net/spdy/spdy_session.h" |
| 63 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 64 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 65 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 66 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 67 | #include "net/ssl/ssl_config_service_defaults.h" |
| 68 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 69 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 70 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 71 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 72 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 73 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 74 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 75 | using base::ASCIIToUTF16; |
| 76 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 77 | //----------------------------------------------------------------------------- |
| 78 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 79 | namespace { |
| 80 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 81 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 82 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 83 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 84 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 85 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 86 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 87 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 88 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 89 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 90 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 91 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 92 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 93 | |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 94 | int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { |
| 95 | return session->GetTransportSocketPool( |
| 96 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 97 | } |
| 98 | |
| 99 | int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) { |
| 100 | return session->GetSSLSocketPool( |
| 101 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 102 | } |
| 103 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 104 | bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) { |
| 105 | return session->GetTransportSocketPool( |
| 106 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled(); |
| 107 | } |
| 108 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 109 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 110 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 111 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 112 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 113 | if (!params) |
| 114 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 115 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 116 | if (!params->GetList("headers", &header_list)) |
| 117 | return false; |
| 118 | std::string double_quote_headers; |
| 119 | base::JSONWriter::Write(header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 120 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 121 | return true; |
| 122 | } |
| 123 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 124 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 125 | // used. |
| 126 | void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) { |
| 127 | EXPECT_TRUE(load_timing_info.socket_reused); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 128 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 129 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 130 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 131 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 132 | |
| 133 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 134 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 135 | |
| 136 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 137 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 138 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 139 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 140 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 141 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 144 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 145 | // used. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 146 | void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info, |
| 147 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 148 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 149 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 150 | |
| 151 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 152 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 153 | |
| 154 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 155 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 157 | load_timing_info.send_start); |
| 158 | |
| 159 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 160 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 161 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 163 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 164 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 168 | // used. |
| 169 | void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) { |
| 170 | EXPECT_TRUE(load_timing_info.socket_reused); |
| 171 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 172 | |
| 173 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 174 | |
| 175 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 176 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 177 | load_timing_info.proxy_resolve_end); |
| 178 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 179 | load_timing_info.send_start); |
| 180 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 181 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 182 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 183 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 184 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 185 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 189 | // used. |
| 190 | void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info, |
| 191 | int connect_timing_flags) { |
| 192 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 193 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 194 | |
| 195 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 196 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 197 | load_timing_info.proxy_resolve_end); |
| 198 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 199 | load_timing_info.connect_timing.connect_start); |
| 200 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 201 | connect_timing_flags); |
| 202 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 203 | load_timing_info.send_start); |
| 204 | |
| 205 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 207 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 209 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 210 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 213 | } // namespace |
| 214 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 215 | namespace net { |
| 216 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 217 | namespace { |
| 218 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 219 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 220 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 223 | } // namespace |
| 224 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 225 | class HttpNetworkTransactionTest |
| 226 | : public PlatformTest, |
| 227 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 228 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 229 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 230 | // Important to restore the per-pool limit first, since the pool limit must |
| 231 | // always be greater than group limit, and the tests reduce both limits. |
| 232 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 233 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 234 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 235 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 236 | } |
| 237 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 238 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 239 | HttpNetworkTransactionTest() |
| 240 | : spdy_util_(GetParam()), |
| 241 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 242 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 243 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 244 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 245 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 246 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 247 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 248 | struct SimpleGetHelperResult { |
| 249 | int rv; |
| 250 | std::string status_line; |
| 251 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 252 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 253 | LoadTimingInfo load_timing_info; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 254 | }; |
| 255 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame^] | 256 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 257 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 258 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 259 | } |
| 260 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame^] | 261 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 262 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 263 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 264 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 265 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 266 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 267 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 268 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 271 | // This is the expected return from a current server advertising SPDY. |
| 272 | std::string GetAlternateProtocolHttpHeader() { |
| 273 | return |
| 274 | std::string("Alternate-Protocol: 443:") + |
| 275 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())) + |
| 276 | "\r\n\r\n"; |
| 277 | } |
| 278 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 279 | // Either |write_failure| specifies a write failure or |read_failure| |
| 280 | // specifies a read failure when using a reused socket. In either case, the |
| 281 | // failure should cause the network transaction to resend the request, and the |
| 282 | // other argument should be NULL. |
| 283 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 284 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 285 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 286 | // Either |write_failure| specifies a write failure or |read_failure| |
| 287 | // specifies a read failure when using a reused socket. In either case, the |
| 288 | // failure should cause the network transaction to resend the request, and the |
| 289 | // other argument should be NULL. |
| 290 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 291 | const MockRead* read_failure, |
| 292 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 293 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 294 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 295 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 296 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 297 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 298 | HttpRequestInfo request; |
| 299 | request.method = "GET"; |
| 300 | request.url = GURL("http://www.google.com/"); |
| 301 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 302 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 303 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 304 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 305 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 306 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 308 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 309 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 310 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 311 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 313 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 314 | |
[email protected] | c47c037 | 2014-03-12 23:07:02 | [diff] [blame] | 315 | EXPECT_TRUE(log.bound().IsLogging()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 316 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 317 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 318 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 319 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 320 | |
| 321 | // Even in the failure cases that use this function, connections are always |
| 322 | // successfully established before the error. |
| 323 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 324 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 325 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 326 | if (out.rv != OK) |
| 327 | return out; |
| 328 | |
| 329 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 330 | // Can't use ASSERT_* inside helper functions like this, so |
| 331 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 332 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 333 | out.rv = ERR_UNEXPECTED; |
| 334 | return out; |
| 335 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 336 | out.status_line = response->headers->GetStatusLine(); |
| 337 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 338 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 339 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 340 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 341 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 342 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 343 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 344 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 345 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 346 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 347 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 348 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 349 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 350 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 351 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 352 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 354 | std::string line; |
| 355 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 356 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 357 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 358 | HttpRequestHeaders request_headers; |
| 359 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 360 | std::string value; |
| 361 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
| 362 | EXPECT_EQ("www.google.com", value); |
| 363 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 364 | EXPECT_EQ("keep-alive", value); |
| 365 | |
| 366 | std::string response_headers; |
| 367 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
| 368 | EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", |
| 369 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 370 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 371 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 372 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 373 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 374 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 375 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 376 | size_t reads_count) { |
| 377 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 378 | StaticSocketDataProvider* data[] = { &reads }; |
| 379 | return SimpleGetHelperForData(data, 1); |
| 380 | } |
| 381 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 382 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 383 | int64 size = 0; |
| 384 | for (size_t i = 0; i < reads_count; ++i) |
| 385 | size += data_reads[i].data_len; |
| 386 | return size; |
| 387 | } |
| 388 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 389 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 390 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 391 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 392 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 393 | |
| 394 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 395 | |
| 396 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 397 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 398 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 399 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 400 | |
| 401 | // Original socket limits. Some tests set these. Safest to always restore |
| 402 | // them once each test has been run. |
| 403 | int old_max_group_sockets_; |
| 404 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 405 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 406 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 407 | INSTANTIATE_TEST_CASE_P( |
| 408 | NextProto, |
| 409 | HttpNetworkTransactionTest, |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 410 | testing::Values(kProtoDeprecatedSPDY2, |
[email protected] | d10833bc | 2014-04-14 17:50:46 | [diff] [blame] | 411 | kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 412 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 413 | namespace { |
| 414 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 415 | class BeforeNetworkStartHandler { |
| 416 | public: |
| 417 | explicit BeforeNetworkStartHandler(bool defer) |
| 418 | : defer_on_before_network_start_(defer), |
| 419 | observed_before_network_start_(false) {} |
| 420 | |
| 421 | void OnBeforeNetworkStart(bool* defer) { |
| 422 | *defer = defer_on_before_network_start_; |
| 423 | observed_before_network_start_ = true; |
| 424 | } |
| 425 | |
| 426 | bool observed_before_network_start() const { |
| 427 | return observed_before_network_start_; |
| 428 | } |
| 429 | |
| 430 | private: |
| 431 | const bool defer_on_before_network_start_; |
| 432 | bool observed_before_network_start_; |
| 433 | |
| 434 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 435 | }; |
| 436 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 437 | class BeforeProxyHeadersSentHandler { |
| 438 | public: |
| 439 | BeforeProxyHeadersSentHandler() |
| 440 | : observed_before_proxy_headers_sent_(false) {} |
| 441 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 442 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 443 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 444 | observed_before_proxy_headers_sent_ = true; |
| 445 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 446 | } |
| 447 | |
| 448 | bool observed_before_proxy_headers_sent() const { |
| 449 | return observed_before_proxy_headers_sent_; |
| 450 | } |
| 451 | |
| 452 | std::string observed_proxy_server_uri() const { |
| 453 | return observed_proxy_server_uri_; |
| 454 | } |
| 455 | |
| 456 | private: |
| 457 | bool observed_before_proxy_headers_sent_; |
| 458 | std::string observed_proxy_server_uri_; |
| 459 | |
| 460 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 461 | }; |
| 462 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 463 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 464 | void FillLargeHeadersString(std::string* str, int size) { |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 465 | const char* row = |
| 466 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 467 | const int sizeof_row = strlen(row); |
| 468 | const int num_rows = static_cast<int>( |
| 469 | ceil(static_cast<float>(size) / sizeof_row)); |
| 470 | const int sizeof_data = num_rows * sizeof_row; |
| 471 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 472 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 473 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 474 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 475 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 478 | // Alternative functions that eliminate randomness and dependency on the local |
| 479 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 480 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 481 | static const uint8 bytes[] = { |
| 482 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 483 | }; |
| 484 | static size_t current_byte = 0; |
| 485 | for (size_t i = 0; i < n; ++i) { |
| 486 | output[i] = bytes[current_byte++]; |
| 487 | current_byte %= arraysize(bytes); |
| 488 | } |
| 489 | } |
| 490 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 491 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 492 | static const uint8 bytes[] = { |
| 493 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 494 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 495 | }; |
| 496 | static size_t current_byte = 0; |
| 497 | for (size_t i = 0; i < n; ++i) { |
| 498 | output[i] = bytes[current_byte++]; |
| 499 | current_byte %= arraysize(bytes); |
| 500 | } |
| 501 | } |
| 502 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 503 | std::string MockGetHostName() { |
| 504 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 505 | } |
| 506 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 507 | template<typename ParentPool> |
| 508 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 509 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 510 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 511 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 512 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 513 | const std::string last_group_name_received() const { |
| 514 | return last_group_name_; |
| 515 | } |
| 516 | |
[email protected] | 684970b | 2009-08-14 04:54:46 | [diff] [blame] | 517 | virtual int RequestSocket(const std::string& group_name, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 518 | const void* socket_params, |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 519 | RequestPriority priority, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 520 | ClientSocketHandle* handle, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 521 | const CompletionCallback& callback, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 522 | const BoundNetLog& net_log) { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 523 | last_group_name_ = group_name; |
| 524 | return ERR_IO_PENDING; |
| 525 | } |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 526 | virtual void CancelRequest(const std::string& group_name, |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 527 | ClientSocketHandle* handle) {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 528 | virtual void ReleaseSocket(const std::string& group_name, |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 529 | scoped_ptr<StreamSocket> socket, |
[email protected] | 9f95c69 | 2011-02-11 19:20:19 | [diff] [blame] | 530 | int id) {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 531 | virtual void CloseIdleSockets() {} |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 532 | virtual int IdleSocketCount() const { |
| 533 | return 0; |
| 534 | } |
| 535 | virtual int IdleSocketCountInGroup(const std::string& group_name) const { |
| 536 | return 0; |
| 537 | } |
| 538 | virtual LoadState GetLoadState(const std::string& group_name, |
| 539 | const ClientSocketHandle* handle) const { |
| 540 | return LOAD_STATE_IDLE; |
| 541 | } |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 542 | virtual base::TimeDelta ConnectionTimeout() const { |
| 543 | return base::TimeDelta(); |
| 544 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 545 | |
| 546 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 547 | std::string last_group_name_; |
| 548 | }; |
| 549 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 550 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 551 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 552 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 553 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 554 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 555 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 556 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 557 | CaptureGroupNameSSLSocketPool; |
| 558 | |
| 559 | template<typename ParentPool> |
| 560 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 561 | HostResolver* host_resolver, |
| 562 | CertVerifier* /* cert_verifier */) |
| 563 | : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 564 | |
| 565 | template<> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 566 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 567 | HostResolver* host_resolver, |
| 568 | CertVerifier* /* cert_verifier */) |
bengr | 39e40610 | 2014-09-10 23:04:46 | [diff] [blame] | 569 | : HttpProxyClientSocketPool( |
| 570 | 0, 0, NULL, host_resolver, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 571 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 572 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 573 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 574 | HostResolver* host_resolver, |
| 575 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 576 | : SSLClientSocketPool(0, |
| 577 | 0, |
| 578 | NULL, |
| 579 | host_resolver, |
| 580 | cert_verifier, |
| 581 | NULL, |
| 582 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 583 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 584 | std::string(), |
| 585 | NULL, |
| 586 | NULL, |
| 587 | NULL, |
| 588 | NULL, |
| 589 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 590 | false, |
| 591 | NULL) { |
| 592 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 593 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 594 | //----------------------------------------------------------------------------- |
| 595 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 596 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 597 | // configured for common cases. |
| 598 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 599 | if (!auth_challenge) |
| 600 | return false; |
| 601 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 602 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 603 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 604 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 605 | return true; |
| 606 | } |
| 607 | |
| 608 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 609 | if (!auth_challenge) |
| 610 | return false; |
| 611 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 612 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 613 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 614 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 615 | return true; |
| 616 | } |
| 617 | |
| 618 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 619 | if (!auth_challenge) |
| 620 | return false; |
| 621 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 622 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 623 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 624 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 625 | return true; |
| 626 | } |
| 627 | |
| 628 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 629 | if (!auth_challenge) |
| 630 | return false; |
| 631 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 632 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 633 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 634 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 635 | return true; |
| 636 | } |
| 637 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 638 | } // namespace |
| 639 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 640 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 641 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 642 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 643 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 646 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 647 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 648 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 649 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 650 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 651 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 652 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 653 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 654 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 655 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 656 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 657 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 658 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 662 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 663 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 664 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 665 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 666 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 667 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 668 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 669 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 670 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 671 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 672 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 673 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 677 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 678 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 679 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 680 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 681 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 682 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 683 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 684 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 685 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 686 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 687 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 688 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 692 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 693 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 694 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 695 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 696 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 697 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 698 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 699 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 700 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 701 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 702 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 703 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | // Beyond 4 bytes of slop and it should fail to find a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 707 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 708 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 709 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 710 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 711 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 712 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 713 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 714 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 715 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 716 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 717 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 718 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 722 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 723 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 724 | MockRead("\n"), |
| 725 | MockRead("\n"), |
| 726 | MockRead("Q"), |
| 727 | MockRead("J"), |
| 728 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 729 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 730 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 731 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 732 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 733 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 734 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 735 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 736 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 737 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 741 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 742 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 743 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 744 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 745 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 746 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 747 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 748 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 750 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 751 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 752 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 753 | } |
| 754 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 755 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 756 | // persistent connection. The response should still terminate since a 204 |
| 757 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 758 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 759 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 760 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 761 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 762 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 763 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 764 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 765 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 766 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 767 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 768 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 769 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 770 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 771 | int64 response_size = reads_size - strlen(junk); |
| 772 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 773 | } |
| 774 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 775 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 776 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 777 | std::string final_chunk = "0\r\n\r\n"; |
| 778 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 779 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 780 | MockRead data_reads[] = { |
| 781 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 782 | MockRead("5\r\nHello\r\n"), |
| 783 | MockRead("1\r\n"), |
| 784 | MockRead(" \r\n"), |
| 785 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 786 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 788 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 789 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 790 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 791 | EXPECT_EQ(OK, out.rv); |
| 792 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 793 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 794 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 795 | int64 response_size = reads_size - extra_data.size(); |
| 796 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 797 | } |
| 798 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 799 | // Next tests deal with http://crbug.com/56344. |
| 800 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 801 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 802 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 803 | MockRead data_reads[] = { |
| 804 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 805 | MockRead("Content-Length: 10\r\n"), |
| 806 | MockRead("Content-Length: 5\r\n\r\n"), |
| 807 | }; |
| 808 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 809 | arraysize(data_reads)); |
| 810 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 811 | } |
| 812 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 813 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 814 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 815 | MockRead data_reads[] = { |
| 816 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 817 | MockRead("Content-Length: 5\r\n"), |
| 818 | MockRead("Content-Length: 5\r\n\r\n"), |
| 819 | MockRead("Hello"), |
| 820 | }; |
| 821 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 822 | arraysize(data_reads)); |
| 823 | EXPECT_EQ(OK, out.rv); |
| 824 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 825 | EXPECT_EQ("Hello", out.response_data); |
| 826 | } |
| 827 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 828 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 829 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 830 | // More than 2 dupes. |
| 831 | { |
| 832 | MockRead data_reads[] = { |
| 833 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 834 | MockRead("Content-Length: 5\r\n"), |
| 835 | MockRead("Content-Length: 5\r\n"), |
| 836 | MockRead("Content-Length: 5\r\n\r\n"), |
| 837 | MockRead("Hello"), |
| 838 | }; |
| 839 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 840 | arraysize(data_reads)); |
| 841 | EXPECT_EQ(OK, out.rv); |
| 842 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 843 | EXPECT_EQ("Hello", out.response_data); |
| 844 | } |
| 845 | // HTTP/1.0 |
| 846 | { |
| 847 | MockRead data_reads[] = { |
| 848 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 849 | MockRead("Content-Length: 5\r\n"), |
| 850 | MockRead("Content-Length: 5\r\n"), |
| 851 | MockRead("Content-Length: 5\r\n\r\n"), |
| 852 | MockRead("Hello"), |
| 853 | }; |
| 854 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 855 | arraysize(data_reads)); |
| 856 | EXPECT_EQ(OK, out.rv); |
| 857 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 858 | EXPECT_EQ("Hello", out.response_data); |
| 859 | } |
| 860 | // 2 dupes and one mismatched. |
| 861 | { |
| 862 | MockRead data_reads[] = { |
| 863 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 864 | MockRead("Content-Length: 10\r\n"), |
| 865 | MockRead("Content-Length: 10\r\n"), |
| 866 | MockRead("Content-Length: 5\r\n\r\n"), |
| 867 | }; |
| 868 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 869 | arraysize(data_reads)); |
| 870 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 871 | } |
| 872 | } |
| 873 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 874 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 875 | MultipleContentLengthHeadersTransferEncoding) { |
| 876 | MockRead data_reads[] = { |
| 877 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 878 | MockRead("Content-Length: 666\r\n"), |
| 879 | MockRead("Content-Length: 1337\r\n"), |
| 880 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 881 | MockRead("5\r\nHello\r\n"), |
| 882 | MockRead("1\r\n"), |
| 883 | MockRead(" \r\n"), |
| 884 | MockRead("5\r\nworld\r\n"), |
| 885 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 886 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 887 | }; |
| 888 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 889 | arraysize(data_reads)); |
| 890 | EXPECT_EQ(OK, out.rv); |
| 891 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 892 | EXPECT_EQ("Hello world", out.response_data); |
| 893 | } |
| 894 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 895 | // Next tests deal with http://crbug.com/98895. |
| 896 | |
| 897 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 898 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 899 | MockRead data_reads[] = { |
| 900 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 901 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 902 | MockRead("Content-Length: 5\r\n\r\n"), |
| 903 | MockRead("Hello"), |
| 904 | }; |
| 905 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 906 | arraysize(data_reads)); |
| 907 | EXPECT_EQ(OK, out.rv); |
| 908 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 909 | EXPECT_EQ("Hello", out.response_data); |
| 910 | } |
| 911 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 912 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 913 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 914 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 915 | MockRead data_reads[] = { |
| 916 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 917 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 918 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 919 | MockRead("Content-Length: 5\r\n\r\n"), |
| 920 | MockRead("Hello"), |
| 921 | }; |
| 922 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 923 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 924 | EXPECT_EQ(OK, out.rv); |
| 925 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 926 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 930 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 931 | MockRead data_reads[] = { |
| 932 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 933 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 934 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 935 | MockRead("Content-Length: 5\r\n\r\n"), |
| 936 | MockRead("Hello"), |
| 937 | }; |
| 938 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 939 | arraysize(data_reads)); |
| 940 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 941 | } |
| 942 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 943 | // Checks that two identical Location headers result in no error. |
| 944 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 945 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 946 | MockRead data_reads[] = { |
| 947 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 948 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 949 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 950 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 951 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 952 | }; |
| 953 | |
| 954 | HttpRequestInfo request; |
| 955 | request.method = "GET"; |
| 956 | request.url = GURL("http://redirect.com/"); |
| 957 | request.load_flags = 0; |
| 958 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 959 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 960 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 961 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 962 | |
| 963 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 964 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 966 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 968 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 969 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 970 | |
| 971 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 972 | |
| 973 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 974 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 975 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 976 | std::string url; |
| 977 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 978 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 979 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 982 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 983 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 984 | MockRead data_reads[] = { |
| 985 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 986 | MockRead("Location: http://good.com/\r\n"), |
| 987 | MockRead("Location: http://evil.com/\r\n"), |
| 988 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 989 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 990 | }; |
| 991 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 992 | arraysize(data_reads)); |
| 993 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 994 | } |
| 995 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 996 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 997 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 998 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 999 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1000 | request.method = "HEAD"; |
| 1001 | request.url = GURL("http://www.google.com/"); |
| 1002 | request.load_flags = 0; |
| 1003 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1004 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1005 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1007 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1008 | trans->SetBeforeProxyHeadersSentCallback( |
| 1009 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1010 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1011 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1012 | MockWrite data_writes1[] = { |
| 1013 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1014 | "Host: www.google.com\r\n" |
| 1015 | "Connection: keep-alive\r\n" |
| 1016 | "Content-Length: 0\r\n\r\n"), |
| 1017 | }; |
| 1018 | MockRead data_reads1[] = { |
| 1019 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1020 | MockRead("Server: Blah\r\n"), |
| 1021 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1022 | |
| 1023 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1024 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1025 | }; |
| 1026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1027 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1028 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1029 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1031 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1033 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1034 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1035 | |
| 1036 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1037 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1038 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1039 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1040 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1041 | |
| 1042 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1043 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1044 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1045 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1046 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1047 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1048 | |
| 1049 | std::string server_header; |
| 1050 | void* iter = NULL; |
| 1051 | bool has_server_header = response->headers->EnumerateHeader( |
| 1052 | &iter, "Server", &server_header); |
| 1053 | EXPECT_TRUE(has_server_header); |
| 1054 | EXPECT_EQ("Blah", server_header); |
| 1055 | |
| 1056 | // Reading should give EOF right away, since there is no message body |
| 1057 | // (despite non-zero content-length). |
| 1058 | std::string response_data; |
| 1059 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1060 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1061 | EXPECT_EQ("", response_data); |
| 1062 | } |
| 1063 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1064 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1065 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1066 | |
| 1067 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1068 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1069 | MockRead("hello"), |
| 1070 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1071 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1072 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1073 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1074 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1076 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1077 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1078 | "hello", "world" |
| 1079 | }; |
| 1080 | |
| 1081 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1082 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1083 | request.method = "GET"; |
| 1084 | request.url = GURL("http://www.google.com/"); |
| 1085 | request.load_flags = 0; |
| 1086 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1087 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1088 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1090 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1092 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1093 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1094 | |
| 1095 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1096 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1097 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1098 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1099 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1100 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1101 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1102 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1103 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1104 | |
| 1105 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1106 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1108 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1112 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1113 | ScopedVector<UploadElementReader> element_readers; |
| 1114 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1115 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1116 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1117 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1118 | request.method = "POST"; |
| 1119 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1120 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1121 | request.load_flags = 0; |
| 1122 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1123 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1124 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1126 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1127 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1128 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1129 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1130 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1131 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1132 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1136 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1138 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1139 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1140 | |
| 1141 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1142 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1143 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1145 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1146 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1147 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1148 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1149 | |
| 1150 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1151 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1152 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1153 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1154 | } |
| 1155 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1156 | // This test is almost the same as Ignores100 above, but the response contains |
| 1157 | // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1158 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1159 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1160 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1161 | request.method = "GET"; |
| 1162 | request.url = GURL("http://www.foo.com/"); |
| 1163 | request.load_flags = 0; |
| 1164 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1165 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1166 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1167 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1168 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1169 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1170 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1171 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1172 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1173 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1174 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1178 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1180 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1182 | |
| 1183 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1184 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1185 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1186 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1187 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1188 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1189 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1190 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1191 | |
| 1192 | std::string response_data; |
| 1193 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1194 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1195 | EXPECT_EQ("hello world", response_data); |
| 1196 | } |
| 1197 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1198 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1199 | HttpRequestInfo request; |
| 1200 | request.method = "POST"; |
| 1201 | request.url = GURL("http://www.foo.com/"); |
| 1202 | request.load_flags = 0; |
| 1203 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1204 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1205 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1206 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1207 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1208 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1209 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1210 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1211 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1212 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1215 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1217 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1218 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1219 | |
| 1220 | rv = callback.WaitForResult(); |
| 1221 | EXPECT_EQ(OK, rv); |
| 1222 | |
| 1223 | std::string response_data; |
| 1224 | rv = ReadTransaction(trans.get(), &response_data); |
| 1225 | EXPECT_EQ(OK, rv); |
| 1226 | EXPECT_EQ("", response_data); |
| 1227 | } |
| 1228 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1229 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1230 | HttpRequestInfo request; |
| 1231 | request.method = "POST"; |
| 1232 | request.url = GURL("http://www.foo.com/"); |
| 1233 | request.load_flags = 0; |
| 1234 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1235 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1236 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1237 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1238 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1239 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1240 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1241 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1242 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1243 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1245 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1247 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1249 | |
| 1250 | rv = callback.WaitForResult(); |
| 1251 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1252 | } |
| 1253 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1254 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1255 | const MockWrite* write_failure, |
| 1256 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1257 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1258 | request.method = "GET"; |
| 1259 | request.url = GURL("http://www.foo.com/"); |
| 1260 | request.load_flags = 0; |
| 1261 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1262 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1263 | session_deps_.net_log = &net_log; |
| 1264 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1265 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1266 | // Written data for successfully sending both requests. |
| 1267 | MockWrite data1_writes[] = { |
| 1268 | MockWrite("GET / HTTP/1.1\r\n" |
| 1269 | "Host: www.foo.com\r\n" |
| 1270 | "Connection: keep-alive\r\n\r\n"), |
| 1271 | MockWrite("GET / HTTP/1.1\r\n" |
| 1272 | "Host: www.foo.com\r\n" |
| 1273 | "Connection: keep-alive\r\n\r\n") |
| 1274 | }; |
| 1275 | |
| 1276 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1277 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1278 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1279 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1280 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1281 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1282 | |
| 1283 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1284 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1285 | data1_writes[1] = *write_failure; |
| 1286 | } else { |
| 1287 | ASSERT_TRUE(read_failure); |
| 1288 | data1_reads[2] = *read_failure; |
| 1289 | } |
| 1290 | |
| 1291 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1292 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1293 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | |
| 1295 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1296 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1297 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1298 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1300 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1301 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | |
| 1303 | const char* kExpectedResponseData[] = { |
| 1304 | "hello", "world" |
| 1305 | }; |
| 1306 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1307 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1308 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1309 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1311 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1312 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1314 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1315 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
| 1317 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1318 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1320 | LoadTimingInfo load_timing_info; |
| 1321 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1322 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1323 | if (i == 0) { |
| 1324 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1325 | } else { |
| 1326 | // The second request should be using a new socket. |
| 1327 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1328 | } |
| 1329 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1330 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1331 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1333 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1334 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1335 | |
| 1336 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1337 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1338 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1339 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1340 | } |
| 1341 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1342 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1343 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1344 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1345 | const MockRead* read_failure, |
| 1346 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1347 | HttpRequestInfo request; |
| 1348 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1349 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1350 | request.load_flags = 0; |
| 1351 | |
| 1352 | CapturingNetLog net_log; |
| 1353 | session_deps_.net_log = &net_log; |
| 1354 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1355 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1356 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1357 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1358 | if (use_spdy) { |
| 1359 | ssl1.SetNextProto(GetParam()); |
| 1360 | ssl2.SetNextProto(GetParam()); |
| 1361 | } |
| 1362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1364 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1365 | // SPDY versions of the request and response. |
| 1366 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1367 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1368 | scoped_ptr<SpdyFrame> spdy_response( |
| 1369 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1370 | scoped_ptr<SpdyFrame> spdy_data( |
| 1371 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1372 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1373 | // HTTP/1.1 versions of the request and response. |
| 1374 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1375 | "Host: www.foo.com\r\n" |
| 1376 | "Connection: keep-alive\r\n\r\n"; |
| 1377 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1378 | const char kHttpData[] = "hello"; |
| 1379 | |
| 1380 | std::vector<MockRead> data1_reads; |
| 1381 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1382 | if (write_failure) { |
| 1383 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1384 | data1_writes.push_back(*write_failure); |
| 1385 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1386 | } else { |
| 1387 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1388 | if (use_spdy) { |
| 1389 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1390 | } else { |
| 1391 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1392 | } |
| 1393 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1394 | } |
| 1395 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1396 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1397 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1398 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1399 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1400 | std::vector<MockRead> data2_reads; |
| 1401 | std::vector<MockWrite> data2_writes; |
| 1402 | |
| 1403 | if (use_spdy) { |
| 1404 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1405 | |
| 1406 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1407 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1408 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1409 | } else { |
| 1410 | data2_writes.push_back( |
| 1411 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1412 | |
| 1413 | data2_reads.push_back( |
| 1414 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1415 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1416 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1417 | } |
| 1418 | OrderedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1419 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1421 | |
| 1422 | // Preconnect a socket. |
| 1423 | net::SSLConfig ssl_config; |
| 1424 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1425 | session->GetNextProtos(&ssl_config.next_protos); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1426 | session->http_stream_factory()->PreconnectStreams( |
| 1427 | 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config); |
| 1428 | // Wait for the preconnect to complete. |
| 1429 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1430 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1431 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1432 | |
| 1433 | // Make the request. |
| 1434 | TestCompletionCallback callback; |
| 1435 | |
| 1436 | scoped_ptr<HttpTransaction> trans( |
| 1437 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1438 | |
| 1439 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1440 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1441 | |
| 1442 | rv = callback.WaitForResult(); |
| 1443 | EXPECT_EQ(OK, rv); |
| 1444 | |
| 1445 | LoadTimingInfo load_timing_info; |
| 1446 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1447 | TestLoadTimingNotReused( |
| 1448 | load_timing_info, |
| 1449 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1450 | |
| 1451 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1452 | ASSERT_TRUE(response != NULL); |
| 1453 | |
| 1454 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1455 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1456 | |
| 1457 | std::string response_data; |
| 1458 | rv = ReadTransaction(trans.get(), &response_data); |
| 1459 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1460 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1463 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1464 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1465 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1466 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1467 | } |
| 1468 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1469 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1470 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1471 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1472 | } |
| 1473 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1474 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1475 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1476 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1477 | } |
| 1478 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1479 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1480 | // if the socket was a reused keep alive socket. |
| 1481 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1482 | MockRead read_failure(SYNCHRONOUS, |
| 1483 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1484 | "Connection: Keep-Alive\r\n" |
| 1485 | "Content-Length: 6\r\n\r\n" |
| 1486 | "Pickle"); |
| 1487 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1488 | } |
| 1489 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1490 | TEST_P(HttpNetworkTransactionTest, |
| 1491 | PreconnectErrorNotConnectedOnWrite) { |
| 1492 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1493 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1497 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1498 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1502 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1503 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1504 | } |
| 1505 | |
| 1506 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1507 | MockRead read_failure(ASYNC, OK); // EOF |
| 1508 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1509 | } |
| 1510 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1511 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1512 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1513 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1514 | MockRead read_failure(SYNCHRONOUS, |
| 1515 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1516 | "Connection: Keep-Alive\r\n" |
| 1517 | "Content-Length: 6\r\n\r\n" |
| 1518 | "Pickle"); |
| 1519 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1520 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1521 | } |
| 1522 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1523 | TEST_P(HttpNetworkTransactionTest, |
| 1524 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1525 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1526 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1527 | } |
| 1528 | |
| 1529 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1530 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1531 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1532 | } |
| 1533 | |
| 1534 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1535 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1536 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1537 | } |
| 1538 | |
| 1539 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1540 | MockRead read_failure(ASYNC, OK); // EOF |
| 1541 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1542 | } |
| 1543 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1544 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1545 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1546 | request.method = "GET"; |
| 1547 | request.url = GURL("http://www.google.com/"); |
| 1548 | request.load_flags = 0; |
| 1549 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1550 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1551 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1553 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1554 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1555 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1556 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1557 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1558 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1559 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1560 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1561 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1563 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1565 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1566 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1567 | |
| 1568 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1569 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1570 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1571 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1572 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | // What do various browsers do when the server closes a non-keepalive |
| 1576 | // connection without sending any response header or body? |
| 1577 | // |
| 1578 | // IE7: error page |
| 1579 | // Safari 3.1.2 (Windows): error page |
| 1580 | // Firefox 3.0.1: blank page |
| 1581 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1582 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1583 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1584 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1585 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1586 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1587 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1588 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1589 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1590 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1591 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1592 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1593 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1594 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1595 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1596 | // Test that network access can be deferred and resumed. |
| 1597 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1598 | HttpRequestInfo request; |
| 1599 | request.method = "GET"; |
| 1600 | request.url = GURL("http://www.google.com/"); |
| 1601 | request.load_flags = 0; |
| 1602 | |
| 1603 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1604 | scoped_ptr<HttpTransaction> trans( |
| 1605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1606 | |
| 1607 | // Defer on OnBeforeNetworkStart. |
| 1608 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1609 | trans->SetBeforeNetworkStartCallback( |
| 1610 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1611 | base::Unretained(&net_start_handler))); |
| 1612 | |
| 1613 | MockRead data_reads[] = { |
| 1614 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1615 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1616 | MockRead("hello"), |
| 1617 | MockRead(SYNCHRONOUS, 0), |
| 1618 | }; |
| 1619 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1620 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1621 | |
| 1622 | TestCompletionCallback callback; |
| 1623 | |
| 1624 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1625 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1626 | base::MessageLoop::current()->RunUntilIdle(); |
| 1627 | |
| 1628 | // Should have deferred for network start. |
| 1629 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1630 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1631 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1632 | |
| 1633 | trans->ResumeNetworkStart(); |
| 1634 | rv = callback.WaitForResult(); |
| 1635 | EXPECT_EQ(OK, rv); |
| 1636 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1637 | |
| 1638 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1639 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1640 | if (rv == ERR_IO_PENDING) |
| 1641 | rv = callback.WaitForResult(); |
| 1642 | EXPECT_EQ(5, rv); |
| 1643 | trans.reset(); |
| 1644 | } |
| 1645 | |
| 1646 | // Test that network use can be deferred and canceled. |
| 1647 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1648 | HttpRequestInfo request; |
| 1649 | request.method = "GET"; |
| 1650 | request.url = GURL("http://www.google.com/"); |
| 1651 | request.load_flags = 0; |
| 1652 | |
| 1653 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1654 | scoped_ptr<HttpTransaction> trans( |
| 1655 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1656 | |
| 1657 | // Defer on OnBeforeNetworkStart. |
| 1658 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1659 | trans->SetBeforeNetworkStartCallback( |
| 1660 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1661 | base::Unretained(&net_start_handler))); |
| 1662 | |
| 1663 | TestCompletionCallback callback; |
| 1664 | |
| 1665 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1666 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1667 | base::MessageLoop::current()->RunUntilIdle(); |
| 1668 | |
| 1669 | // Should have deferred for network start. |
| 1670 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1671 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1672 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1673 | } |
| 1674 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1675 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1676 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1677 | // destructor in such situations. |
| 1678 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1679 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1680 | HttpRequestInfo request; |
| 1681 | request.method = "GET"; |
| 1682 | request.url = GURL("http://www.google.com/"); |
| 1683 | request.load_flags = 0; |
| 1684 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1685 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1686 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1688 | |
| 1689 | MockRead data_reads[] = { |
| 1690 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1691 | MockRead("Connection: keep-alive\r\n"), |
| 1692 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1693 | MockRead("hello"), |
| 1694 | MockRead(SYNCHRONOUS, 0), |
| 1695 | }; |
| 1696 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1698 | |
| 1699 | TestCompletionCallback callback; |
| 1700 | |
| 1701 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1703 | |
| 1704 | rv = callback.WaitForResult(); |
| 1705 | EXPECT_EQ(OK, rv); |
| 1706 | |
| 1707 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1708 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1709 | if (rv == ERR_IO_PENDING) |
| 1710 | rv = callback.WaitForResult(); |
| 1711 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1712 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1713 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1714 | |
| 1715 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1716 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1717 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1718 | } |
| 1719 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1720 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1721 | HttpRequestInfo request; |
| 1722 | request.method = "GET"; |
| 1723 | request.url = GURL("http://www.google.com/"); |
| 1724 | request.load_flags = 0; |
| 1725 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1726 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1727 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1728 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1729 | |
| 1730 | MockRead data_reads[] = { |
| 1731 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1732 | MockRead("Connection: keep-alive\r\n"), |
| 1733 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1734 | MockRead(SYNCHRONOUS, 0), |
| 1735 | }; |
| 1736 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1738 | |
| 1739 | TestCompletionCallback callback; |
| 1740 | |
| 1741 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1743 | |
| 1744 | rv = callback.WaitForResult(); |
| 1745 | EXPECT_EQ(OK, rv); |
| 1746 | |
| 1747 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1748 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1749 | if (rv == ERR_IO_PENDING) |
| 1750 | rv = callback.WaitForResult(); |
| 1751 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1752 | |
| 1753 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1754 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1755 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1756 | } |
| 1757 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1758 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1759 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1760 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1761 | HttpRequestInfo request; |
| 1762 | request.method = "GET"; |
| 1763 | request.url = GURL("http://www.foo.com/"); |
| 1764 | request.load_flags = 0; |
| 1765 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1766 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1767 | session_deps_.net_log = &net_log; |
| 1768 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1769 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1770 | // Note that because all these reads happen in the same |
| 1771 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1772 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1773 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1774 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1775 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1776 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1777 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1778 | "Content-Length: 0\r\n\r\n"), |
| 1779 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1780 | "Content-Length: 5\r\n\r\n" |
| 1781 | "hello"), |
| 1782 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1783 | "Content-Length: 0\r\n\r\n"), |
| 1784 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1785 | "Content-Length: 5\r\n\r\n" |
| 1786 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1787 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1788 | MockRead("hello"), |
| 1789 | }; |
| 1790 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1791 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1792 | |
| 1793 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1794 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1795 | }; |
| 1796 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1797 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1798 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1799 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1800 | std::string response_lines[kNumUnreadBodies]; |
| 1801 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1802 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1803 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1804 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1805 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1806 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1807 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1809 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1810 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1811 | |
| 1812 | rv = callback.WaitForResult(); |
| 1813 | EXPECT_EQ(OK, rv); |
| 1814 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1815 | LoadTimingInfo load_timing_info; |
| 1816 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1817 | if (i == 0) { |
| 1818 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1819 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1820 | } else { |
| 1821 | TestLoadTimingReused(load_timing_info); |
| 1822 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1823 | } |
| 1824 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1825 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1826 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1827 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1828 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1829 | response_lines[i] = response->headers->GetStatusLine(); |
| 1830 | |
| 1831 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1832 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1833 | |
| 1834 | const char* const kStatusLines[] = { |
| 1835 | "HTTP/1.1 204 No Content", |
| 1836 | "HTTP/1.1 205 Reset Content", |
| 1837 | "HTTP/1.1 304 Not Modified", |
| 1838 | "HTTP/1.1 302 Found", |
| 1839 | "HTTP/1.1 302 Found", |
| 1840 | "HTTP/1.1 301 Moved Permanently", |
| 1841 | "HTTP/1.1 301 Moved Permanently", |
| 1842 | }; |
| 1843 | |
| 1844 | COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines), |
| 1845 | forgot_to_update_kStatusLines); |
| 1846 | |
| 1847 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1848 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1850 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1851 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1852 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1853 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1854 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1855 | rv = callback.WaitForResult(); |
| 1856 | EXPECT_EQ(OK, rv); |
| 1857 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1858 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1859 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1860 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1861 | std::string response_data; |
| 1862 | rv = ReadTransaction(trans.get(), &response_data); |
| 1863 | EXPECT_EQ(OK, rv); |
| 1864 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1865 | } |
| 1866 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1867 | // Test the request-challenge-retry sequence for basic auth. |
| 1868 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1869 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1870 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1871 | request.method = "GET"; |
| 1872 | request.url = GURL("http://www.google.com/"); |
| 1873 | request.load_flags = 0; |
| 1874 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1875 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1876 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1877 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1878 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1879 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1880 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1881 | MockWrite data_writes1[] = { |
| 1882 | MockWrite("GET / HTTP/1.1\r\n" |
| 1883 | "Host: www.google.com\r\n" |
| 1884 | "Connection: keep-alive\r\n\r\n"), |
| 1885 | }; |
| 1886 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1887 | MockRead data_reads1[] = { |
| 1888 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1889 | // Give a couple authenticate options (only the middle one is actually |
| 1890 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1891 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1892 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1893 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1894 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1895 | // Large content-length -- won't matter, as connection will be reset. |
| 1896 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1897 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1898 | }; |
| 1899 | |
| 1900 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1901 | // be issuing -- the final header line contains the credentials. |
| 1902 | MockWrite data_writes2[] = { |
| 1903 | MockWrite("GET / HTTP/1.1\r\n" |
| 1904 | "Host: www.google.com\r\n" |
| 1905 | "Connection: keep-alive\r\n" |
| 1906 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1907 | }; |
| 1908 | |
| 1909 | // Lastly, the server responds with the actual content. |
| 1910 | MockRead data_reads2[] = { |
| 1911 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1912 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1913 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1914 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1915 | }; |
| 1916 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1917 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1918 | data_writes1, arraysize(data_writes1)); |
| 1919 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1920 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1921 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1922 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1924 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1926 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1927 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1928 | |
| 1929 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1930 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1931 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1932 | LoadTimingInfo load_timing_info1; |
| 1933 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1934 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1935 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1936 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1937 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1938 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1939 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1940 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1941 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1943 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1945 | rv = trans->RestartWithAuth( |
| 1946 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1947 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1948 | |
| 1949 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1950 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1951 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1952 | LoadTimingInfo load_timing_info2; |
| 1953 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1954 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1955 | // The load timing after restart should have a new socket ID, and times after |
| 1956 | // those of the first load timing. |
| 1957 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1958 | load_timing_info2.connect_timing.connect_start); |
| 1959 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1960 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1961 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1962 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1963 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1964 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1965 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1966 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1967 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1968 | } |
| 1969 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1970 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1971 | HttpRequestInfo request; |
| 1972 | request.method = "GET"; |
| 1973 | request.url = GURL("http://www.google.com/"); |
| 1974 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1975 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1976 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1977 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1978 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1979 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1980 | MockWrite data_writes[] = { |
| 1981 | MockWrite("GET / HTTP/1.1\r\n" |
| 1982 | "Host: www.google.com\r\n" |
| 1983 | "Connection: keep-alive\r\n\r\n"), |
| 1984 | }; |
| 1985 | |
| 1986 | MockRead data_reads[] = { |
| 1987 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1988 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1989 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1990 | // Large content-length -- won't matter, as connection will be reset. |
| 1991 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1992 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1993 | }; |
| 1994 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1995 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 1996 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1998 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2000 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2001 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2002 | |
| 2003 | rv = callback.WaitForResult(); |
| 2004 | EXPECT_EQ(0, rv); |
| 2005 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2006 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2007 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2008 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2010 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2011 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2012 | } |
| 2013 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2014 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2015 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2016 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2017 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2018 | request.method = "GET"; |
| 2019 | request.url = GURL("http://www.google.com/"); |
| 2020 | request.load_flags = 0; |
| 2021 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2022 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2023 | session_deps_.net_log = &log; |
| 2024 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2025 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2026 | MockWrite data_writes1[] = { |
| 2027 | MockWrite("GET / HTTP/1.1\r\n" |
| 2028 | "Host: www.google.com\r\n" |
| 2029 | "Connection: keep-alive\r\n\r\n"), |
| 2030 | |
| 2031 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2032 | // be issuing -- the final header line contains the credentials. |
| 2033 | MockWrite("GET / HTTP/1.1\r\n" |
| 2034 | "Host: www.google.com\r\n" |
| 2035 | "Connection: keep-alive\r\n" |
| 2036 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2037 | }; |
| 2038 | |
| 2039 | MockRead data_reads1[] = { |
| 2040 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2041 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2042 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2043 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2044 | MockRead("Unauthorized\r\n"), |
| 2045 | |
| 2046 | // Lastly, the server responds with the actual content. |
| 2047 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2048 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2049 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2050 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2051 | }; |
| 2052 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2053 | // If there is a regression where we disconnect a Keep-Alive |
| 2054 | // connection during an auth roundtrip, we'll end up reading this. |
| 2055 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2056 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2057 | }; |
| 2058 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2059 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2060 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2061 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2062 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2063 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2064 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2066 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2067 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2068 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2069 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2070 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2072 | |
| 2073 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2074 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2075 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2076 | LoadTimingInfo load_timing_info1; |
| 2077 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2078 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2079 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2080 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2081 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2082 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2084 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2086 | rv = trans->RestartWithAuth( |
| 2087 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2089 | |
| 2090 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2091 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2092 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2093 | LoadTimingInfo load_timing_info2; |
| 2094 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2095 | TestLoadTimingReused(load_timing_info2); |
| 2096 | // The load timing after restart should have the same socket ID, and times |
| 2097 | // those of the first load timing. |
| 2098 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2099 | load_timing_info2.send_start); |
| 2100 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2101 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2102 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2103 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2104 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2105 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2106 | |
| 2107 | std::string response_data; |
| 2108 | rv = ReadTransaction(trans.get(), &response_data); |
| 2109 | EXPECT_EQ(OK, rv); |
| 2110 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2111 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2115 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2116 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2117 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2118 | request.method = "GET"; |
| 2119 | request.url = GURL("http://www.google.com/"); |
| 2120 | request.load_flags = 0; |
| 2121 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2122 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2123 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2124 | MockWrite data_writes1[] = { |
| 2125 | MockWrite("GET / HTTP/1.1\r\n" |
| 2126 | "Host: www.google.com\r\n" |
| 2127 | "Connection: keep-alive\r\n\r\n"), |
| 2128 | |
| 2129 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2130 | // be issuing -- the final header line contains the credentials. |
| 2131 | MockWrite("GET / HTTP/1.1\r\n" |
| 2132 | "Host: www.google.com\r\n" |
| 2133 | "Connection: keep-alive\r\n" |
| 2134 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2135 | }; |
| 2136 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2137 | MockRead data_reads1[] = { |
| 2138 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2139 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2140 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2141 | |
| 2142 | // Lastly, the server responds with the actual content. |
| 2143 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2144 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2145 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2146 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2147 | }; |
| 2148 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2149 | // An incorrect reconnect would cause this to be read. |
| 2150 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2151 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2152 | }; |
| 2153 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2154 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2155 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2156 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2157 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2158 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2159 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2161 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2162 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2163 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2165 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2167 | |
| 2168 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2169 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2170 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2171 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2172 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2173 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2175 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2177 | rv = trans->RestartWithAuth( |
| 2178 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2180 | |
| 2181 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2182 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2183 | |
| 2184 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2185 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2186 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2187 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2191 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2192 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2193 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2194 | request.method = "GET"; |
| 2195 | request.url = GURL("http://www.google.com/"); |
| 2196 | request.load_flags = 0; |
| 2197 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2198 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2199 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2200 | MockWrite data_writes1[] = { |
| 2201 | MockWrite("GET / HTTP/1.1\r\n" |
| 2202 | "Host: www.google.com\r\n" |
| 2203 | "Connection: keep-alive\r\n\r\n"), |
| 2204 | |
| 2205 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2206 | // be issuing -- the final header line contains the credentials. |
| 2207 | MockWrite("GET / HTTP/1.1\r\n" |
| 2208 | "Host: www.google.com\r\n" |
| 2209 | "Connection: keep-alive\r\n" |
| 2210 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2211 | }; |
| 2212 | |
| 2213 | // Respond with 5 kb of response body. |
| 2214 | std::string large_body_string("Unauthorized"); |
| 2215 | large_body_string.append(5 * 1024, ' '); |
| 2216 | large_body_string.append("\r\n"); |
| 2217 | |
| 2218 | MockRead data_reads1[] = { |
| 2219 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2220 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2221 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2222 | // 5134 = 12 + 5 * 1024 + 2 |
| 2223 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2224 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2225 | |
| 2226 | // Lastly, the server responds with the actual content. |
| 2227 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2228 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2229 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2230 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2231 | }; |
| 2232 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2233 | // An incorrect reconnect would cause this to be read. |
| 2234 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2235 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2236 | }; |
| 2237 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2238 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2239 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2240 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2241 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2243 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2245 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2246 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2247 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2249 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2250 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2251 | |
| 2252 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2253 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2254 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2256 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2257 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2259 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2261 | rv = trans->RestartWithAuth( |
| 2262 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2264 | |
| 2265 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2266 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2267 | |
| 2268 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2269 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2270 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2271 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2275 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2276 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2277 | HttpRequestInfo request; |
| 2278 | request.method = "GET"; |
| 2279 | request.url = GURL("http://www.google.com/"); |
| 2280 | request.load_flags = 0; |
| 2281 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2282 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2283 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2284 | MockWrite data_writes1[] = { |
| 2285 | MockWrite("GET / HTTP/1.1\r\n" |
| 2286 | "Host: www.google.com\r\n" |
| 2287 | "Connection: keep-alive\r\n\r\n"), |
| 2288 | // This simulates the seemingly successful write to a closed connection |
| 2289 | // if the bug is not fixed. |
| 2290 | MockWrite("GET / HTTP/1.1\r\n" |
| 2291 | "Host: www.google.com\r\n" |
| 2292 | "Connection: keep-alive\r\n" |
| 2293 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2294 | }; |
| 2295 | |
| 2296 | MockRead data_reads1[] = { |
| 2297 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2298 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2299 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2300 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2301 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2302 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2303 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2304 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2305 | }; |
| 2306 | |
| 2307 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2308 | // be issuing -- the final header line contains the credentials. |
| 2309 | MockWrite data_writes2[] = { |
| 2310 | MockWrite("GET / HTTP/1.1\r\n" |
| 2311 | "Host: www.google.com\r\n" |
| 2312 | "Connection: keep-alive\r\n" |
| 2313 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2314 | }; |
| 2315 | |
| 2316 | // Lastly, the server responds with the actual content. |
| 2317 | MockRead data_reads2[] = { |
| 2318 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2319 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2320 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2321 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2322 | }; |
| 2323 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2324 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2325 | data_writes1, arraysize(data_writes1)); |
| 2326 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2327 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2328 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2329 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2331 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2332 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2333 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2334 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2335 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2337 | |
| 2338 | rv = callback1.WaitForResult(); |
| 2339 | EXPECT_EQ(OK, rv); |
| 2340 | |
| 2341 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2342 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2343 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2345 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2347 | rv = trans->RestartWithAuth( |
| 2348 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2350 | |
| 2351 | rv = callback2.WaitForResult(); |
| 2352 | EXPECT_EQ(OK, rv); |
| 2353 | |
| 2354 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2355 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2356 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2357 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2358 | } |
| 2359 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2360 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2361 | // that requires a restart when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2362 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2363 | HttpRequestInfo request; |
| 2364 | request.method = "GET"; |
| 2365 | request.url = GURL("https://www.google.com/"); |
| 2366 | // when the no authentication data flag is set. |
| 2367 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2368 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2369 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2370 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2371 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2372 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2373 | session_deps_.net_log = log.bound().net_log(); |
| 2374 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2375 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2376 | // Since we have proxy, should try to establish tunnel. |
| 2377 | MockWrite data_writes1[] = { |
| 2378 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2379 | "Host: www.google.com\r\n" |
| 2380 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2381 | |
| 2382 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2383 | // be issuing -- the final header line contains the credentials. |
| 2384 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2385 | "Host: www.google.com\r\n" |
| 2386 | "Proxy-Connection: keep-alive\r\n" |
| 2387 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2388 | |
| 2389 | MockWrite("GET / HTTP/1.1\r\n" |
| 2390 | "Host: www.google.com\r\n" |
| 2391 | "Connection: keep-alive\r\n\r\n"), |
| 2392 | }; |
| 2393 | |
| 2394 | // The proxy responds to the connect with a 407, using a persistent |
| 2395 | // connection. |
| 2396 | MockRead data_reads1[] = { |
| 2397 | // No credentials. |
| 2398 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2399 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2400 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2401 | |
| 2402 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2403 | |
| 2404 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2405 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2406 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2407 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2408 | }; |
| 2409 | |
| 2410 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2411 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2412 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2413 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2416 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2417 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2418 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2419 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2421 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2422 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2423 | |
| 2424 | rv = callback1.WaitForResult(); |
| 2425 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2426 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2427 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2428 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2429 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2430 | NetLog::PHASE_NONE); |
| 2431 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2432 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2433 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2434 | NetLog::PHASE_NONE); |
| 2435 | |
| 2436 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2437 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2438 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2439 | EXPECT_EQ(407, response->headers->response_code()); |
| 2440 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2441 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2442 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2443 | LoadTimingInfo load_timing_info; |
| 2444 | // CONNECT requests and responses are handled at the connect job level, so |
| 2445 | // the transaction does not yet have a connection. |
| 2446 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2448 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2450 | rv = trans->RestartWithAuth( |
| 2451 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2452 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2453 | |
| 2454 | rv = callback2.WaitForResult(); |
| 2455 | EXPECT_EQ(OK, rv); |
| 2456 | |
| 2457 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2458 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2459 | |
| 2460 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2461 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2462 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2463 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2464 | |
| 2465 | // The password prompt info should not be set. |
| 2466 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2467 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2468 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2469 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2470 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2471 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2472 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2473 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2474 | } |
| 2475 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2476 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2477 | // proxy connection, when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2478 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2479 | HttpRequestInfo request; |
| 2480 | request.method = "GET"; |
| 2481 | request.url = GURL("https://www.google.com/"); |
| 2482 | // Ensure that proxy authentication is attempted even |
| 2483 | // when the no authentication data flag is set. |
| 2484 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2485 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2486 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2487 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2488 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2489 | session_deps_.net_log = log.bound().net_log(); |
| 2490 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2491 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2492 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2493 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2494 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2495 | // Since we have proxy, should try to establish tunnel. |
| 2496 | MockWrite data_writes1[] = { |
| 2497 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2498 | "Host: www.google.com\r\n" |
| 2499 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2500 | |
| 2501 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2502 | // be issuing -- the final header line contains the credentials. |
| 2503 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2504 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2505 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2506 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2507 | }; |
| 2508 | |
| 2509 | // The proxy responds to the connect with a 407, using a persistent |
| 2510 | // connection. |
| 2511 | MockRead data_reads1[] = { |
| 2512 | // No credentials. |
| 2513 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2514 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2515 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2516 | MockRead("0123456789"), |
| 2517 | |
| 2518 | // Wrong credentials (wrong password). |
| 2519 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2520 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2521 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2522 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2523 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2524 | }; |
| 2525 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2526 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2527 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2528 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2530 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2532 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2533 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2534 | |
| 2535 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2536 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2537 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2538 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2539 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2540 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2541 | NetLog::PHASE_NONE); |
| 2542 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2543 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2544 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2545 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2546 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2547 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2548 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2549 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2550 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2551 | EXPECT_EQ(407, response->headers->response_code()); |
| 2552 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2553 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2554 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2556 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2557 | |
| 2558 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2559 | rv = trans->RestartWithAuth( |
| 2560 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2561 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2562 | |
| 2563 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2564 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2565 | |
| 2566 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2567 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2568 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2569 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2570 | EXPECT_EQ(407, response->headers->response_code()); |
| 2571 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2572 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2573 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2574 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2575 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2576 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2577 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2578 | } |
| 2579 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2580 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2581 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2582 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2583 | HttpRequestInfo request; |
| 2584 | request.method = "GET"; |
| 2585 | request.url = GURL("https://www.google.com/"); |
| 2586 | request.load_flags = 0; |
| 2587 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2588 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2589 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2590 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2591 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2592 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2593 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2594 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2595 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2596 | // Since we have proxy, should try to establish tunnel. |
| 2597 | MockWrite data_writes[] = { |
| 2598 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2599 | "Host: www.google.com\r\n" |
| 2600 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2601 | }; |
| 2602 | |
| 2603 | // The proxy responds to the connect with a 407. |
| 2604 | MockRead data_reads[] = { |
| 2605 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2606 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2607 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2608 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2609 | }; |
| 2610 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2612 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2614 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2615 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2616 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2617 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2618 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2619 | |
| 2620 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2621 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2622 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2624 | ASSERT_TRUE(response != NULL); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2625 | |
| 2626 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2627 | EXPECT_EQ(407, response->headers->response_code()); |
| 2628 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2629 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2630 | |
| 2631 | std::string response_data; |
| 2632 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2633 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2634 | |
| 2635 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2636 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2637 | } |
| 2638 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2639 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2640 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2641 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2642 | HttpRequestInfo request; |
| 2643 | request.method = "GET"; |
| 2644 | request.url = GURL("http://www.google.com/"); |
| 2645 | request.load_flags = 0; |
| 2646 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2647 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2648 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2649 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2650 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2651 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2652 | MockWrite data_writes1[] = { |
| 2653 | MockWrite("GET / HTTP/1.1\r\n" |
| 2654 | "Host: www.google.com\r\n" |
| 2655 | "Connection: keep-alive\r\n\r\n"), |
| 2656 | }; |
| 2657 | |
| 2658 | MockRead data_reads1[] = { |
| 2659 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2660 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2661 | // Large content-length -- won't matter, as connection will be reset. |
| 2662 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2663 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2664 | }; |
| 2665 | |
| 2666 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2667 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2668 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2670 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2672 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2673 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2674 | |
| 2675 | rv = callback.WaitForResult(); |
| 2676 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2677 | } |
| 2678 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2679 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2680 | // through a non-authenticating proxy. The request should fail with |
| 2681 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2682 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2683 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2684 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2685 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2686 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2687 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2688 | HttpRequestInfo request; |
| 2689 | request.method = "GET"; |
| 2690 | request.url = GURL("https://www.google.com/"); |
| 2691 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2692 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2693 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2694 | session_deps_.net_log = log.bound().net_log(); |
| 2695 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2696 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2697 | // Since we have proxy, should try to establish tunnel. |
| 2698 | MockWrite data_writes1[] = { |
| 2699 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2700 | "Host: www.google.com\r\n" |
| 2701 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2702 | |
| 2703 | MockWrite("GET / HTTP/1.1\r\n" |
| 2704 | "Host: www.google.com\r\n" |
| 2705 | "Connection: keep-alive\r\n\r\n"), |
| 2706 | }; |
| 2707 | |
| 2708 | MockRead data_reads1[] = { |
| 2709 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2710 | |
| 2711 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 2712 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2713 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2714 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2715 | }; |
| 2716 | |
| 2717 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2718 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2719 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2720 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2723 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2724 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2725 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2726 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2728 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2729 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2730 | |
| 2731 | rv = callback1.WaitForResult(); |
| 2732 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2733 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2734 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2735 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2736 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2737 | NetLog::PHASE_NONE); |
| 2738 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2739 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2740 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2741 | NetLog::PHASE_NONE); |
| 2742 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2743 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2744 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2745 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2746 | HttpRequestInfo request1; |
| 2747 | request1.method = "GET"; |
| 2748 | request1.url = GURL("https://www.google.com/1"); |
| 2749 | |
| 2750 | HttpRequestInfo request2; |
| 2751 | request2.method = "GET"; |
| 2752 | request2.url = GURL("https://www.google.com/2"); |
| 2753 | |
| 2754 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2755 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2756 | ProxyService::CreateFixed("PROXY myproxy:70")); |
| 2757 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2758 | session_deps_.net_log = log.bound().net_log(); |
| 2759 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2760 | |
| 2761 | // Since we have proxy, should try to establish tunnel. |
| 2762 | MockWrite data_writes1[] = { |
| 2763 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2764 | "Host: www.google.com\r\n" |
| 2765 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2766 | |
| 2767 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2768 | "Host: www.google.com\r\n" |
| 2769 | "Connection: keep-alive\r\n\r\n"), |
| 2770 | |
| 2771 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2772 | "Host: www.google.com\r\n" |
| 2773 | "Connection: keep-alive\r\n\r\n"), |
| 2774 | }; |
| 2775 | |
| 2776 | // The proxy responds to the connect with a 407, using a persistent |
| 2777 | // connection. |
| 2778 | MockRead data_reads1[] = { |
| 2779 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2780 | |
| 2781 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2782 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2783 | MockRead(SYNCHRONOUS, "1"), |
| 2784 | |
| 2785 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2786 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2787 | MockRead(SYNCHRONOUS, "22"), |
| 2788 | }; |
| 2789 | |
| 2790 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2791 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2792 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2793 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2794 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2795 | |
| 2796 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2797 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2798 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2799 | |
| 2800 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2801 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2802 | |
| 2803 | rv = callback1.WaitForResult(); |
| 2804 | EXPECT_EQ(OK, rv); |
| 2805 | |
| 2806 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2807 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2808 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2809 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2810 | |
| 2811 | LoadTimingInfo load_timing_info1; |
| 2812 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2813 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2814 | |
| 2815 | trans1.reset(); |
| 2816 | |
| 2817 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2818 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2819 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2820 | |
| 2821 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2822 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2823 | |
| 2824 | rv = callback2.WaitForResult(); |
| 2825 | EXPECT_EQ(OK, rv); |
| 2826 | |
| 2827 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2828 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2829 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2830 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2831 | |
| 2832 | LoadTimingInfo load_timing_info2; |
| 2833 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2834 | TestLoadTimingReused(load_timing_info2); |
| 2835 | |
| 2836 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2837 | |
| 2838 | trans2.reset(); |
| 2839 | session->CloseAllConnections(); |
| 2840 | } |
| 2841 | |
| 2842 | // Test the load timing for HTTPS requests with an HTTP proxy and a PAC script. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2843 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2844 | HttpRequestInfo request1; |
| 2845 | request1.method = "GET"; |
| 2846 | request1.url = GURL("https://www.google.com/1"); |
| 2847 | |
| 2848 | HttpRequestInfo request2; |
| 2849 | request2.method = "GET"; |
| 2850 | request2.url = GURL("https://www.google.com/2"); |
| 2851 | |
| 2852 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2853 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2854 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 2855 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2856 | session_deps_.net_log = log.bound().net_log(); |
| 2857 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2858 | |
| 2859 | // Since we have proxy, should try to establish tunnel. |
| 2860 | MockWrite data_writes1[] = { |
| 2861 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2862 | "Host: www.google.com\r\n" |
| 2863 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2864 | |
| 2865 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2866 | "Host: www.google.com\r\n" |
| 2867 | "Connection: keep-alive\r\n\r\n"), |
| 2868 | |
| 2869 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2870 | "Host: www.google.com\r\n" |
| 2871 | "Connection: keep-alive\r\n\r\n"), |
| 2872 | }; |
| 2873 | |
| 2874 | // The proxy responds to the connect with a 407, using a persistent |
| 2875 | // connection. |
| 2876 | MockRead data_reads1[] = { |
| 2877 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2878 | |
| 2879 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2880 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2881 | MockRead(SYNCHRONOUS, "1"), |
| 2882 | |
| 2883 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2884 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2885 | MockRead(SYNCHRONOUS, "22"), |
| 2886 | }; |
| 2887 | |
| 2888 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2889 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2890 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2891 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2892 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2893 | |
| 2894 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2895 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2897 | |
| 2898 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2900 | |
| 2901 | rv = callback1.WaitForResult(); |
| 2902 | EXPECT_EQ(OK, rv); |
| 2903 | |
| 2904 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2905 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2906 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2907 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2908 | |
| 2909 | LoadTimingInfo load_timing_info1; |
| 2910 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2911 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 2912 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2913 | |
| 2914 | trans1.reset(); |
| 2915 | |
| 2916 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2917 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2919 | |
| 2920 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2921 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2922 | |
| 2923 | rv = callback2.WaitForResult(); |
| 2924 | EXPECT_EQ(OK, rv); |
| 2925 | |
| 2926 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2927 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2928 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2929 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2930 | |
| 2931 | LoadTimingInfo load_timing_info2; |
| 2932 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2933 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 2934 | |
| 2935 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2936 | |
| 2937 | trans2.reset(); |
| 2938 | session->CloseAllConnections(); |
| 2939 | } |
| 2940 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2941 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2942 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2943 | HttpRequestInfo request; |
| 2944 | request.method = "GET"; |
| 2945 | request.url = GURL("http://www.google.com/"); |
| 2946 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2947 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2948 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2949 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2950 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2951 | session_deps_.net_log = log.bound().net_log(); |
| 2952 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2953 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2954 | // Since we have proxy, should use full url |
| 2955 | MockWrite data_writes1[] = { |
| 2956 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 2957 | "Host: www.google.com\r\n" |
| 2958 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2959 | }; |
| 2960 | |
| 2961 | MockRead data_reads1[] = { |
| 2962 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2963 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2964 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2966 | }; |
| 2967 | |
| 2968 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2969 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2970 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2971 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2974 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2975 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2976 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2979 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2980 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2981 | |
| 2982 | rv = callback1.WaitForResult(); |
| 2983 | EXPECT_EQ(OK, rv); |
| 2984 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2985 | LoadTimingInfo load_timing_info; |
| 2986 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2987 | TestLoadTimingNotReused(load_timing_info, |
| 2988 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2989 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2990 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2991 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2992 | |
| 2993 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2994 | EXPECT_EQ(200, response->headers->response_code()); |
| 2995 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2996 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2997 | |
| 2998 | // The password prompt info should not be set. |
| 2999 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3000 | } |
| 3001 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3002 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3003 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3004 | HttpRequestInfo request; |
| 3005 | request.method = "GET"; |
| 3006 | request.url = GURL("http://www.google.com/"); |
| 3007 | request.load_flags = 0; |
| 3008 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3009 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3010 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3011 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3012 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3013 | session_deps_.net_log = log.bound().net_log(); |
| 3014 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3015 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3016 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3017 | scoped_ptr<SpdyFrame> req( |
| 3018 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3019 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 3020 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3021 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3022 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3023 | MockRead spdy_reads[] = { |
| 3024 | CreateMockRead(*resp), |
| 3025 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3026 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3027 | }; |
| 3028 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3029 | DelayedSocketData spdy_data( |
| 3030 | 1, // wait for one write to finish before reading. |
| 3031 | spdy_reads, arraysize(spdy_reads), |
| 3032 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3033 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3034 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3035 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3036 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3039 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3040 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3041 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3044 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3046 | |
| 3047 | rv = callback1.WaitForResult(); |
| 3048 | EXPECT_EQ(OK, rv); |
| 3049 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3050 | LoadTimingInfo load_timing_info; |
| 3051 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3052 | TestLoadTimingNotReused(load_timing_info, |
| 3053 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3054 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3055 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3056 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3057 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3058 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3059 | |
| 3060 | std::string response_data; |
| 3061 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3062 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3063 | } |
| 3064 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3065 | // Verifies that a session which races and wins against the owning transaction |
| 3066 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3067 | // Regression test for crbug.com/334413. |
| 3068 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3069 | HttpRequestInfo request; |
| 3070 | request.method = "GET"; |
| 3071 | request.url = GURL("http://www.google.com/"); |
| 3072 | request.load_flags = 0; |
| 3073 | |
| 3074 | // Configure SPDY proxy server "proxy:70". |
| 3075 | session_deps_.proxy_service.reset( |
| 3076 | ProxyService::CreateFixed("https://proxy:70")); |
| 3077 | CapturingBoundNetLog log; |
| 3078 | session_deps_.net_log = log.bound().net_log(); |
| 3079 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3080 | |
| 3081 | // Fetch http://www.google.com/ through the SPDY proxy. |
| 3082 | scoped_ptr<SpdyFrame> req( |
| 3083 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
| 3084 | MockWrite spdy_writes[] = {CreateMockWrite(*req)}; |
| 3085 | |
| 3086 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3087 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3088 | MockRead spdy_reads[] = { |
| 3089 | CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0), |
| 3090 | }; |
| 3091 | |
| 3092 | DelayedSocketData spdy_data( |
| 3093 | 1, // wait for one write to finish before reading. |
| 3094 | spdy_reads, |
| 3095 | arraysize(spdy_reads), |
| 3096 | spdy_writes, |
| 3097 | arraysize(spdy_writes)); |
| 3098 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3099 | |
| 3100 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3101 | ssl.SetNextProto(GetParam()); |
| 3102 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3103 | |
| 3104 | TestCompletionCallback callback1; |
| 3105 | |
| 3106 | scoped_ptr<HttpTransaction> trans( |
| 3107 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3108 | |
| 3109 | // Stall the hostname resolution begun by the transaction. |
| 3110 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3111 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3112 | |
| 3113 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3114 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3115 | |
| 3116 | // Race a session to the proxy, which completes first. |
| 3117 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3118 | SpdySessionKey key( |
| 3119 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3120 | base::WeakPtr<SpdySession> spdy_session = |
| 3121 | CreateSecureSpdySession(session, key, log.bound()); |
| 3122 | |
| 3123 | // Unstall the resolution begun by the transaction. |
| 3124 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3125 | session_deps_.host_resolver->ResolveAllPending(); |
| 3126 | |
| 3127 | EXPECT_FALSE(callback1.have_result()); |
| 3128 | rv = callback1.WaitForResult(); |
| 3129 | EXPECT_EQ(OK, rv); |
| 3130 | |
| 3131 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3132 | ASSERT_TRUE(response != NULL); |
| 3133 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3134 | 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)); |
| 3138 | EXPECT_EQ(kUploadData, response_data); |
| 3139 | } |
| 3140 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3141 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3142 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3143 | HttpRequestInfo request; |
| 3144 | request.method = "GET"; |
| 3145 | request.url = GURL("http://www.google.com/"); |
| 3146 | request.load_flags = 0; |
| 3147 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3148 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3149 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3150 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3151 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3152 | session_deps_.net_log = log.bound().net_log(); |
| 3153 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3154 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3155 | // The first request will be a bare GET, the second request will be a |
| 3156 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3157 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3158 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3159 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3160 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3161 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3162 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3163 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3164 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3165 | false, |
| 3166 | 3, |
| 3167 | LOWEST, |
| 3168 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3169 | MockWrite spdy_writes[] = { |
| 3170 | CreateMockWrite(*req_get, 1), |
| 3171 | CreateMockWrite(*req_get_authorization, 4), |
| 3172 | }; |
| 3173 | |
| 3174 | // The first response is a 407 proxy authentication challenge, and the second |
| 3175 | // response will be a 200 response since the second request includes a valid |
| 3176 | // Authorization header. |
| 3177 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3178 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3179 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3180 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3181 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3182 | "407 Proxy Authentication Required", |
| 3183 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3184 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3185 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3186 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3187 | scoped_ptr<SpdyFrame> resp_data( |
| 3188 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3189 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3190 | MockRead spdy_reads[] = { |
| 3191 | CreateMockRead(*resp_authentication, 2), |
| 3192 | CreateMockRead(*body_authentication, 3), |
| 3193 | CreateMockRead(*resp_data, 5), |
| 3194 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3195 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3196 | }; |
| 3197 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3198 | OrderedSocketData data( |
| 3199 | spdy_reads, arraysize(spdy_reads), |
| 3200 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3202 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3203 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3204 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3207 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3208 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3209 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3212 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3214 | |
| 3215 | rv = callback1.WaitForResult(); |
| 3216 | EXPECT_EQ(OK, rv); |
| 3217 | |
| 3218 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3219 | |
| 3220 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3221 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3222 | EXPECT_EQ(407, response->headers->response_code()); |
| 3223 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3224 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3226 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3228 | rv = trans->RestartWithAuth( |
| 3229 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3230 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3231 | |
| 3232 | rv = callback2.WaitForResult(); |
| 3233 | EXPECT_EQ(OK, rv); |
| 3234 | |
| 3235 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3236 | |
| 3237 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3238 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3239 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3240 | // The password prompt info should not be set. |
| 3241 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3242 | } |
| 3243 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3244 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3245 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3246 | HttpRequestInfo request; |
| 3247 | request.method = "GET"; |
| 3248 | request.url = GURL("https://www.google.com/"); |
| 3249 | request.load_flags = 0; |
| 3250 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3251 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3252 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3253 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3254 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3255 | session_deps_.net_log = log.bound().net_log(); |
| 3256 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3257 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3258 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3259 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3260 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3261 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3262 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3263 | LOWEST)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3264 | // fetch https://www.google.com/ via HTTP |
| 3265 | |
| 3266 | const char get[] = "GET / HTTP/1.1\r\n" |
| 3267 | "Host: www.google.com\r\n" |
| 3268 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3269 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3270 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3271 | scoped_ptr<SpdyFrame> conn_resp( |
| 3272 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3273 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3274 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3275 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3276 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3277 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3278 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3279 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3280 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3281 | |
| 3282 | MockWrite spdy_writes[] = { |
| 3283 | CreateMockWrite(*connect, 1), |
| 3284 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3285 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3286 | }; |
| 3287 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3288 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3289 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3290 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3291 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3292 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 3293 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3294 | }; |
| 3295 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3296 | OrderedSocketData spdy_data( |
| 3297 | spdy_reads, arraysize(spdy_reads), |
| 3298 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3299 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3300 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3301 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3302 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3303 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3304 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3305 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 3306 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3307 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3309 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3311 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3312 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3313 | |
| 3314 | rv = callback1.WaitForResult(); |
| 3315 | EXPECT_EQ(OK, rv); |
| 3316 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3317 | LoadTimingInfo load_timing_info; |
| 3318 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3319 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3320 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3321 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3322 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3323 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3324 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3325 | |
| 3326 | std::string response_data; |
| 3327 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3328 | EXPECT_EQ("1234567890", response_data); |
| 3329 | } |
| 3330 | |
| 3331 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3332 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3333 | HttpRequestInfo request; |
| 3334 | request.method = "GET"; |
| 3335 | request.url = GURL("https://www.google.com/"); |
| 3336 | request.load_flags = 0; |
| 3337 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3338 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3339 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3340 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3341 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3342 | session_deps_.net_log = log.bound().net_log(); |
| 3343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3344 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3345 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3346 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3347 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3348 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3349 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3350 | LOWEST)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3351 | // fetch https://www.google.com/ via SPDY |
| 3352 | const char* const kMyUrl = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3353 | scoped_ptr<SpdyFrame> get( |
| 3354 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3355 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3356 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3357 | scoped_ptr<SpdyFrame> conn_resp( |
| 3358 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3359 | scoped_ptr<SpdyFrame> get_resp( |
| 3360 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3361 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3362 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3363 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3364 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3365 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3366 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3367 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3368 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3369 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3370 | |
| 3371 | MockWrite spdy_writes[] = { |
| 3372 | CreateMockWrite(*connect, 1), |
| 3373 | CreateMockWrite(*wrapped_get, 3), |
| 3374 | CreateMockWrite(*window_update_get_resp, 5), |
| 3375 | CreateMockWrite(*window_update_body, 7), |
| 3376 | }; |
| 3377 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3378 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3379 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3380 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3381 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3382 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3383 | }; |
| 3384 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3385 | OrderedSocketData spdy_data( |
| 3386 | spdy_reads, arraysize(spdy_reads), |
| 3387 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3388 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3389 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3390 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3391 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3393 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3394 | ssl2.SetNextProto(GetParam()); |
| 3395 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3398 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3400 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3401 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3402 | |
| 3403 | rv = callback1.WaitForResult(); |
| 3404 | EXPECT_EQ(OK, rv); |
| 3405 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3406 | LoadTimingInfo load_timing_info; |
| 3407 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3408 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3409 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3410 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3411 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3412 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3413 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3414 | |
| 3415 | std::string response_data; |
| 3416 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3417 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3421 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3422 | HttpRequestInfo request; |
| 3423 | request.method = "GET"; |
| 3424 | request.url = GURL("https://www.google.com/"); |
| 3425 | request.load_flags = 0; |
| 3426 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3427 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3428 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3429 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3430 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3431 | session_deps_.net_log = log.bound().net_log(); |
| 3432 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3433 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3434 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3435 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3436 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3437 | // CONNECT to www.google.com:443 via SPDY |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3438 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3439 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3440 | scoped_ptr<SpdyFrame> get( |
| 3441 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3442 | |
| 3443 | MockWrite spdy_writes[] = { |
| 3444 | CreateMockWrite(*connect, 1), |
| 3445 | CreateMockWrite(*get, 3), |
| 3446 | }; |
| 3447 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3448 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3449 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3450 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3451 | CreateMockRead(*resp, 2, ASYNC), |
| 3452 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3453 | }; |
| 3454 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3455 | OrderedSocketData spdy_data( |
| 3456 | spdy_reads, arraysize(spdy_reads), |
| 3457 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3458 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3459 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3460 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3461 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3463 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3464 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3467 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3469 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3470 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3471 | |
| 3472 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3473 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3474 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3475 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3476 | } |
| 3477 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3478 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3479 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3480 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3481 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3482 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3483 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3484 | "https://proxy:70")); |
| 3485 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3486 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3487 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3488 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3489 | |
| 3490 | HttpRequestInfo request1; |
| 3491 | request1.method = "GET"; |
| 3492 | request1.url = GURL("https://www.google.com/"); |
| 3493 | request1.load_flags = 0; |
| 3494 | |
| 3495 | HttpRequestInfo request2; |
| 3496 | request2.method = "GET"; |
| 3497 | request2.url = GURL("https://news.google.com/"); |
| 3498 | request2.load_flags = 0; |
| 3499 | |
| 3500 | // CONNECT to www.google.com:443 via SPDY. |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3501 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3502 | LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3503 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3504 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3505 | |
| 3506 | // Fetch https://www.google.com/ via HTTP. |
| 3507 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3508 | "Host: www.google.com\r\n" |
| 3509 | "Connection: keep-alive\r\n\r\n"; |
| 3510 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3511 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3512 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3513 | "Content-Length: 1\r\n\r\n"; |
| 3514 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3515 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3516 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3517 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3518 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3519 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3520 | |
| 3521 | // CONNECT to news.google.com:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3522 | SpdyHeaderBlock connect2_block; |
| 3523 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 3524 | connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443"; |
| 3525 | connect2_block[spdy_util_.GetHostKey()] = "news.google.com"; |
| 3526 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3527 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3528 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3529 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3530 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3531 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3532 | |
| 3533 | // Fetch https://news.google.com/ via HTTP. |
| 3534 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3535 | "Host: news.google.com\r\n" |
| 3536 | "Connection: keep-alive\r\n\r\n"; |
| 3537 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3538 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3539 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3540 | "Content-Length: 2\r\n\r\n"; |
| 3541 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3542 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3543 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3544 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3545 | |
| 3546 | MockWrite spdy_writes[] = { |
| 3547 | CreateMockWrite(*connect1, 0), |
| 3548 | CreateMockWrite(*wrapped_get1, 2), |
| 3549 | CreateMockWrite(*connect2, 5), |
| 3550 | CreateMockWrite(*wrapped_get2, 7), |
| 3551 | }; |
| 3552 | |
| 3553 | MockRead spdy_reads[] = { |
| 3554 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3555 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3556 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3557 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3558 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3559 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3560 | MockRead(ASYNC, 0, 10), |
| 3561 | }; |
| 3562 | |
| 3563 | DeterministicSocketData spdy_data( |
| 3564 | spdy_reads, arraysize(spdy_reads), |
| 3565 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3566 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3567 | |
| 3568 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3569 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3570 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3571 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3572 | ssl2.was_npn_negotiated = false; |
| 3573 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3574 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3575 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3576 | ssl3.was_npn_negotiated = false; |
| 3577 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3578 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3579 | |
| 3580 | TestCompletionCallback callback; |
| 3581 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3582 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3584 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3586 | // The first connect and request, each of their responses, and the body. |
| 3587 | spdy_data.RunFor(5); |
| 3588 | |
| 3589 | rv = callback.WaitForResult(); |
| 3590 | EXPECT_EQ(OK, rv); |
| 3591 | |
| 3592 | LoadTimingInfo load_timing_info; |
| 3593 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3594 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3595 | |
| 3596 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3597 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3598 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3599 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3600 | |
| 3601 | std::string response_data; |
| 3602 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3603 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3604 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3605 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3607 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3609 | |
| 3610 | // The second connect and request, each of their responses, and the body. |
| 3611 | spdy_data.RunFor(5); |
| 3612 | rv = callback.WaitForResult(); |
| 3613 | EXPECT_EQ(OK, rv); |
| 3614 | |
| 3615 | LoadTimingInfo load_timing_info2; |
| 3616 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3617 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3618 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3619 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3620 | |
| 3621 | // The requests should have different IDs, since they each are using their own |
| 3622 | // separate stream. |
| 3623 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3624 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3625 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3629 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3630 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3631 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3632 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3633 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3634 | "https://proxy:70")); |
| 3635 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3636 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3637 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3638 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3639 | |
| 3640 | HttpRequestInfo request1; |
| 3641 | request1.method = "GET"; |
| 3642 | request1.url = GURL("https://www.google.com/"); |
| 3643 | request1.load_flags = 0; |
| 3644 | |
| 3645 | HttpRequestInfo request2; |
| 3646 | request2.method = "GET"; |
| 3647 | request2.url = GURL("https://www.google.com/2"); |
| 3648 | request2.load_flags = 0; |
| 3649 | |
| 3650 | // CONNECT to www.google.com:443 via SPDY. |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 3651 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 3652 | LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3653 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3654 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3655 | |
| 3656 | // Fetch https://www.google.com/ via HTTP. |
| 3657 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3658 | "Host: www.google.com\r\n" |
| 3659 | "Connection: keep-alive\r\n\r\n"; |
| 3660 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3661 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3662 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3663 | "Content-Length: 1\r\n\r\n"; |
| 3664 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3665 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3666 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3667 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3668 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3669 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3670 | |
| 3671 | // Fetch https://www.google.com/2 via HTTP. |
| 3672 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3673 | "Host: www.google.com\r\n" |
| 3674 | "Connection: keep-alive\r\n\r\n"; |
| 3675 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3676 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3677 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3678 | "Content-Length: 2\r\n\r\n"; |
| 3679 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3680 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3681 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3682 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3683 | |
| 3684 | MockWrite spdy_writes[] = { |
| 3685 | CreateMockWrite(*connect1, 0), |
| 3686 | CreateMockWrite(*wrapped_get1, 2), |
| 3687 | CreateMockWrite(*wrapped_get2, 5), |
| 3688 | }; |
| 3689 | |
| 3690 | MockRead spdy_reads[] = { |
| 3691 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3692 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3693 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3694 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3695 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3696 | MockRead(ASYNC, 0, 8), |
| 3697 | }; |
| 3698 | |
| 3699 | DeterministicSocketData spdy_data( |
| 3700 | spdy_reads, arraysize(spdy_reads), |
| 3701 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3702 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3703 | |
| 3704 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3705 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3706 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3707 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3708 | ssl2.was_npn_negotiated = false; |
| 3709 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3710 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3711 | |
| 3712 | TestCompletionCallback callback; |
| 3713 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3714 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3715 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3716 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3718 | // The first connect and request, each of their responses, and the body. |
| 3719 | spdy_data.RunFor(5); |
| 3720 | |
| 3721 | rv = callback.WaitForResult(); |
| 3722 | EXPECT_EQ(OK, rv); |
| 3723 | |
| 3724 | LoadTimingInfo load_timing_info; |
| 3725 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3726 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3727 | |
| 3728 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3729 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3730 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3731 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3732 | |
| 3733 | std::string response_data; |
| 3734 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3735 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3736 | trans.reset(); |
| 3737 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3738 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3739 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3740 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3741 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3742 | |
| 3743 | // The second request, response, and body. There should not be a second |
| 3744 | // connect. |
| 3745 | spdy_data.RunFor(3); |
| 3746 | rv = callback.WaitForResult(); |
| 3747 | EXPECT_EQ(OK, rv); |
| 3748 | |
| 3749 | LoadTimingInfo load_timing_info2; |
| 3750 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3751 | TestLoadTimingReused(load_timing_info2); |
| 3752 | |
| 3753 | // The requests should have the same ID. |
| 3754 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3755 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3756 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 3760 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3761 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3762 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 3763 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3764 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3765 | "https://proxy:70")); |
| 3766 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3767 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3768 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3769 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3770 | |
| 3771 | HttpRequestInfo request1; |
| 3772 | request1.method = "GET"; |
| 3773 | request1.url = GURL("http://www.google.com/"); |
| 3774 | request1.load_flags = 0; |
| 3775 | |
| 3776 | HttpRequestInfo request2; |
| 3777 | request2.method = "GET"; |
| 3778 | request2.url = GURL("http://news.google.com/"); |
| 3779 | request2.load_flags = 0; |
| 3780 | |
| 3781 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3782 | scoped_ptr<SpdyHeaderBlock> headers( |
| 3783 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3784 | scoped_ptr<SpdyFrame> get1( |
| 3785 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3786 | scoped_ptr<SpdyFrame> get_resp1( |
| 3787 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3788 | scoped_ptr<SpdyFrame> body1( |
| 3789 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3790 | |
| 3791 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3792 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 3793 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3794 | scoped_ptr<SpdyFrame> get2( |
| 3795 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3796 | scoped_ptr<SpdyFrame> get_resp2( |
| 3797 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3798 | scoped_ptr<SpdyFrame> body2( |
| 3799 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3800 | |
| 3801 | MockWrite spdy_writes[] = { |
| 3802 | CreateMockWrite(*get1, 0), |
| 3803 | CreateMockWrite(*get2, 3), |
| 3804 | }; |
| 3805 | |
| 3806 | MockRead spdy_reads[] = { |
| 3807 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 3808 | CreateMockRead(*body1, 2, ASYNC), |
| 3809 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 3810 | CreateMockRead(*body2, 5, ASYNC), |
| 3811 | MockRead(ASYNC, 0, 6), |
| 3812 | }; |
| 3813 | |
| 3814 | DeterministicSocketData spdy_data( |
| 3815 | spdy_reads, arraysize(spdy_reads), |
| 3816 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3817 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3818 | |
| 3819 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3820 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3821 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3822 | |
| 3823 | TestCompletionCallback callback; |
| 3824 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3825 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3826 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3827 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3828 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3829 | spdy_data.RunFor(2); |
| 3830 | |
| 3831 | rv = callback.WaitForResult(); |
| 3832 | EXPECT_EQ(OK, rv); |
| 3833 | |
| 3834 | LoadTimingInfo load_timing_info; |
| 3835 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3836 | TestLoadTimingNotReused(load_timing_info, |
| 3837 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3838 | |
| 3839 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3840 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3841 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3842 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3843 | |
| 3844 | std::string response_data; |
| 3845 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3846 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3847 | spdy_data.RunFor(1); |
| 3848 | EXPECT_EQ(1, callback.WaitForResult()); |
| 3849 | // Delete the first request, so the second one can reuse the socket. |
| 3850 | trans.reset(); |
| 3851 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3852 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3853 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3854 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3856 | |
| 3857 | spdy_data.RunFor(2); |
| 3858 | rv = callback.WaitForResult(); |
| 3859 | EXPECT_EQ(OK, rv); |
| 3860 | |
| 3861 | LoadTimingInfo load_timing_info2; |
| 3862 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3863 | TestLoadTimingReused(load_timing_info2); |
| 3864 | |
| 3865 | // The requests should have the same ID. |
| 3866 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3867 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3868 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3869 | spdy_data.RunFor(1); |
| 3870 | EXPECT_EQ(2, callback.WaitForResult()); |
| 3871 | } |
| 3872 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3873 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3874 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3875 | HttpRequestInfo request; |
| 3876 | request.method = "GET"; |
| 3877 | request.url = GURL("http://www.google.com/"); |
| 3878 | // when the no authentication data flag is set. |
| 3879 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3880 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3881 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3882 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3883 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3884 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3885 | session_deps_.net_log = log.bound().net_log(); |
| 3886 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3887 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3888 | // Since we have proxy, should use full url |
| 3889 | MockWrite data_writes1[] = { |
| 3890 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3891 | "Host: www.google.com\r\n" |
| 3892 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3893 | |
| 3894 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3895 | // be issuing -- the final header line contains the credentials. |
| 3896 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3897 | "Host: www.google.com\r\n" |
| 3898 | "Proxy-Connection: keep-alive\r\n" |
| 3899 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3900 | }; |
| 3901 | |
| 3902 | // The proxy responds to the GET with a 407, using a persistent |
| 3903 | // connection. |
| 3904 | MockRead data_reads1[] = { |
| 3905 | // No credentials. |
| 3906 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3907 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3908 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3909 | MockRead("Content-Length: 0\r\n\r\n"), |
| 3910 | |
| 3911 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3912 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3913 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3914 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3915 | }; |
| 3916 | |
| 3917 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3918 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3919 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3920 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3921 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3923 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3924 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3925 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3926 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3928 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3930 | |
| 3931 | rv = callback1.WaitForResult(); |
| 3932 | EXPECT_EQ(OK, rv); |
| 3933 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3934 | LoadTimingInfo load_timing_info; |
| 3935 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3936 | TestLoadTimingNotReused(load_timing_info, |
| 3937 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3938 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3939 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3940 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3941 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3942 | EXPECT_EQ(407, response->headers->response_code()); |
| 3943 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3944 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3946 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3948 | rv = trans->RestartWithAuth( |
| 3949 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3950 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3951 | |
| 3952 | rv = callback2.WaitForResult(); |
| 3953 | EXPECT_EQ(OK, rv); |
| 3954 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3955 | load_timing_info = LoadTimingInfo(); |
| 3956 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3957 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 3958 | TestLoadTimingReused(load_timing_info); |
| 3959 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3960 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3961 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3962 | |
| 3963 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3964 | EXPECT_EQ(200, response->headers->response_code()); |
| 3965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3966 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3967 | |
| 3968 | // The password prompt info should not be set. |
| 3969 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3970 | } |
| 3971 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3972 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3973 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3974 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3975 | request.method = "GET"; |
| 3976 | request.url = GURL("https://www.google.com/"); |
| 3977 | request.load_flags = 0; |
| 3978 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3979 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3980 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3981 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3982 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3983 | // Since we have proxy, should try to establish tunnel. |
| 3984 | MockWrite data_writes[] = { |
| 3985 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 3986 | "Host: www.google.com\r\n" |
| 3987 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3988 | }; |
| 3989 | |
| 3990 | MockRead data_reads[] = { |
| 3991 | status, |
| 3992 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3993 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3994 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3995 | }; |
| 3996 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3997 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3998 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3999 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4001 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4002 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4003 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4004 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4005 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4006 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4007 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4008 | |
| 4009 | rv = callback.WaitForResult(); |
| 4010 | EXPECT_EQ(expected_status, rv); |
| 4011 | } |
| 4012 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4013 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4014 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4015 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4016 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4017 | } |
| 4018 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4019 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4020 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4021 | } |
| 4022 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4023 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4024 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4025 | } |
| 4026 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4027 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4028 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4029 | } |
| 4030 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4031 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4032 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4033 | } |
| 4034 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4035 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4036 | ConnectStatusHelper( |
| 4037 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4038 | } |
| 4039 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4040 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4041 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4042 | } |
| 4043 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4044 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4045 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4046 | } |
| 4047 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4048 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4049 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4050 | } |
| 4051 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4052 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4053 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4054 | } |
| 4055 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4056 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4057 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4058 | } |
| 4059 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4060 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4061 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4062 | } |
| 4063 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4064 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4065 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4066 | } |
| 4067 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4068 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4069 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4070 | } |
| 4071 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4072 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4073 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4074 | } |
| 4075 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4076 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4077 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4078 | } |
| 4079 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4080 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4081 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4082 | } |
| 4083 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4084 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4085 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4086 | } |
| 4087 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4088 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4089 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4090 | } |
| 4091 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4092 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4093 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4094 | } |
| 4095 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4096 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4097 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4098 | } |
| 4099 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4100 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4101 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4102 | } |
| 4103 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4104 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4105 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4106 | } |
| 4107 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4108 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4109 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4110 | } |
| 4111 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4112 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4113 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4114 | } |
| 4115 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4116 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4117 | ConnectStatusHelperWithExpectedStatus( |
| 4118 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4119 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4120 | } |
| 4121 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4122 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4123 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4124 | } |
| 4125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4126 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4127 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4128 | } |
| 4129 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4130 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4131 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4132 | } |
| 4133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4134 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4135 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4136 | } |
| 4137 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4138 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4139 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4140 | } |
| 4141 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4142 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4143 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4144 | } |
| 4145 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4146 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4147 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4148 | } |
| 4149 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4150 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4151 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4152 | } |
| 4153 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4154 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4155 | ConnectStatusHelper( |
| 4156 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4157 | } |
| 4158 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4159 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4160 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4161 | } |
| 4162 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4163 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4164 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4165 | } |
| 4166 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4167 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4168 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4169 | } |
| 4170 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4171 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4172 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4173 | } |
| 4174 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4175 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4176 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4177 | } |
| 4178 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4179 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4180 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4181 | } |
| 4182 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4183 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4184 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4185 | } |
| 4186 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4187 | // Test the flow when both the proxy server AND origin server require |
| 4188 | // authentication. Again, this uses basic auth for both since that is |
| 4189 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4190 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4191 | HttpRequestInfo request; |
| 4192 | request.method = "GET"; |
| 4193 | request.url = GURL("http://www.google.com/"); |
| 4194 | request.load_flags = 0; |
| 4195 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4196 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4197 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4198 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4199 | |
| 4200 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4201 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4202 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4203 | MockWrite data_writes1[] = { |
| 4204 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4205 | "Host: www.google.com\r\n" |
| 4206 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4207 | }; |
| 4208 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4209 | MockRead data_reads1[] = { |
| 4210 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4211 | // Give a couple authenticate options (only the middle one is actually |
| 4212 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4213 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4214 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4215 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4216 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4217 | // Large content-length -- won't matter, as connection will be reset. |
| 4218 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4219 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4220 | }; |
| 4221 | |
| 4222 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4223 | // request we should be issuing -- the final header line contains the |
| 4224 | // proxy's credentials. |
| 4225 | MockWrite data_writes2[] = { |
| 4226 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4227 | "Host: www.google.com\r\n" |
| 4228 | "Proxy-Connection: keep-alive\r\n" |
| 4229 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4230 | }; |
| 4231 | |
| 4232 | // Now the proxy server lets the request pass through to origin server. |
| 4233 | // The origin server responds with a 401. |
| 4234 | MockRead data_reads2[] = { |
| 4235 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4236 | // Note: We are using the same realm-name as the proxy server. This is |
| 4237 | // completely valid, as realms are unique across hosts. |
| 4238 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4239 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4240 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4241 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4242 | }; |
| 4243 | |
| 4244 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4245 | // the credentials for both the proxy and origin server. |
| 4246 | MockWrite data_writes3[] = { |
| 4247 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4248 | "Host: www.google.com\r\n" |
| 4249 | "Proxy-Connection: keep-alive\r\n" |
| 4250 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4251 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4252 | }; |
| 4253 | |
| 4254 | // Lastly we get the desired content. |
| 4255 | MockRead data_reads3[] = { |
| 4256 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4257 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4258 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4259 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4260 | }; |
| 4261 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4262 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4263 | data_writes1, arraysize(data_writes1)); |
| 4264 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4265 | data_writes2, arraysize(data_writes2)); |
| 4266 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4267 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4268 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4269 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4270 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4272 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4274 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4276 | |
| 4277 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4278 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4279 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4280 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4281 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4282 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4284 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4286 | rv = trans->RestartWithAuth( |
| 4287 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4288 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4289 | |
| 4290 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4291 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4292 | |
| 4293 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4294 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4295 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4297 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4299 | rv = trans->RestartWithAuth( |
| 4300 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4301 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4302 | |
| 4303 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4304 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4305 | |
| 4306 | response = trans->GetResponseInfo(); |
| 4307 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4308 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4309 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4310 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4311 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4312 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4313 | // authorization headers. |
| 4314 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4315 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4316 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4317 | // bytes in the debugger. |
| 4318 | |
| 4319 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4320 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4321 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4322 | request.method = "GET"; |
| 4323 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4324 | |
| 4325 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4326 | // to other auth schemes. |
| 4327 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4328 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4329 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4330 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4332 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4333 | MockWrite data_writes1[] = { |
| 4334 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4335 | "Host: 172.22.68.17\r\n" |
| 4336 | "Connection: keep-alive\r\n\r\n"), |
| 4337 | }; |
| 4338 | |
| 4339 | MockRead data_reads1[] = { |
| 4340 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4341 | // Negotiate and NTLM are often requested together. However, we only want |
| 4342 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4343 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4344 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4345 | MockRead("Connection: close\r\n"), |
| 4346 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4347 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4348 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4349 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4350 | }; |
| 4351 | |
| 4352 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4353 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4354 | // request we should be issuing -- the final header line contains a Type |
| 4355 | // 1 message. |
| 4356 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4357 | "Host: 172.22.68.17\r\n" |
| 4358 | "Connection: keep-alive\r\n" |
| 4359 | "Authorization: NTLM " |
| 4360 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4361 | |
| 4362 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4363 | // (the credentials for the origin server). The second request continues |
| 4364 | // on the same connection. |
| 4365 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4366 | "Host: 172.22.68.17\r\n" |
| 4367 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4368 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4369 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4370 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4371 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4372 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4373 | }; |
| 4374 | |
| 4375 | MockRead data_reads2[] = { |
| 4376 | // The origin server responds with a Type 2 message. |
| 4377 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4378 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4379 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4380 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4381 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4382 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4383 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4384 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4385 | "BtAAAAAAA=\r\n"), |
| 4386 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4387 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4388 | MockRead("You are not authorized to view this page\r\n"), |
| 4389 | |
| 4390 | // Lastly we get the desired content. |
| 4391 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4392 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4393 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4394 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4395 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4396 | }; |
| 4397 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4398 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4399 | data_writes1, arraysize(data_writes1)); |
| 4400 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4401 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4402 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4403 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4405 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4406 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4407 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4408 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4410 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4411 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4412 | |
| 4413 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4414 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4415 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4416 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4417 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4418 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4419 | ASSERT_FALSE(response == NULL); |
| 4420 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4422 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4423 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4424 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4425 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4426 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4427 | |
| 4428 | rv = callback2.WaitForResult(); |
| 4429 | EXPECT_EQ(OK, rv); |
| 4430 | |
| 4431 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4432 | |
| 4433 | response = trans->GetResponseInfo(); |
| 4434 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4435 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4437 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4439 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4440 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4441 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4442 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4443 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4444 | |
| 4445 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4446 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4447 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4448 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4449 | } |
| 4450 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4451 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4452 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4453 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4454 | request.method = "GET"; |
| 4455 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4456 | request.load_flags = 0; |
| 4457 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4458 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4459 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4460 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4461 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4462 | MockWrite data_writes1[] = { |
| 4463 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4464 | "Host: 172.22.68.17\r\n" |
| 4465 | "Connection: keep-alive\r\n\r\n"), |
| 4466 | }; |
| 4467 | |
| 4468 | MockRead data_reads1[] = { |
| 4469 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4470 | // Negotiate and NTLM are often requested together. However, we only want |
| 4471 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4472 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4473 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4474 | MockRead("Connection: close\r\n"), |
| 4475 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4476 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4477 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4478 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4479 | }; |
| 4480 | |
| 4481 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4482 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4483 | // request we should be issuing -- the final header line contains a Type |
| 4484 | // 1 message. |
| 4485 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4486 | "Host: 172.22.68.17\r\n" |
| 4487 | "Connection: keep-alive\r\n" |
| 4488 | "Authorization: NTLM " |
| 4489 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4490 | |
| 4491 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4492 | // (the credentials for the origin server). The second request continues |
| 4493 | // on the same connection. |
| 4494 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4495 | "Host: 172.22.68.17\r\n" |
| 4496 | "Connection: keep-alive\r\n" |
| 4497 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4498 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4499 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4500 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4501 | "4Ww7b7E=\r\n\r\n"), |
| 4502 | }; |
| 4503 | |
| 4504 | MockRead data_reads2[] = { |
| 4505 | // The origin server responds with a Type 2 message. |
| 4506 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4507 | MockRead("WWW-Authenticate: NTLM " |
| 4508 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4509 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4510 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4511 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4512 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4513 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4514 | "BtAAAAAAA=\r\n"), |
| 4515 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4516 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4517 | MockRead("You are not authorized to view this page\r\n"), |
| 4518 | |
| 4519 | // Wrong password. |
| 4520 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4521 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4522 | MockRead("Connection: close\r\n"), |
| 4523 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4524 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4525 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4526 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4527 | }; |
| 4528 | |
| 4529 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4530 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4531 | // request we should be issuing -- the final header line contains a Type |
| 4532 | // 1 message. |
| 4533 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4534 | "Host: 172.22.68.17\r\n" |
| 4535 | "Connection: keep-alive\r\n" |
| 4536 | "Authorization: NTLM " |
| 4537 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4538 | |
| 4539 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4540 | // (the credentials for the origin server). The second request continues |
| 4541 | // on the same connection. |
| 4542 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4543 | "Host: 172.22.68.17\r\n" |
| 4544 | "Connection: keep-alive\r\n" |
| 4545 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4546 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4547 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4548 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4549 | "+4MUm7c=\r\n\r\n"), |
| 4550 | }; |
| 4551 | |
| 4552 | MockRead data_reads3[] = { |
| 4553 | // The origin server responds with a Type 2 message. |
| 4554 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4555 | MockRead("WWW-Authenticate: NTLM " |
| 4556 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4557 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4558 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4559 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4560 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4561 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4562 | "BtAAAAAAA=\r\n"), |
| 4563 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4564 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4565 | MockRead("You are not authorized to view this page\r\n"), |
| 4566 | |
| 4567 | // Lastly we get the desired content. |
| 4568 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4569 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4570 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4571 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4572 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4573 | }; |
| 4574 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4575 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4576 | data_writes1, arraysize(data_writes1)); |
| 4577 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4578 | data_writes2, arraysize(data_writes2)); |
| 4579 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4580 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4581 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4582 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4583 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4585 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4586 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4587 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4589 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4590 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4591 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4592 | |
| 4593 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4594 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4595 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4596 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4597 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4598 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4599 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4600 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4601 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4602 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4603 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4604 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4605 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4606 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4607 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4608 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4609 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4610 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4611 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4612 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4613 | TestCompletionCallback callback3; |
| 4614 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4615 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4616 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4617 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4618 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4619 | |
| 4620 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4621 | ASSERT_FALSE(response == NULL); |
| 4622 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4624 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4625 | |
| 4626 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4627 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4628 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4629 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4630 | |
| 4631 | rv = callback4.WaitForResult(); |
| 4632 | EXPECT_EQ(OK, rv); |
| 4633 | |
| 4634 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4635 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4636 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4637 | |
| 4638 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4639 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4641 | |
| 4642 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4643 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4644 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4645 | response = trans->GetResponseInfo(); |
| 4646 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4647 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4648 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4649 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4650 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4651 | // Test reading a server response which has only headers, and no body. |
| 4652 | // After some maximum number of bytes is consumed, the transaction should |
| 4653 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4654 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4655 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4656 | request.method = "GET"; |
| 4657 | request.url = GURL("http://www.google.com/"); |
| 4658 | request.load_flags = 0; |
| 4659 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4660 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4661 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4662 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4663 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4664 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4665 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4666 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4667 | |
| 4668 | MockRead data_reads[] = { |
| 4669 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4670 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4671 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4672 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4673 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4674 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4675 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4677 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4678 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4679 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4680 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4681 | |
| 4682 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4683 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4684 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4685 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4686 | EXPECT_TRUE(response == NULL); |
| 4687 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4688 | |
| 4689 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4690 | // establish tunnel. |
| 4691 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4692 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4693 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4694 | HttpRequestInfo request; |
| 4695 | request.method = "GET"; |
| 4696 | request.url = GURL("https://www.google.com/"); |
| 4697 | request.load_flags = 0; |
| 4698 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4699 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4700 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 4701 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4702 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4703 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4704 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4705 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4706 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4707 | // Since we have proxy, should try to establish tunnel. |
| 4708 | MockWrite data_writes1[] = { |
| 4709 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4710 | "Host: www.google.com\r\n" |
| 4711 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4712 | }; |
| 4713 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 4714 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4715 | // connection. Usually a proxy would return 501 (not implemented), |
| 4716 | // or 200 (tunnel established). |
| 4717 | MockRead data_reads1[] = { |
| 4718 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 4719 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4720 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4721 | }; |
| 4722 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4723 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4724 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4725 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4727 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4729 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4730 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4731 | |
| 4732 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4733 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4734 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4735 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4736 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4737 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4738 | // Empty the current queue. This is necessary because idle sockets are |
| 4739 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4740 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4741 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4742 | // We now check to make sure the TCPClientSocket was not added back to |
| 4743 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4744 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4745 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4746 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4747 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4748 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4749 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4750 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4751 | // Make sure that we recycle a socket after reading all of the response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4752 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4753 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4754 | request.method = "GET"; |
| 4755 | request.url = GURL("http://www.google.com/"); |
| 4756 | request.load_flags = 0; |
| 4757 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4758 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4759 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4760 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4761 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4762 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4763 | MockRead data_reads[] = { |
| 4764 | // A part of the response body is received with the response headers. |
| 4765 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 4766 | // The rest of the response body is received in two parts. |
| 4767 | MockRead("lo"), |
| 4768 | MockRead(" world"), |
| 4769 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4771 | }; |
| 4772 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4773 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4775 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4776 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4778 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4779 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4780 | |
| 4781 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4782 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4783 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4784 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4785 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4786 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4787 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4788 | std::string status_line = response->headers->GetStatusLine(); |
| 4789 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 4790 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4791 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4792 | |
| 4793 | std::string response_data; |
| 4794 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4795 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4796 | EXPECT_EQ("hello world", response_data); |
| 4797 | |
| 4798 | // Empty the current queue. This is necessary because idle sockets are |
| 4799 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4800 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4801 | |
| 4802 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4803 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4804 | } |
| 4805 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4806 | // Make sure that we recycle a SSL socket after reading all of the response |
| 4807 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4808 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4809 | HttpRequestInfo request; |
| 4810 | request.method = "GET"; |
| 4811 | request.url = GURL("https://www.google.com/"); |
| 4812 | request.load_flags = 0; |
| 4813 | |
| 4814 | MockWrite data_writes[] = { |
| 4815 | MockWrite("GET / HTTP/1.1\r\n" |
| 4816 | "Host: www.google.com\r\n" |
| 4817 | "Connection: keep-alive\r\n\r\n"), |
| 4818 | }; |
| 4819 | |
| 4820 | MockRead data_reads[] = { |
| 4821 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4822 | MockRead("Content-Length: 11\r\n\r\n"), |
| 4823 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4825 | }; |
| 4826 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4827 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4828 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4829 | |
| 4830 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4831 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4834 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4835 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4836 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4837 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4838 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4840 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4841 | |
| 4842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4843 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4844 | |
| 4845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4846 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4847 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4848 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4849 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4850 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4851 | |
| 4852 | std::string response_data; |
| 4853 | rv = ReadTransaction(trans.get(), &response_data); |
| 4854 | EXPECT_EQ(OK, rv); |
| 4855 | EXPECT_EQ("hello world", response_data); |
| 4856 | |
| 4857 | // Empty the current queue. This is necessary because idle sockets are |
| 4858 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4859 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4860 | |
| 4861 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4862 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 4866 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4867 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4868 | HttpRequestInfo request; |
| 4869 | request.method = "GET"; |
| 4870 | request.url = GURL("https://www.google.com/"); |
| 4871 | request.load_flags = 0; |
| 4872 | |
| 4873 | MockWrite data_writes[] = { |
| 4874 | MockWrite("GET / HTTP/1.1\r\n" |
| 4875 | "Host: www.google.com\r\n" |
| 4876 | "Connection: keep-alive\r\n\r\n"), |
| 4877 | MockWrite("GET / HTTP/1.1\r\n" |
| 4878 | "Host: www.google.com\r\n" |
| 4879 | "Connection: keep-alive\r\n\r\n"), |
| 4880 | }; |
| 4881 | |
| 4882 | MockRead data_reads[] = { |
| 4883 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4884 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4885 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4886 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4887 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4888 | }; |
| 4889 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4890 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4891 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4892 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4894 | |
| 4895 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4896 | data_writes, arraysize(data_writes)); |
| 4897 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 4898 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4899 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4902 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4903 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4904 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4905 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4906 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4907 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4908 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4909 | |
| 4910 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4911 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4912 | |
| 4913 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4914 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4915 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4916 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4917 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4918 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4919 | |
| 4920 | std::string response_data; |
| 4921 | rv = ReadTransaction(trans.get(), &response_data); |
| 4922 | EXPECT_EQ(OK, rv); |
| 4923 | EXPECT_EQ("hello world", response_data); |
| 4924 | |
| 4925 | // Empty the current queue. This is necessary because idle sockets are |
| 4926 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4927 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4928 | |
| 4929 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4930 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4931 | |
| 4932 | // Now start the second transaction, which should reuse the previous socket. |
| 4933 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4934 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4936 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4937 | |
| 4938 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4939 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4940 | |
| 4941 | response = trans->GetResponseInfo(); |
| 4942 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4943 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4944 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4945 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4946 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4947 | |
| 4948 | rv = ReadTransaction(trans.get(), &response_data); |
| 4949 | EXPECT_EQ(OK, rv); |
| 4950 | EXPECT_EQ("hello world", response_data); |
| 4951 | |
| 4952 | // Empty the current queue. This is necessary because idle sockets are |
| 4953 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4954 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4955 | |
| 4956 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4957 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4958 | } |
| 4959 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4960 | // Make sure that we recycle a socket after a zero-length response. |
| 4961 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4962 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4963 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4964 | request.method = "GET"; |
| 4965 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 4966 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 4967 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 4968 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 4969 | request.load_flags = 0; |
| 4970 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4971 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4972 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4973 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4974 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4975 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4976 | MockRead data_reads[] = { |
| 4977 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 4978 | "Content-Length: 0\r\n" |
| 4979 | "Content-Type: text/html\r\n\r\n"), |
| 4980 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4982 | }; |
| 4983 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4984 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4987 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4989 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4990 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4991 | |
| 4992 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4993 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4994 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4995 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4996 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4997 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4998 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4999 | std::string status_line = response->headers->GetStatusLine(); |
| 5000 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5001 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5002 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5003 | |
| 5004 | std::string response_data; |
| 5005 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5006 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5007 | EXPECT_EQ("", response_data); |
| 5008 | |
| 5009 | // Empty the current queue. This is necessary because idle sockets are |
| 5010 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5011 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5012 | |
| 5013 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5014 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5015 | } |
| 5016 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5017 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5018 | ScopedVector<UploadElementReader> element_readers; |
| 5019 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5020 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5021 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5022 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5023 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5024 | // after use. |
| 5025 | request[0].method = "GET"; |
| 5026 | request[0].url = GURL("http://www.google.com/"); |
| 5027 | request[0].load_flags = 0; |
| 5028 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5029 | // transaction 1. The first attempts fails when writing the POST data. |
| 5030 | // This causes the transaction to retry with a new socket. The second |
| 5031 | // attempt succeeds. |
| 5032 | request[1].method = "POST"; |
| 5033 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5034 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5035 | request[1].load_flags = 0; |
| 5036 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5037 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5038 | |
| 5039 | // The first socket is used for transaction 1 and the first attempt of |
| 5040 | // transaction 2. |
| 5041 | |
| 5042 | // The response of transaction 1. |
| 5043 | MockRead data_reads1[] = { |
| 5044 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5045 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5046 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5047 | }; |
| 5048 | // The mock write results of transaction 1 and the first attempt of |
| 5049 | // transaction 2. |
| 5050 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5051 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5052 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5053 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5054 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5055 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5056 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5057 | |
| 5058 | // The second socket is used for the second attempt of transaction 2. |
| 5059 | |
| 5060 | // The response of transaction 2. |
| 5061 | MockRead data_reads2[] = { |
| 5062 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5063 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5064 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5065 | }; |
| 5066 | // The mock write results of the second attempt of transaction 2. |
| 5067 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5068 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5069 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5070 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5071 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5072 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5073 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5074 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5075 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5076 | |
| 5077 | const char* kExpectedResponseData[] = { |
| 5078 | "hello world", "welcome" |
| 5079 | }; |
| 5080 | |
| 5081 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5082 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5085 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5087 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5089 | |
| 5090 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5091 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5092 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5093 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5094 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5095 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5096 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5097 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5098 | |
| 5099 | std::string response_data; |
| 5100 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5101 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5102 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5103 | } |
| 5104 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5105 | |
| 5106 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5107 | // an identity in the URL. The request should be sent as normal, but when |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5108 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5109 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5110 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5111 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5112 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5113 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5114 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5115 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5116 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5117 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5118 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5119 | // The password contains an escaped character -- for this test to pass it |
| 5120 | // will need to be unescaped by HttpNetworkTransaction. |
| 5121 | EXPECT_EQ("b%40r", request.url.password()); |
| 5122 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5123 | MockWrite data_writes1[] = { |
| 5124 | MockWrite("GET / HTTP/1.1\r\n" |
| 5125 | "Host: www.google.com\r\n" |
| 5126 | "Connection: keep-alive\r\n\r\n"), |
| 5127 | }; |
| 5128 | |
| 5129 | MockRead data_reads1[] = { |
| 5130 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5131 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5132 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5133 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5134 | }; |
| 5135 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5136 | // After the challenge above, the transaction will be restarted using the |
| 5137 | // identity from the url (foo, b@r) to answer the challenge. |
| 5138 | MockWrite data_writes2[] = { |
| 5139 | MockWrite("GET / HTTP/1.1\r\n" |
| 5140 | "Host: www.google.com\r\n" |
| 5141 | "Connection: keep-alive\r\n" |
| 5142 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 5143 | }; |
| 5144 | |
| 5145 | MockRead data_reads2[] = { |
| 5146 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5147 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5148 | MockRead(SYNCHRONOUS, OK), |
| 5149 | }; |
| 5150 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5151 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5152 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5153 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5154 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5155 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5156 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5158 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5159 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5161 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5162 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5163 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5164 | |
| 5165 | TestCompletionCallback callback2; |
| 5166 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5167 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5168 | rv = callback2.WaitForResult(); |
| 5169 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5170 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5171 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5172 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5173 | ASSERT_TRUE(response != NULL); |
| 5174 | |
| 5175 | // There is no challenge info, since the identity in URL worked. |
| 5176 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5177 | |
| 5178 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5179 | |
| 5180 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5181 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5185 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5186 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5187 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5188 | HttpRequestInfo request; |
| 5189 | request.method = "GET"; |
| 5190 | // Note: the URL has a username:password in it. The password "baz" is |
| 5191 | // wrong (should be "bar"). |
| 5192 | request.url = GURL("http://foo:[email protected]/"); |
| 5193 | |
| 5194 | request.load_flags = LOAD_NORMAL; |
| 5195 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5196 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5197 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5198 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5199 | |
| 5200 | MockWrite data_writes1[] = { |
| 5201 | MockWrite("GET / HTTP/1.1\r\n" |
| 5202 | "Host: www.google.com\r\n" |
| 5203 | "Connection: keep-alive\r\n\r\n"), |
| 5204 | }; |
| 5205 | |
| 5206 | MockRead data_reads1[] = { |
| 5207 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5208 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5209 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5210 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5211 | }; |
| 5212 | |
| 5213 | // After the challenge above, the transaction will be restarted using the |
| 5214 | // identity from the url (foo, baz) to answer the challenge. |
| 5215 | MockWrite data_writes2[] = { |
| 5216 | MockWrite("GET / HTTP/1.1\r\n" |
| 5217 | "Host: www.google.com\r\n" |
| 5218 | "Connection: keep-alive\r\n" |
| 5219 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 5220 | }; |
| 5221 | |
| 5222 | MockRead data_reads2[] = { |
| 5223 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5224 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5225 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5226 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5227 | }; |
| 5228 | |
| 5229 | // After the challenge above, the transaction will be restarted using the |
| 5230 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5231 | MockWrite data_writes3[] = { |
| 5232 | MockWrite("GET / HTTP/1.1\r\n" |
| 5233 | "Host: www.google.com\r\n" |
| 5234 | "Connection: keep-alive\r\n" |
| 5235 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5236 | }; |
| 5237 | |
| 5238 | MockRead data_reads3[] = { |
| 5239 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5240 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5241 | MockRead(SYNCHRONOUS, OK), |
| 5242 | }; |
| 5243 | |
| 5244 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5245 | data_writes1, arraysize(data_writes1)); |
| 5246 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5247 | data_writes2, arraysize(data_writes2)); |
| 5248 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5249 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5250 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5251 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5252 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5253 | |
| 5254 | TestCompletionCallback callback1; |
| 5255 | |
| 5256 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5257 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5258 | |
| 5259 | rv = callback1.WaitForResult(); |
| 5260 | EXPECT_EQ(OK, rv); |
| 5261 | |
| 5262 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5263 | TestCompletionCallback callback2; |
| 5264 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5266 | rv = callback2.WaitForResult(); |
| 5267 | EXPECT_EQ(OK, rv); |
| 5268 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5269 | |
| 5270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5271 | ASSERT_TRUE(response != NULL); |
| 5272 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5273 | |
| 5274 | TestCompletionCallback callback3; |
| 5275 | rv = trans->RestartWithAuth( |
| 5276 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5278 | rv = callback3.WaitForResult(); |
| 5279 | EXPECT_EQ(OK, rv); |
| 5280 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5281 | |
| 5282 | response = trans->GetResponseInfo(); |
| 5283 | ASSERT_TRUE(response != NULL); |
| 5284 | |
| 5285 | // There is no challenge info, since the identity worked. |
| 5286 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5287 | |
| 5288 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5289 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5290 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5291 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5292 | } |
| 5293 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5294 | |
| 5295 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5296 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5297 | // from the URL should never be used. |
| 5298 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5299 | HttpRequestInfo request; |
| 5300 | request.method = "GET"; |
| 5301 | request.url = GURL("http://foo:[email protected]/"); |
| 5302 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5303 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5304 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5305 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5306 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5307 | |
| 5308 | MockWrite data_writes1[] = { |
| 5309 | MockWrite("GET / HTTP/1.1\r\n" |
| 5310 | "Host: www.google.com\r\n" |
| 5311 | "Connection: keep-alive\r\n\r\n"), |
| 5312 | }; |
| 5313 | |
| 5314 | MockRead data_reads1[] = { |
| 5315 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5316 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5317 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5318 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5319 | }; |
| 5320 | |
| 5321 | // After the challenge above, the transaction will be restarted using the |
| 5322 | // identity supplied by the user, not the one in the URL, to answer the |
| 5323 | // challenge. |
| 5324 | MockWrite data_writes3[] = { |
| 5325 | MockWrite("GET / HTTP/1.1\r\n" |
| 5326 | "Host: www.google.com\r\n" |
| 5327 | "Connection: keep-alive\r\n" |
| 5328 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5329 | }; |
| 5330 | |
| 5331 | MockRead data_reads3[] = { |
| 5332 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5333 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5334 | MockRead(SYNCHRONOUS, OK), |
| 5335 | }; |
| 5336 | |
| 5337 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5338 | data_writes1, arraysize(data_writes1)); |
| 5339 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5340 | data_writes3, arraysize(data_writes3)); |
| 5341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5342 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5343 | |
| 5344 | TestCompletionCallback callback1; |
| 5345 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5346 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5347 | rv = callback1.WaitForResult(); |
| 5348 | EXPECT_EQ(OK, rv); |
| 5349 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5350 | |
| 5351 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5352 | ASSERT_TRUE(response != NULL); |
| 5353 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5354 | |
| 5355 | TestCompletionCallback callback3; |
| 5356 | rv = trans->RestartWithAuth( |
| 5357 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5359 | rv = callback3.WaitForResult(); |
| 5360 | EXPECT_EQ(OK, rv); |
| 5361 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5362 | |
| 5363 | response = trans->GetResponseInfo(); |
| 5364 | ASSERT_TRUE(response != NULL); |
| 5365 | |
| 5366 | // There is no challenge info, since the identity worked. |
| 5367 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5368 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5369 | |
| 5370 | // Empty the current queue. |
| 5371 | base::MessageLoop::current()->RunUntilIdle(); |
| 5372 | } |
| 5373 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5374 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5375 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5376 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5377 | |
| 5378 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5379 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5380 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5381 | request.method = "GET"; |
| 5382 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5383 | request.load_flags = 0; |
| 5384 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5385 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5386 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5387 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5388 | MockWrite data_writes1[] = { |
| 5389 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5390 | "Host: www.google.com\r\n" |
| 5391 | "Connection: keep-alive\r\n\r\n"), |
| 5392 | }; |
| 5393 | |
| 5394 | MockRead data_reads1[] = { |
| 5395 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5396 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5397 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5398 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5399 | }; |
| 5400 | |
| 5401 | // Resend with authorization (username=foo, password=bar) |
| 5402 | MockWrite data_writes2[] = { |
| 5403 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5404 | "Host: www.google.com\r\n" |
| 5405 | "Connection: keep-alive\r\n" |
| 5406 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5407 | }; |
| 5408 | |
| 5409 | // Sever accepts the authorization. |
| 5410 | MockRead data_reads2[] = { |
| 5411 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5412 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5413 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5414 | }; |
| 5415 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5416 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5417 | data_writes1, arraysize(data_writes1)); |
| 5418 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5419 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5420 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5421 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5422 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5423 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5425 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5426 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5427 | |
| 5428 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5429 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5430 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5431 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5432 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5433 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5435 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5437 | rv = trans->RestartWithAuth( |
| 5438 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5440 | |
| 5441 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5442 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5443 | |
| 5444 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5445 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5446 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5447 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5448 | } |
| 5449 | |
| 5450 | // ------------------------------------------------------------------------ |
| 5451 | |
| 5452 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5453 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5454 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5455 | request.method = "GET"; |
| 5456 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5457 | // protection space as MyRealm1. |
| 5458 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5459 | request.load_flags = 0; |
| 5460 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5461 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5462 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5463 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5464 | MockWrite data_writes1[] = { |
| 5465 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5466 | "Host: www.google.com\r\n" |
| 5467 | "Connection: keep-alive\r\n" |
| 5468 | // Send preemptive authorization for MyRealm1 |
| 5469 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5470 | }; |
| 5471 | |
| 5472 | // The server didn't like the preemptive authorization, and |
| 5473 | // challenges us for a different realm (MyRealm2). |
| 5474 | MockRead data_reads1[] = { |
| 5475 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5476 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5477 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5478 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5479 | }; |
| 5480 | |
| 5481 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5482 | MockWrite data_writes2[] = { |
| 5483 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5484 | "Host: www.google.com\r\n" |
| 5485 | "Connection: keep-alive\r\n" |
| 5486 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 5487 | }; |
| 5488 | |
| 5489 | // Sever accepts the authorization. |
| 5490 | MockRead data_reads2[] = { |
| 5491 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5492 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5493 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5494 | }; |
| 5495 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5496 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5497 | data_writes1, arraysize(data_writes1)); |
| 5498 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5499 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5500 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5501 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5503 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5505 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5506 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5507 | |
| 5508 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5509 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5510 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5511 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5512 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5513 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5514 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 5515 | EXPECT_EQ("www.google.com:80", |
| 5516 | response->auth_challenge->challenger.ToString()); |
| 5517 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5518 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5520 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5521 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5522 | rv = trans->RestartWithAuth( |
| 5523 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5524 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5525 | |
| 5526 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5527 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5528 | |
| 5529 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5530 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5531 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5532 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5533 | } |
| 5534 | |
| 5535 | // ------------------------------------------------------------------------ |
| 5536 | |
| 5537 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5538 | // succeed with preemptive authorization. |
| 5539 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5540 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5541 | request.method = "GET"; |
| 5542 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 5543 | request.load_flags = 0; |
| 5544 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5545 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5546 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5547 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5548 | MockWrite data_writes1[] = { |
| 5549 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 5550 | "Host: www.google.com\r\n" |
| 5551 | "Connection: keep-alive\r\n" |
| 5552 | // The authorization for MyRealm1 gets sent preemptively |
| 5553 | // (since the url is in the same protection space) |
| 5554 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5555 | }; |
| 5556 | |
| 5557 | // Sever accepts the preemptive authorization |
| 5558 | MockRead data_reads1[] = { |
| 5559 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5560 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5561 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5562 | }; |
| 5563 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5564 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5565 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5566 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5568 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5570 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5571 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5572 | |
| 5573 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5574 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5575 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5576 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5577 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5578 | |
| 5579 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5580 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5581 | } |
| 5582 | |
| 5583 | // ------------------------------------------------------------------------ |
| 5584 | |
| 5585 | // Transaction 4: request another URL in MyRealm (however the |
| 5586 | // url is not known to belong to the protection space, so no pre-auth). |
| 5587 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5588 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5589 | request.method = "GET"; |
| 5590 | request.url = GURL("http://www.google.com/x/1"); |
| 5591 | request.load_flags = 0; |
| 5592 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5593 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5594 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5595 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5596 | MockWrite data_writes1[] = { |
| 5597 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5598 | "Host: www.google.com\r\n" |
| 5599 | "Connection: keep-alive\r\n\r\n"), |
| 5600 | }; |
| 5601 | |
| 5602 | MockRead data_reads1[] = { |
| 5603 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5604 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5605 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5606 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5607 | }; |
| 5608 | |
| 5609 | // Resend with authorization from MyRealm's cache. |
| 5610 | MockWrite data_writes2[] = { |
| 5611 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5612 | "Host: www.google.com\r\n" |
| 5613 | "Connection: keep-alive\r\n" |
| 5614 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5615 | }; |
| 5616 | |
| 5617 | // Sever accepts the authorization. |
| 5618 | MockRead data_reads2[] = { |
| 5619 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5620 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5621 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5622 | }; |
| 5623 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5624 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5625 | data_writes1, arraysize(data_writes1)); |
| 5626 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5627 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5628 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5629 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5631 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5633 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5634 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5635 | |
| 5636 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5637 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5638 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5639 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5640 | TestCompletionCallback callback2; |
| 5641 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5642 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5643 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5644 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5645 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5646 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5647 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5648 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5649 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5650 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5651 | } |
| 5652 | |
| 5653 | // ------------------------------------------------------------------------ |
| 5654 | |
| 5655 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5656 | // cached identity. Should invalidate and re-prompt. |
| 5657 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5658 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5659 | request.method = "GET"; |
| 5660 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5661 | request.load_flags = 0; |
| 5662 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5663 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5664 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5665 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5666 | MockWrite data_writes1[] = { |
| 5667 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5668 | "Host: www.google.com\r\n" |
| 5669 | "Connection: keep-alive\r\n\r\n"), |
| 5670 | }; |
| 5671 | |
| 5672 | MockRead data_reads1[] = { |
| 5673 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5674 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5675 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5676 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5677 | }; |
| 5678 | |
| 5679 | // Resend with authorization from cache for MyRealm. |
| 5680 | MockWrite data_writes2[] = { |
| 5681 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5682 | "Host: www.google.com\r\n" |
| 5683 | "Connection: keep-alive\r\n" |
| 5684 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5685 | }; |
| 5686 | |
| 5687 | // Sever rejects the authorization. |
| 5688 | MockRead data_reads2[] = { |
| 5689 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5690 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5691 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5692 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5693 | }; |
| 5694 | |
| 5695 | // At this point we should prompt for new credentials for MyRealm. |
| 5696 | // Restart with username=foo3, password=foo4. |
| 5697 | MockWrite data_writes3[] = { |
| 5698 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5699 | "Host: www.google.com\r\n" |
| 5700 | "Connection: keep-alive\r\n" |
| 5701 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 5702 | }; |
| 5703 | |
| 5704 | // Sever accepts the authorization. |
| 5705 | MockRead data_reads3[] = { |
| 5706 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5707 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5708 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5709 | }; |
| 5710 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5711 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5712 | data_writes1, arraysize(data_writes1)); |
| 5713 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5714 | data_writes2, arraysize(data_writes2)); |
| 5715 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5716 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5717 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5718 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5719 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5721 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5723 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5724 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5725 | |
| 5726 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5727 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5728 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5729 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5730 | TestCompletionCallback callback2; |
| 5731 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5733 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5734 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5735 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5736 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5737 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5738 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5739 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5741 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5742 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5743 | rv = trans->RestartWithAuth( |
| 5744 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5746 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5747 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5748 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5749 | |
| 5750 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5751 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5752 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5753 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5754 | } |
| 5755 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5756 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5757 | // Tests that nonce count increments when multiple auth attempts |
| 5758 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5759 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 5760 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 5761 | new HttpAuthHandlerDigest::Factory(); |
| 5762 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 5763 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 5764 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5765 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 5766 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5767 | |
| 5768 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5769 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5770 | HttpRequestInfo request; |
| 5771 | request.method = "GET"; |
| 5772 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5773 | request.load_flags = 0; |
| 5774 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5775 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5776 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5777 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5778 | MockWrite data_writes1[] = { |
| 5779 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5780 | "Host: www.google.com\r\n" |
| 5781 | "Connection: keep-alive\r\n\r\n"), |
| 5782 | }; |
| 5783 | |
| 5784 | MockRead data_reads1[] = { |
| 5785 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5786 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 5787 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5789 | }; |
| 5790 | |
| 5791 | // Resend with authorization (username=foo, password=bar) |
| 5792 | MockWrite data_writes2[] = { |
| 5793 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5794 | "Host: www.google.com\r\n" |
| 5795 | "Connection: keep-alive\r\n" |
| 5796 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5797 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 5798 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 5799 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5800 | }; |
| 5801 | |
| 5802 | // Sever accepts the authorization. |
| 5803 | MockRead data_reads2[] = { |
| 5804 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5806 | }; |
| 5807 | |
| 5808 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5809 | data_writes1, arraysize(data_writes1)); |
| 5810 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5811 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5812 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5813 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5815 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5817 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5819 | |
| 5820 | rv = callback1.WaitForResult(); |
| 5821 | EXPECT_EQ(OK, rv); |
| 5822 | |
| 5823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5824 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5825 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5827 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5829 | rv = trans->RestartWithAuth( |
| 5830 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5832 | |
| 5833 | rv = callback2.WaitForResult(); |
| 5834 | EXPECT_EQ(OK, rv); |
| 5835 | |
| 5836 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5837 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5838 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5839 | } |
| 5840 | |
| 5841 | // ------------------------------------------------------------------------ |
| 5842 | |
| 5843 | // Transaction 2: Request another resource in digestive's protection space. |
| 5844 | // This will preemptively add an Authorization header which should have an |
| 5845 | // "nc" value of 2 (as compared to 1 in the first use. |
| 5846 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5847 | HttpRequestInfo request; |
| 5848 | request.method = "GET"; |
| 5849 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5850 | // protection space as digest. |
| 5851 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5852 | request.load_flags = 0; |
| 5853 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5854 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5855 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5856 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5857 | MockWrite data_writes1[] = { |
| 5858 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5859 | "Host: www.google.com\r\n" |
| 5860 | "Connection: keep-alive\r\n" |
| 5861 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5862 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 5863 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 5864 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5865 | }; |
| 5866 | |
| 5867 | // Sever accepts the authorization. |
| 5868 | MockRead data_reads1[] = { |
| 5869 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5870 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5872 | }; |
| 5873 | |
| 5874 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5875 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5876 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5878 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5880 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5881 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5882 | |
| 5883 | rv = callback1.WaitForResult(); |
| 5884 | EXPECT_EQ(OK, rv); |
| 5885 | |
| 5886 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5887 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5888 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5889 | } |
| 5890 | } |
| 5891 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5892 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5893 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5894 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5895 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5896 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5898 | |
| 5899 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5900 | trans->read_buf_ = new IOBuffer(15); |
| 5901 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5902 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5903 | |
| 5904 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 5905 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5906 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5907 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5908 | response->response_time = base::Time::Now(); |
| 5909 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5910 | |
| 5911 | { // Setup state for response_.vary_data |
| 5912 | HttpRequestInfo request; |
| 5913 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 5914 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 5915 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 5916 | request.extra_headers.SetHeader("Foo", "1"); |
| 5917 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5918 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5919 | } |
| 5920 | |
| 5921 | // Cause the above state to be reset. |
| 5922 | trans->ResetStateForRestart(); |
| 5923 | |
| 5924 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 5925 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5926 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5927 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5928 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5929 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 5930 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5931 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5932 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5933 | } |
| 5934 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5935 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5936 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5937 | HttpRequestInfo request; |
| 5938 | request.method = "GET"; |
| 5939 | request.url = GURL("https://www.google.com/"); |
| 5940 | request.load_flags = 0; |
| 5941 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5942 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5943 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5944 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5945 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5946 | MockWrite data_writes[] = { |
| 5947 | MockWrite("GET / HTTP/1.1\r\n" |
| 5948 | "Host: www.google.com\r\n" |
| 5949 | "Connection: keep-alive\r\n\r\n"), |
| 5950 | }; |
| 5951 | |
| 5952 | MockRead data_reads[] = { |
| 5953 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5954 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5955 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5956 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5957 | }; |
| 5958 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 5959 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5960 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5961 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5962 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 5963 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5964 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5965 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 5966 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5967 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 5968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5970 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5972 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5973 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5974 | |
| 5975 | rv = callback.WaitForResult(); |
| 5976 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 5977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5978 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5979 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5980 | |
| 5981 | rv = callback.WaitForResult(); |
| 5982 | EXPECT_EQ(OK, rv); |
| 5983 | |
| 5984 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5985 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5986 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5987 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5988 | } |
| 5989 | |
| 5990 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 5991 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5992 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5993 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5994 | |
| 5995 | HttpRequestInfo request; |
| 5996 | request.method = "GET"; |
| 5997 | request.url = GURL("https://www.google.com/"); |
| 5998 | request.load_flags = 0; |
| 5999 | |
| 6000 | MockWrite proxy_writes[] = { |
| 6001 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6002 | "Host: www.google.com\r\n" |
| 6003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6004 | }; |
| 6005 | |
| 6006 | MockRead proxy_reads[] = { |
| 6007 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6008 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6009 | }; |
| 6010 | |
| 6011 | MockWrite data_writes[] = { |
| 6012 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6013 | "Host: www.google.com\r\n" |
| 6014 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6015 | MockWrite("GET / HTTP/1.1\r\n" |
| 6016 | "Host: www.google.com\r\n" |
| 6017 | "Connection: keep-alive\r\n\r\n"), |
| 6018 | }; |
| 6019 | |
| 6020 | MockRead data_reads[] = { |
| 6021 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6022 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6023 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6024 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6026 | }; |
| 6027 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6028 | StaticSocketDataProvider ssl_bad_certificate( |
| 6029 | proxy_reads, arraysize(proxy_reads), |
| 6030 | proxy_writes, arraysize(proxy_writes)); |
| 6031 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6032 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6033 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6034 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6035 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6036 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6037 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6041 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6042 | |
| 6043 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6044 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6045 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6046 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6047 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6050 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6051 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6052 | |
| 6053 | rv = callback.WaitForResult(); |
| 6054 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6056 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6058 | |
| 6059 | rv = callback.WaitForResult(); |
| 6060 | EXPECT_EQ(OK, rv); |
| 6061 | |
| 6062 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6063 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6064 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6065 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6066 | } |
| 6067 | } |
| 6068 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6069 | |
| 6070 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6071 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6072 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6073 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6074 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6075 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6076 | |
| 6077 | HttpRequestInfo request; |
| 6078 | request.method = "GET"; |
| 6079 | request.url = GURL("https://www.google.com/"); |
| 6080 | request.load_flags = 0; |
| 6081 | |
| 6082 | MockWrite data_writes[] = { |
| 6083 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6084 | "Host: www.google.com\r\n" |
| 6085 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6086 | MockWrite("GET / HTTP/1.1\r\n" |
| 6087 | "Host: www.google.com\r\n" |
| 6088 | "Connection: keep-alive\r\n\r\n"), |
| 6089 | }; |
| 6090 | |
| 6091 | MockRead data_reads[] = { |
| 6092 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6094 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6095 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6096 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6097 | }; |
| 6098 | |
| 6099 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6100 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6101 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6102 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6103 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6104 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6105 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6108 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6109 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6110 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6111 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6112 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6114 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6115 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6116 | |
| 6117 | rv = callback.WaitForResult(); |
| 6118 | EXPECT_EQ(OK, rv); |
| 6119 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6120 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6121 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6122 | |
| 6123 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6124 | EXPECT_EQ(200, response->headers->response_code()); |
| 6125 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6126 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6127 | |
| 6128 | LoadTimingInfo load_timing_info; |
| 6129 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6130 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6131 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6132 | } |
| 6133 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6134 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6135 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6136 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6137 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6138 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6139 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6140 | |
| 6141 | HttpRequestInfo request; |
| 6142 | request.method = "GET"; |
| 6143 | request.url = GURL("https://www.google.com/"); |
| 6144 | request.load_flags = 0; |
| 6145 | |
| 6146 | MockWrite data_writes[] = { |
| 6147 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6148 | "Host: www.google.com\r\n" |
| 6149 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6150 | }; |
| 6151 | |
| 6152 | MockRead data_reads[] = { |
| 6153 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6154 | MockRead("Location: http://login.example.com/\r\n"), |
| 6155 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6156 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6157 | }; |
| 6158 | |
| 6159 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6160 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6161 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6162 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6163 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6166 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6167 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6168 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6169 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6170 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6172 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6173 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6174 | |
| 6175 | rv = callback.WaitForResult(); |
| 6176 | EXPECT_EQ(OK, rv); |
| 6177 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6178 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6179 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6180 | |
| 6181 | EXPECT_EQ(302, response->headers->response_code()); |
| 6182 | std::string url; |
| 6183 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6184 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6185 | |
| 6186 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6187 | // timing for the proxy connection instead of the connection to the host, |
| 6188 | // and no send / receive times. |
| 6189 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6190 | LoadTimingInfo load_timing_info; |
| 6191 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6192 | |
| 6193 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 6194 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 6195 | |
| 6196 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6197 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6198 | load_timing_info.proxy_resolve_end); |
| 6199 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6200 | load_timing_info.connect_timing.connect_start); |
| 6201 | ExpectConnectTimingHasTimes( |
| 6202 | load_timing_info.connect_timing, |
| 6203 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6204 | |
| 6205 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6206 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6207 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6211 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6212 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6213 | ProxyService::CreateFixed("https://proxy:70")); |
| 6214 | |
| 6215 | HttpRequestInfo request; |
| 6216 | request.method = "GET"; |
| 6217 | request.url = GURL("https://www.google.com/"); |
| 6218 | request.load_flags = 0; |
| 6219 | |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 6220 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 6221 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6222 | scoped_ptr<SpdyFrame> goaway( |
| 6223 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6224 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6225 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 6226 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6227 | }; |
| 6228 | |
| 6229 | static const char* const kExtraHeaders[] = { |
| 6230 | "location", |
| 6231 | "http://login.example.com/", |
| 6232 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6233 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6234 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6235 | arraysize(kExtraHeaders)/2, 1)); |
| 6236 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6237 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6238 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6239 | }; |
| 6240 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6241 | DelayedSocketData data( |
| 6242 | 1, // wait for one write to finish before reading. |
| 6243 | data_reads, arraysize(data_reads), |
| 6244 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6245 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6246 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6247 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6248 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6251 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6252 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6253 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6254 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6255 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6257 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6258 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6259 | |
| 6260 | rv = callback.WaitForResult(); |
| 6261 | EXPECT_EQ(OK, rv); |
| 6262 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6263 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6264 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6265 | |
| 6266 | EXPECT_EQ(302, response->headers->response_code()); |
| 6267 | std::string url; |
| 6268 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6269 | EXPECT_EQ("http://login.example.com/", url); |
| 6270 | } |
| 6271 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6272 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6273 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6274 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6275 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6276 | ProxyService::CreateFixed("https://proxy:70")); |
| 6277 | |
| 6278 | HttpRequestInfo request; |
| 6279 | request.method = "GET"; |
| 6280 | request.url = GURL("https://www.google.com/"); |
| 6281 | request.load_flags = 0; |
| 6282 | |
| 6283 | MockWrite data_writes[] = { |
| 6284 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6285 | "Host: www.google.com\r\n" |
| 6286 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6287 | }; |
| 6288 | |
| 6289 | MockRead data_reads[] = { |
| 6290 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6291 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6292 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6293 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6294 | }; |
| 6295 | |
| 6296 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6297 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6298 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6299 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6301 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6303 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6304 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6305 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6306 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6309 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6311 | |
| 6312 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6313 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6314 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6315 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6316 | } |
| 6317 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6318 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6319 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6320 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6321 | session_deps_.proxy_service.reset( |
| 6322 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6323 | |
| 6324 | HttpRequestInfo request; |
| 6325 | request.method = "GET"; |
| 6326 | request.url = GURL("https://www.google.com/"); |
| 6327 | request.load_flags = 0; |
| 6328 | |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 6329 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 6330 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6331 | scoped_ptr<SpdyFrame> rst( |
| 6332 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6333 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6334 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6335 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6336 | }; |
| 6337 | |
| 6338 | static const char* const kExtraHeaders[] = { |
| 6339 | "location", |
| 6340 | "http://login.example.com/", |
| 6341 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6342 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6343 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6344 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6345 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6346 | spdy_util_.ConstructSpdyBodyFrame( |
| 6347 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6348 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6349 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6350 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6351 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6352 | }; |
| 6353 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6354 | DelayedSocketData data( |
| 6355 | 1, // wait for one write to finish before reading. |
| 6356 | data_reads, arraysize(data_reads), |
| 6357 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6358 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6359 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6360 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6364 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6365 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6366 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6367 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6368 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6370 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6372 | |
| 6373 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6374 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6375 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6376 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6377 | } |
| 6378 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6379 | // Test the request-challenge-retry sequence for basic auth, through |
| 6380 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6381 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6382 | HttpRequestInfo request; |
| 6383 | request.method = "GET"; |
| 6384 | request.url = GURL("https://www.google.com/"); |
| 6385 | // when the no authentication data flag is set. |
| 6386 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 6387 | |
| 6388 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6389 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6390 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6391 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6392 | session_deps_.net_log = log.bound().net_log(); |
| 6393 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6394 | |
| 6395 | // Since we have proxy, should try to establish tunnel. |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 6396 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 6397 | LOWEST)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6398 | scoped_ptr<SpdyFrame> rst( |
| 6399 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6400 | |
| 6401 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6402 | // be issuing -- the final header line contains the credentials. |
| 6403 | const char* const kAuthCredentials[] = { |
| 6404 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6405 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6406 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 6407 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6408 | // fetch https://www.google.com/ via HTTP |
| 6409 | const char get[] = "GET / HTTP/1.1\r\n" |
| 6410 | "Host: www.google.com\r\n" |
| 6411 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6412 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6413 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6414 | |
| 6415 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6416 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 6417 | CreateMockWrite(*rst, 4, ASYNC), |
| 6418 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6419 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6420 | }; |
| 6421 | |
| 6422 | // The proxy responds to the connect with a 407, using a persistent |
| 6423 | // connection. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6424 | const char* const kAuthStatus = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6425 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6426 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6427 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6428 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6429 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6430 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6431 | scoped_ptr<SpdyFrame> conn_resp( |
| 6432 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6433 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6434 | "Content-Length: 5\r\n\r\n"; |
| 6435 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6436 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6437 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6438 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6439 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6440 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6441 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 6442 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 6443 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 6444 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 6445 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6446 | }; |
| 6447 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6448 | OrderedSocketData spdy_data( |
| 6449 | spdy_reads, arraysize(spdy_reads), |
| 6450 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6451 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6452 | // Negotiate SPDY to the proxy |
| 6453 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6454 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6455 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6456 | // Vanilla SSL to the server |
| 6457 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6458 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6459 | |
| 6460 | TestCompletionCallback callback1; |
| 6461 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6462 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6463 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6464 | |
| 6465 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6466 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6467 | |
| 6468 | rv = callback1.WaitForResult(); |
| 6469 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 6470 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6471 | log.GetEntries(&entries); |
| 6472 | size_t pos = ExpectLogContainsSomewhere( |
| 6473 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6474 | NetLog::PHASE_NONE); |
| 6475 | ExpectLogContainsSomewhere( |
| 6476 | entries, pos, |
| 6477 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6478 | NetLog::PHASE_NONE); |
| 6479 | |
| 6480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6481 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6482 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6483 | EXPECT_EQ(407, response->headers->response_code()); |
| 6484 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6485 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6486 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6487 | |
| 6488 | TestCompletionCallback callback2; |
| 6489 | |
| 6490 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6491 | callback2.callback()); |
| 6492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6493 | |
| 6494 | rv = callback2.WaitForResult(); |
| 6495 | EXPECT_EQ(OK, rv); |
| 6496 | |
| 6497 | response = trans->GetResponseInfo(); |
| 6498 | ASSERT_TRUE(response != NULL); |
| 6499 | |
| 6500 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6501 | EXPECT_EQ(200, response->headers->response_code()); |
| 6502 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6503 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6504 | |
| 6505 | // The password prompt info should not be set. |
| 6506 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6507 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6508 | LoadTimingInfo load_timing_info; |
| 6509 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6510 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6511 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6512 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6513 | trans.reset(); |
| 6514 | session->CloseAllConnections(); |
| 6515 | } |
| 6516 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6517 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6518 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6519 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6520 | HttpRequestInfo request; |
| 6521 | HttpRequestInfo push_request; |
| 6522 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6523 | request.method = "GET"; |
| 6524 | request.url = GURL("http://www.google.com/"); |
| 6525 | push_request.method = "GET"; |
| 6526 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6527 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6528 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6529 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6530 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6531 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6532 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6533 | |
| 6534 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6535 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6536 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6537 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6538 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6539 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6540 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6541 | |
| 6542 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6543 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6544 | }; |
| 6545 | |
| 6546 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6547 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6548 | |
| 6549 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6550 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6551 | |
| 6552 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6553 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6554 | 0, |
| 6555 | 2, |
| 6556 | 1, |
| 6557 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6558 | const char kPushedData[] = "pushed"; |
| 6559 | scoped_ptr<SpdyFrame> stream2_body( |
| 6560 | spdy_util_.ConstructSpdyBodyFrame( |
| 6561 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6562 | |
| 6563 | MockRead spdy_reads[] = { |
| 6564 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6565 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6566 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6567 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6568 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6569 | }; |
| 6570 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6571 | OrderedSocketData spdy_data( |
| 6572 | spdy_reads, arraysize(spdy_reads), |
| 6573 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6574 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6575 | // Negotiate SPDY to the proxy |
| 6576 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6577 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6579 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6580 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6581 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6582 | TestCompletionCallback callback; |
| 6583 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6584 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6585 | |
| 6586 | rv = callback.WaitForResult(); |
| 6587 | EXPECT_EQ(OK, rv); |
| 6588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6589 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6590 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6592 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6593 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6594 | |
| 6595 | rv = callback.WaitForResult(); |
| 6596 | EXPECT_EQ(OK, rv); |
| 6597 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6598 | |
| 6599 | ASSERT_TRUE(response != NULL); |
| 6600 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6601 | |
| 6602 | EXPECT_EQ(200, response->headers->response_code()); |
| 6603 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6604 | |
| 6605 | std::string response_data; |
| 6606 | rv = ReadTransaction(trans.get(), &response_data); |
| 6607 | EXPECT_EQ(OK, rv); |
| 6608 | EXPECT_EQ("hello!", response_data); |
| 6609 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6610 | LoadTimingInfo load_timing_info; |
| 6611 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6612 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6613 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6614 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6615 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6616 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6617 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6618 | |
| 6619 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6620 | EXPECT_EQ(OK, rv); |
| 6621 | EXPECT_EQ("pushed", response_data); |
| 6622 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6623 | LoadTimingInfo push_load_timing_info; |
| 6624 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6625 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6626 | // The transactions should share a socket ID, despite being for different |
| 6627 | // origins. |
| 6628 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6629 | push_load_timing_info.socket_log_id); |
| 6630 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6631 | trans.reset(); |
| 6632 | push_trans.reset(); |
| 6633 | session->CloseAllConnections(); |
| 6634 | } |
| 6635 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6636 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6637 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6638 | HttpRequestInfo request; |
| 6639 | |
| 6640 | request.method = "GET"; |
| 6641 | request.url = GURL("http://www.google.com/"); |
| 6642 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6643 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6644 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6645 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6646 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6647 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6648 | |
| 6649 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6650 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6651 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6652 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6653 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6654 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6655 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6656 | |
| 6657 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6658 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6659 | |
| 6660 | MockWrite spdy_writes[] = { |
| 6661 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6662 | CreateMockWrite(*push_rst, 4), |
| 6663 | }; |
| 6664 | |
| 6665 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6666 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6667 | |
| 6668 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6669 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6670 | |
| 6671 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6672 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6673 | 0, |
| 6674 | 2, |
| 6675 | 1, |
| 6676 | "https://www.another-origin.com/foo.dat")); |
| 6677 | |
| 6678 | MockRead spdy_reads[] = { |
| 6679 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6680 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6681 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6682 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6683 | }; |
| 6684 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6685 | OrderedSocketData spdy_data( |
| 6686 | spdy_reads, arraysize(spdy_reads), |
| 6687 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6688 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6689 | // Negotiate SPDY to the proxy |
| 6690 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6691 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6693 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6694 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6696 | TestCompletionCallback callback; |
| 6697 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6698 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6699 | |
| 6700 | rv = callback.WaitForResult(); |
| 6701 | EXPECT_EQ(OK, rv); |
| 6702 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6703 | |
| 6704 | ASSERT_TRUE(response != NULL); |
| 6705 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6706 | |
| 6707 | EXPECT_EQ(200, response->headers->response_code()); |
| 6708 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6709 | |
| 6710 | std::string response_data; |
| 6711 | rv = ReadTransaction(trans.get(), &response_data); |
| 6712 | EXPECT_EQ(OK, rv); |
| 6713 | EXPECT_EQ("hello!", response_data); |
| 6714 | |
| 6715 | trans.reset(); |
| 6716 | session->CloseAllConnections(); |
| 6717 | } |
| 6718 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6719 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 6720 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6721 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6722 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 6723 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6724 | |
| 6725 | HttpRequestInfo request; |
| 6726 | request.method = "GET"; |
| 6727 | request.url = GURL("https://www.google.com/"); |
| 6728 | request.load_flags = 0; |
| 6729 | |
| 6730 | // Attempt to fetch the URL from a server with a bad cert |
| 6731 | MockWrite bad_cert_writes[] = { |
| 6732 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6733 | "Host: www.google.com\r\n" |
| 6734 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6735 | }; |
| 6736 | |
| 6737 | MockRead bad_cert_reads[] = { |
| 6738 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6739 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6740 | }; |
| 6741 | |
| 6742 | // Attempt to fetch the URL with a good cert |
| 6743 | MockWrite good_data_writes[] = { |
| 6744 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6745 | "Host: www.google.com\r\n" |
| 6746 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6747 | MockWrite("GET / HTTP/1.1\r\n" |
| 6748 | "Host: www.google.com\r\n" |
| 6749 | "Connection: keep-alive\r\n\r\n"), |
| 6750 | }; |
| 6751 | |
| 6752 | MockRead good_cert_reads[] = { |
| 6753 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6754 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6755 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6756 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6757 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6758 | }; |
| 6759 | |
| 6760 | StaticSocketDataProvider ssl_bad_certificate( |
| 6761 | bad_cert_reads, arraysize(bad_cert_reads), |
| 6762 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 6763 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 6764 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6765 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6766 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6767 | |
| 6768 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6770 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6771 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6772 | |
| 6773 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6774 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6778 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6779 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6780 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6781 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6782 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6784 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6785 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6786 | |
| 6787 | rv = callback.WaitForResult(); |
| 6788 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6790 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6791 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6792 | |
| 6793 | rv = callback.WaitForResult(); |
| 6794 | EXPECT_EQ(OK, rv); |
| 6795 | |
| 6796 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6797 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6798 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6799 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6800 | } |
| 6801 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6802 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6803 | HttpRequestInfo request; |
| 6804 | request.method = "GET"; |
| 6805 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6806 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6807 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6808 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6809 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6810 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6812 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6813 | MockWrite data_writes[] = { |
| 6814 | MockWrite("GET / HTTP/1.1\r\n" |
| 6815 | "Host: www.google.com\r\n" |
| 6816 | "Connection: keep-alive\r\n" |
| 6817 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6818 | }; |
| 6819 | |
| 6820 | // Lastly, the server responds with the actual content. |
| 6821 | MockRead data_reads[] = { |
| 6822 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6823 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6824 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6826 | }; |
| 6827 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6828 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6829 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6830 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6831 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6832 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6834 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6835 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6836 | |
| 6837 | rv = callback.WaitForResult(); |
| 6838 | EXPECT_EQ(OK, rv); |
| 6839 | } |
| 6840 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6841 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6842 | HttpRequestInfo request; |
| 6843 | request.method = "GET"; |
| 6844 | request.url = GURL("https://www.google.com/"); |
| 6845 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6846 | "Chromium Ultra Awesome X Edition"); |
| 6847 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6848 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6849 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6850 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6851 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6852 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6853 | MockWrite data_writes[] = { |
| 6854 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6855 | "Host: www.google.com\r\n" |
| 6856 | "Proxy-Connection: keep-alive\r\n" |
| 6857 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6858 | }; |
| 6859 | MockRead data_reads[] = { |
| 6860 | // Return an error, so the transaction stops here (this test isn't |
| 6861 | // interested in the rest). |
| 6862 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6863 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6864 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 6865 | }; |
| 6866 | |
| 6867 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6868 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6869 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6871 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6873 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6875 | |
| 6876 | rv = callback.WaitForResult(); |
| 6877 | EXPECT_EQ(OK, rv); |
| 6878 | } |
| 6879 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6880 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6881 | HttpRequestInfo request; |
| 6882 | request.method = "GET"; |
| 6883 | request.url = GURL("http://www.google.com/"); |
| 6884 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6885 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 6886 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6887 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6888 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6889 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6891 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6892 | MockWrite data_writes[] = { |
| 6893 | MockWrite("GET / HTTP/1.1\r\n" |
| 6894 | "Host: www.google.com\r\n" |
| 6895 | "Connection: keep-alive\r\n" |
| 6896 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 6897 | }; |
| 6898 | |
| 6899 | // Lastly, the server responds with the actual content. |
| 6900 | MockRead data_reads[] = { |
| 6901 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6902 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6903 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6904 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6905 | }; |
| 6906 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6907 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6908 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6909 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6911 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6913 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6914 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6915 | |
| 6916 | rv = callback.WaitForResult(); |
| 6917 | EXPECT_EQ(OK, rv); |
| 6918 | } |
| 6919 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6920 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6921 | HttpRequestInfo request; |
| 6922 | request.method = "POST"; |
| 6923 | request.url = GURL("http://www.google.com/"); |
| 6924 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6925 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6926 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6928 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6929 | MockWrite data_writes[] = { |
| 6930 | MockWrite("POST / HTTP/1.1\r\n" |
| 6931 | "Host: www.google.com\r\n" |
| 6932 | "Connection: keep-alive\r\n" |
| 6933 | "Content-Length: 0\r\n\r\n"), |
| 6934 | }; |
| 6935 | |
| 6936 | // Lastly, the server responds with the actual content. |
| 6937 | MockRead data_reads[] = { |
| 6938 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6939 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6940 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6941 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6942 | }; |
| 6943 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6944 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6945 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6948 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6950 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6951 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6952 | |
| 6953 | rv = callback.WaitForResult(); |
| 6954 | EXPECT_EQ(OK, rv); |
| 6955 | } |
| 6956 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6957 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6958 | HttpRequestInfo request; |
| 6959 | request.method = "PUT"; |
| 6960 | request.url = GURL("http://www.google.com/"); |
| 6961 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6963 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6964 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6965 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6966 | MockWrite data_writes[] = { |
| 6967 | MockWrite("PUT / HTTP/1.1\r\n" |
| 6968 | "Host: www.google.com\r\n" |
| 6969 | "Connection: keep-alive\r\n" |
| 6970 | "Content-Length: 0\r\n\r\n"), |
| 6971 | }; |
| 6972 | |
| 6973 | // Lastly, the server responds with the actual content. |
| 6974 | MockRead data_reads[] = { |
| 6975 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6976 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6977 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6978 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6979 | }; |
| 6980 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6981 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6982 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6983 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6985 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6987 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6988 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6989 | |
| 6990 | rv = callback.WaitForResult(); |
| 6991 | EXPECT_EQ(OK, rv); |
| 6992 | } |
| 6993 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6994 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6995 | HttpRequestInfo request; |
| 6996 | request.method = "HEAD"; |
| 6997 | request.url = GURL("http://www.google.com/"); |
| 6998 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6999 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7000 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7001 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7002 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7003 | MockWrite data_writes[] = { |
| 7004 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7005 | "Host: www.google.com\r\n" |
| 7006 | "Connection: keep-alive\r\n" |
| 7007 | "Content-Length: 0\r\n\r\n"), |
| 7008 | }; |
| 7009 | |
| 7010 | // Lastly, the server responds with the actual content. |
| 7011 | MockRead data_reads[] = { |
| 7012 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7013 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7014 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7015 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7016 | }; |
| 7017 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7018 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7019 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7022 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7024 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7025 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7026 | |
| 7027 | rv = callback.WaitForResult(); |
| 7028 | EXPECT_EQ(OK, rv); |
| 7029 | } |
| 7030 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7031 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7032 | HttpRequestInfo request; |
| 7033 | request.method = "GET"; |
| 7034 | request.url = GURL("http://www.google.com/"); |
| 7035 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7036 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7037 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7038 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7039 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7040 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7041 | MockWrite data_writes[] = { |
| 7042 | MockWrite("GET / HTTP/1.1\r\n" |
| 7043 | "Host: www.google.com\r\n" |
| 7044 | "Connection: keep-alive\r\n" |
| 7045 | "Pragma: no-cache\r\n" |
| 7046 | "Cache-Control: no-cache\r\n\r\n"), |
| 7047 | }; |
| 7048 | |
| 7049 | // Lastly, the server responds with the actual content. |
| 7050 | MockRead data_reads[] = { |
| 7051 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7052 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7053 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7054 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7055 | }; |
| 7056 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7057 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7058 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7061 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7063 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7064 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7065 | |
| 7066 | rv = callback.WaitForResult(); |
| 7067 | EXPECT_EQ(OK, rv); |
| 7068 | } |
| 7069 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7070 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7071 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7072 | HttpRequestInfo request; |
| 7073 | request.method = "GET"; |
| 7074 | request.url = GURL("http://www.google.com/"); |
| 7075 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7076 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7077 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7078 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7080 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7081 | MockWrite data_writes[] = { |
| 7082 | MockWrite("GET / HTTP/1.1\r\n" |
| 7083 | "Host: www.google.com\r\n" |
| 7084 | "Connection: keep-alive\r\n" |
| 7085 | "Cache-Control: max-age=0\r\n\r\n"), |
| 7086 | }; |
| 7087 | |
| 7088 | // Lastly, the server responds with the actual content. |
| 7089 | MockRead data_reads[] = { |
| 7090 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7091 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7092 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7093 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7094 | }; |
| 7095 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7096 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7097 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7098 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7100 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7102 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7104 | |
| 7105 | rv = callback.WaitForResult(); |
| 7106 | EXPECT_EQ(OK, rv); |
| 7107 | } |
| 7108 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7109 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7110 | HttpRequestInfo request; |
| 7111 | request.method = "GET"; |
| 7112 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7113 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7114 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7115 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7116 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7117 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7118 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7119 | MockWrite data_writes[] = { |
| 7120 | MockWrite("GET / HTTP/1.1\r\n" |
| 7121 | "Host: www.google.com\r\n" |
| 7122 | "Connection: keep-alive\r\n" |
| 7123 | "FooHeader: Bar\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] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7131 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7132 | }; |
| 7133 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7134 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7135 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7136 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7138 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7140 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7141 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7142 | |
| 7143 | rv = callback.WaitForResult(); |
| 7144 | EXPECT_EQ(OK, rv); |
| 7145 | } |
| 7146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7147 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7148 | HttpRequestInfo request; |
| 7149 | request.method = "GET"; |
| 7150 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7151 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7152 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7153 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7154 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7155 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7156 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7157 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7158 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7159 | MockWrite data_writes[] = { |
| 7160 | MockWrite("GET / HTTP/1.1\r\n" |
| 7161 | "Host: www.google.com\r\n" |
| 7162 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7163 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7164 | "hEllo: Kitty\r\n" |
| 7165 | "FoO: bar\r\n\r\n"), |
| 7166 | }; |
| 7167 | |
| 7168 | // Lastly, the server responds with the actual content. |
| 7169 | MockRead data_reads[] = { |
| 7170 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7171 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7172 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7173 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7174 | }; |
| 7175 | |
| 7176 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7177 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7180 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7182 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7184 | |
| 7185 | rv = callback.WaitForResult(); |
| 7186 | EXPECT_EQ(OK, rv); |
| 7187 | } |
| 7188 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7189 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7190 | HttpRequestInfo request; |
| 7191 | request.method = "GET"; |
| 7192 | request.url = GURL("http://www.google.com/"); |
| 7193 | request.load_flags = 0; |
| 7194 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7195 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7196 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7197 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7198 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7199 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7200 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7201 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7203 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7204 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7205 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7206 | |
| 7207 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7208 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7209 | MockWrite("GET / HTTP/1.1\r\n" |
| 7210 | "Host: www.google.com\r\n" |
| 7211 | "Connection: keep-alive\r\n\r\n") |
| 7212 | }; |
| 7213 | |
| 7214 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7215 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7216 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7217 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7218 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7219 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7220 | }; |
| 7221 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7222 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7223 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7226 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7228 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7229 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7230 | |
| 7231 | rv = callback.WaitForResult(); |
| 7232 | EXPECT_EQ(OK, rv); |
| 7233 | |
| 7234 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7235 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7236 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7237 | LoadTimingInfo load_timing_info; |
| 7238 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7239 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7240 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7241 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7242 | std::string response_text; |
| 7243 | rv = ReadTransaction(trans.get(), &response_text); |
| 7244 | EXPECT_EQ(OK, rv); |
| 7245 | EXPECT_EQ("Payload", response_text); |
| 7246 | } |
| 7247 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7248 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7249 | HttpRequestInfo request; |
| 7250 | request.method = "GET"; |
| 7251 | request.url = GURL("https://www.google.com/"); |
| 7252 | request.load_flags = 0; |
| 7253 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7254 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7255 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7256 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7257 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7258 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7259 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7260 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7262 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7263 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7264 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7265 | |
| 7266 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7267 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7268 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7269 | MockWrite("GET / HTTP/1.1\r\n" |
| 7270 | "Host: www.google.com\r\n" |
| 7271 | "Connection: keep-alive\r\n\r\n") |
| 7272 | }; |
| 7273 | |
| 7274 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7275 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7276 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7277 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7278 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7279 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7280 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7281 | }; |
| 7282 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7283 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7284 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7286 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7287 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7290 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7292 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7294 | |
| 7295 | rv = callback.WaitForResult(); |
| 7296 | EXPECT_EQ(OK, rv); |
| 7297 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7298 | LoadTimingInfo load_timing_info; |
| 7299 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7300 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7301 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7302 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7303 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7304 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7305 | |
| 7306 | std::string response_text; |
| 7307 | rv = ReadTransaction(trans.get(), &response_text); |
| 7308 | EXPECT_EQ(OK, rv); |
| 7309 | EXPECT_EQ("Payload", response_text); |
| 7310 | } |
| 7311 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7312 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7313 | HttpRequestInfo request; |
| 7314 | request.method = "GET"; |
| 7315 | request.url = GURL("http://www.google.com/"); |
| 7316 | request.load_flags = 0; |
| 7317 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7318 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7319 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
| 7320 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7321 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7322 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7323 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7324 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7325 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7326 | |
| 7327 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7328 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7329 | |
| 7330 | MockWrite data_writes[] = { |
| 7331 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7332 | MockWrite("GET / HTTP/1.1\r\n" |
| 7333 | "Host: www.google.com\r\n" |
| 7334 | "Connection: keep-alive\r\n\r\n") |
| 7335 | }; |
| 7336 | |
| 7337 | MockRead data_reads[] = { |
| 7338 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7339 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7340 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7341 | MockRead("Payload"), |
| 7342 | MockRead(SYNCHRONOUS, OK) |
| 7343 | }; |
| 7344 | |
| 7345 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7346 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7348 | |
| 7349 | TestCompletionCallback callback; |
| 7350 | |
| 7351 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7352 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7353 | |
| 7354 | rv = callback.WaitForResult(); |
| 7355 | EXPECT_EQ(OK, rv); |
| 7356 | |
| 7357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7358 | ASSERT_TRUE(response != NULL); |
| 7359 | |
| 7360 | LoadTimingInfo load_timing_info; |
| 7361 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7362 | TestLoadTimingNotReused(load_timing_info, |
| 7363 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7364 | |
| 7365 | std::string response_text; |
| 7366 | rv = ReadTransaction(trans.get(), &response_text); |
| 7367 | EXPECT_EQ(OK, rv); |
| 7368 | EXPECT_EQ("Payload", response_text); |
| 7369 | } |
| 7370 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7371 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7372 | HttpRequestInfo request; |
| 7373 | request.method = "GET"; |
| 7374 | request.url = GURL("http://www.google.com/"); |
| 7375 | request.load_flags = 0; |
| 7376 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7377 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7378 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7379 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7380 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7381 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7382 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7383 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7384 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7385 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7386 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7387 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7388 | const char kSOCKS5OkRequest[] = { |
| 7389 | 0x05, // Version |
| 7390 | 0x01, // Command (CONNECT) |
| 7391 | 0x00, // Reserved. |
| 7392 | 0x03, // Address type (DOMAINNAME). |
| 7393 | 0x0E, // Length of domain (14) |
| 7394 | // Domain string: |
| 7395 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7396 | 0x00, 0x50, // 16-bit port (80) |
| 7397 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7398 | const char kSOCKS5OkResponse[] = |
| 7399 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7400 | |
| 7401 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7402 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7403 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7404 | MockWrite("GET / HTTP/1.1\r\n" |
| 7405 | "Host: www.google.com\r\n" |
| 7406 | "Connection: keep-alive\r\n\r\n") |
| 7407 | }; |
| 7408 | |
| 7409 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7410 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7411 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7412 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7413 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7414 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7415 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7416 | }; |
| 7417 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7418 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7419 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7422 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7424 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7426 | |
| 7427 | rv = callback.WaitForResult(); |
| 7428 | EXPECT_EQ(OK, rv); |
| 7429 | |
| 7430 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7431 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7432 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7433 | LoadTimingInfo load_timing_info; |
| 7434 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7435 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7436 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7437 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7438 | std::string response_text; |
| 7439 | rv = ReadTransaction(trans.get(), &response_text); |
| 7440 | EXPECT_EQ(OK, rv); |
| 7441 | EXPECT_EQ("Payload", response_text); |
| 7442 | } |
| 7443 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7444 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7445 | HttpRequestInfo request; |
| 7446 | request.method = "GET"; |
| 7447 | request.url = GURL("https://www.google.com/"); |
| 7448 | request.load_flags = 0; |
| 7449 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7450 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7451 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7452 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7453 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7454 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7455 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7456 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7457 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7458 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7459 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7460 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7461 | const unsigned char kSOCKS5OkRequest[] = { |
| 7462 | 0x05, // Version |
| 7463 | 0x01, // Command (CONNECT) |
| 7464 | 0x00, // Reserved. |
| 7465 | 0x03, // Address type (DOMAINNAME). |
| 7466 | 0x0E, // Length of domain (14) |
| 7467 | // Domain string: |
| 7468 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7469 | 0x01, 0xBB, // 16-bit port (443) |
| 7470 | }; |
| 7471 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7472 | const char kSOCKS5OkResponse[] = |
| 7473 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7474 | |
| 7475 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7476 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7477 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7478 | arraysize(kSOCKS5OkRequest)), |
| 7479 | MockWrite("GET / HTTP/1.1\r\n" |
| 7480 | "Host: www.google.com\r\n" |
| 7481 | "Connection: keep-alive\r\n\r\n") |
| 7482 | }; |
| 7483 | |
| 7484 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7485 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7486 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7487 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7488 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7489 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7490 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7491 | }; |
| 7492 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7493 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7494 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7495 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7496 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7497 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7500 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7502 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7503 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7504 | |
| 7505 | rv = callback.WaitForResult(); |
| 7506 | EXPECT_EQ(OK, rv); |
| 7507 | |
| 7508 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7509 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7510 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7511 | LoadTimingInfo load_timing_info; |
| 7512 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7513 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7514 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7515 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7516 | std::string response_text; |
| 7517 | rv = ReadTransaction(trans.get(), &response_text); |
| 7518 | EXPECT_EQ(OK, rv); |
| 7519 | EXPECT_EQ("Payload", response_text); |
| 7520 | } |
| 7521 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7522 | namespace { |
| 7523 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7524 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7525 | |
| 7526 | struct GroupNameTest { |
| 7527 | std::string proxy_server; |
| 7528 | std::string url; |
| 7529 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7530 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7531 | }; |
| 7532 | |
| 7533 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7534 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7535 | SpdySessionDependencies* session_deps_) { |
| 7536 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7537 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7538 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7539 | session->http_server_properties(); |
| 7540 | http_server_properties->SetAlternateProtocol( |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7541 | HostPortPair("host.with.alternate", 80), 443, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 7542 | AlternateProtocolFromNextProto(next_proto), 1); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7543 | |
| 7544 | return session; |
| 7545 | } |
| 7546 | |
| 7547 | int GroupNameTransactionHelper( |
| 7548 | const std::string& url, |
| 7549 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7550 | HttpRequestInfo request; |
| 7551 | request.method = "GET"; |
| 7552 | request.url = GURL(url); |
| 7553 | request.load_flags = 0; |
| 7554 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7555 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7556 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7558 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7559 | |
| 7560 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7561 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7562 | } |
| 7563 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7564 | } // namespace |
| 7565 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7566 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7567 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7568 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7569 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7570 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7571 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7572 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7573 | }, |
| 7574 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7575 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7576 | "http://[2001:1418:13:1::25]/direct", |
| 7577 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7578 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7579 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7580 | |
| 7581 | // SSL Tests |
| 7582 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7583 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7584 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7585 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7586 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7587 | }, |
| 7588 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7589 | "", // unused |
| 7590 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7591 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7592 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7593 | }, |
| 7594 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7595 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7596 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7597 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7598 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7599 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7600 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7601 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7602 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7603 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7604 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7605 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7606 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7607 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7608 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7609 | |
| 7610 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7611 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7612 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7613 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7614 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7615 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7616 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7617 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7618 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7619 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7620 | |
| 7621 | EXPECT_EQ(ERR_IO_PENDING, |
| 7622 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7623 | if (tests[i].ssl) |
| 7624 | EXPECT_EQ(tests[i].expected_group_name, |
| 7625 | ssl_conn_pool->last_group_name_received()); |
| 7626 | else |
| 7627 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7628 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7629 | } |
| 7630 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7631 | } |
| 7632 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7633 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7634 | const GroupNameTest tests[] = { |
| 7635 | { |
| 7636 | "http_proxy", |
| 7637 | "http://www.google.com/http_proxy_normal", |
| 7638 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7639 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7640 | }, |
| 7641 | |
| 7642 | // SSL Tests |
| 7643 | { |
| 7644 | "http_proxy", |
| 7645 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7646 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7647 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7648 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7649 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7650 | { |
| 7651 | "http_proxy", |
| 7652 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7653 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7654 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7655 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7656 | |
| 7657 | { |
| 7658 | "http_proxy", |
| 7659 | "ftp://ftp.google.com/http_proxy_normal", |
| 7660 | "ftp/ftp.google.com:21", |
| 7661 | false, |
| 7662 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7663 | }; |
| 7664 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7665 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7666 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7667 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7668 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7669 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7670 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7671 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7672 | |
| 7673 | HttpNetworkSessionPeer peer(session); |
| 7674 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7675 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7676 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7677 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7678 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7679 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7680 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7681 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7682 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7683 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7684 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7685 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7686 | |
| 7687 | EXPECT_EQ(ERR_IO_PENDING, |
| 7688 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7689 | if (tests[i].ssl) |
| 7690 | EXPECT_EQ(tests[i].expected_group_name, |
| 7691 | ssl_conn_pool->last_group_name_received()); |
| 7692 | else |
| 7693 | EXPECT_EQ(tests[i].expected_group_name, |
| 7694 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7695 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7696 | } |
| 7697 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7698 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7699 | const GroupNameTest tests[] = { |
| 7700 | { |
| 7701 | "socks4://socks_proxy:1080", |
| 7702 | "http://www.google.com/socks4_direct", |
| 7703 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7704 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7705 | }, |
| 7706 | { |
| 7707 | "socks5://socks_proxy:1080", |
| 7708 | "http://www.google.com/socks5_direct", |
| 7709 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7710 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7711 | }, |
| 7712 | |
| 7713 | // SSL Tests |
| 7714 | { |
| 7715 | "socks4://socks_proxy:1080", |
| 7716 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7717 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7718 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7719 | }, |
| 7720 | { |
| 7721 | "socks5://socks_proxy:1080", |
| 7722 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7723 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7724 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7725 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7726 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7727 | { |
| 7728 | "socks4://socks_proxy:1080", |
| 7729 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7730 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7731 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7732 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7733 | }; |
| 7734 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7735 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7736 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7737 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7738 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7739 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7740 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7741 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7742 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7743 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7744 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7745 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7746 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7747 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7748 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7749 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7750 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7751 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7752 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7753 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 7754 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7755 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7756 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7757 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7758 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7759 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7760 | EXPECT_EQ(ERR_IO_PENDING, |
| 7761 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7762 | if (tests[i].ssl) |
| 7763 | EXPECT_EQ(tests[i].expected_group_name, |
| 7764 | ssl_conn_pool->last_group_name_received()); |
| 7765 | else |
| 7766 | EXPECT_EQ(tests[i].expected_group_name, |
| 7767 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7768 | } |
| 7769 | } |
| 7770 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7771 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7772 | HttpRequestInfo request; |
| 7773 | request.method = "GET"; |
| 7774 | request.url = GURL("http://www.google.com/"); |
| 7775 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7776 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 7777 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7778 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 7779 | // This simulates failure resolving all hostnames; that means we will fail |
| 7780 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7781 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7782 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7783 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7784 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7785 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7787 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7788 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7789 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7790 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7791 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7792 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 7793 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7794 | } |
| 7795 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7796 | // Base test to make sure that when the load flags for a request specify to |
| 7797 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7798 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7799 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7800 | // Issue a request, asking to bypass the cache(s). |
| 7801 | HttpRequestInfo request; |
| 7802 | request.method = "GET"; |
| 7803 | request.load_flags = load_flags; |
| 7804 | request.url = GURL("http://www.google.com/"); |
| 7805 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 7806 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7807 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7808 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7809 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7810 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7812 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7813 | // Warm up the host cache so it has an entry for "www.google.com". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7814 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7815 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7816 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7817 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7818 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7819 | &addrlist, |
| 7820 | callback.callback(), |
| 7821 | NULL, |
| 7822 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7824 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7825 | EXPECT_EQ(OK, rv); |
| 7826 | |
| 7827 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 7828 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7829 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7830 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7831 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7832 | &addrlist, |
| 7833 | callback.callback(), |
| 7834 | NULL, |
| 7835 | BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7836 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7837 | |
| 7838 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 7839 | // we can tell if the next lookup hit the cache, or the "network". |
| 7840 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7841 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7842 | |
| 7843 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 7844 | // first read -- this won't be reached as the host resolution will fail first. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7845 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7846 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7848 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7849 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7850 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7851 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7852 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7853 | |
| 7854 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 7855 | // "www.google.com". |
| 7856 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 7857 | } |
| 7858 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7859 | // There are multiple load flags that should trigger the host cache bypass. |
| 7860 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7861 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7862 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 7863 | } |
| 7864 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7865 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7866 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 7867 | } |
| 7868 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7869 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7870 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 7871 | } |
| 7872 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7873 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7874 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7875 | HttpRequestInfo request; |
| 7876 | request.method = "GET"; |
| 7877 | request.url = GURL("http://www.foo.com/"); |
| 7878 | request.load_flags = 0; |
| 7879 | |
| 7880 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7881 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7882 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7883 | StaticSocketDataProvider data(NULL, 0, |
| 7884 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7886 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7888 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7889 | |
| 7890 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7893 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7895 | |
| 7896 | rv = callback.WaitForResult(); |
| 7897 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 7898 | } |
| 7899 | |
| 7900 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7901 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7902 | HttpRequestInfo request; |
| 7903 | request.method = "GET"; |
| 7904 | request.url = GURL("http://www.foo.com/"); |
| 7905 | request.load_flags = 0; |
| 7906 | |
| 7907 | MockRead data_reads[] = { |
| 7908 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7909 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7910 | }; |
| 7911 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7912 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7913 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7914 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7916 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7917 | |
| 7918 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7919 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7921 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7922 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7923 | |
| 7924 | rv = callback.WaitForResult(); |
| 7925 | EXPECT_EQ(OK, rv); |
| 7926 | |
| 7927 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7928 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7929 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7930 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7931 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7932 | |
| 7933 | std::string response_data; |
| 7934 | rv = ReadTransaction(trans.get(), &response_data); |
| 7935 | EXPECT_EQ(OK, rv); |
| 7936 | EXPECT_EQ("", response_data); |
| 7937 | } |
| 7938 | |
| 7939 | // Make sure that a dropped connection while draining the body for auth |
| 7940 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7941 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7942 | HttpRequestInfo request; |
| 7943 | request.method = "GET"; |
| 7944 | request.url = GURL("http://www.google.com/"); |
| 7945 | request.load_flags = 0; |
| 7946 | |
| 7947 | MockWrite data_writes1[] = { |
| 7948 | MockWrite("GET / HTTP/1.1\r\n" |
| 7949 | "Host: www.google.com\r\n" |
| 7950 | "Connection: keep-alive\r\n\r\n"), |
| 7951 | }; |
| 7952 | |
| 7953 | MockRead data_reads1[] = { |
| 7954 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 7955 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7957 | MockRead("Content-Length: 14\r\n\r\n"), |
| 7958 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7959 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7960 | }; |
| 7961 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7962 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7963 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7964 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7965 | |
| 7966 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7967 | // be issuing -- the final header line contains the credentials. |
| 7968 | MockWrite data_writes2[] = { |
| 7969 | MockWrite("GET / HTTP/1.1\r\n" |
| 7970 | "Host: www.google.com\r\n" |
| 7971 | "Connection: keep-alive\r\n" |
| 7972 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 7973 | }; |
| 7974 | |
| 7975 | // Lastly, the server responds with the actual content. |
| 7976 | MockRead data_reads2[] = { |
| 7977 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7978 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7979 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7980 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7981 | }; |
| 7982 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7983 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7984 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7985 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7986 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7988 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7989 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7990 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7991 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7993 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7994 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7995 | |
| 7996 | rv = callback1.WaitForResult(); |
| 7997 | EXPECT_EQ(OK, rv); |
| 7998 | |
| 7999 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8000 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8001 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8003 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8005 | rv = trans->RestartWithAuth( |
| 8006 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8007 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8008 | |
| 8009 | rv = callback2.WaitForResult(); |
| 8010 | EXPECT_EQ(OK, rv); |
| 8011 | |
| 8012 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8013 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8014 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8015 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8016 | } |
| 8017 | |
| 8018 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8019 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8020 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8021 | |
| 8022 | HttpRequestInfo request; |
| 8023 | request.method = "GET"; |
| 8024 | request.url = GURL("https://www.google.com/"); |
| 8025 | request.load_flags = 0; |
| 8026 | |
| 8027 | MockRead proxy_reads[] = { |
| 8028 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8029 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8030 | }; |
| 8031 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8032 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8033 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8034 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8035 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8036 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8038 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8039 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8040 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8041 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8042 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8043 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8044 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8046 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8047 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8048 | |
| 8049 | rv = callback.WaitForResult(); |
| 8050 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8051 | } |
| 8052 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8053 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8054 | HttpRequestInfo request; |
| 8055 | request.method = "GET"; |
| 8056 | request.url = GURL("http://www.google.com/"); |
| 8057 | request.load_flags = 0; |
| 8058 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8059 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8060 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8062 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8063 | MockRead data_reads[] = { |
| 8064 | MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8065 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8066 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8067 | |
| 8068 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8069 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8071 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8073 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8074 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8075 | |
| 8076 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8077 | |
| 8078 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8079 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8080 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8081 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8082 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8083 | |
| 8084 | std::string response_data; |
| 8085 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8086 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8087 | } |
| 8088 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8089 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8090 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8091 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8092 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8093 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8094 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8095 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8096 | ScopedVector<UploadElementReader> element_readers; |
| 8097 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8098 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8099 | temp_file_path, |
| 8100 | 0, |
| 8101 | kuint64max, |
| 8102 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8103 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8104 | |
| 8105 | HttpRequestInfo request; |
| 8106 | request.method = "POST"; |
| 8107 | request.url = GURL("http://www.google.com/upload"); |
| 8108 | request.upload_data_stream = &upload_data_stream; |
| 8109 | request.load_flags = 0; |
| 8110 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8111 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8112 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8114 | |
| 8115 | MockRead data_reads[] = { |
| 8116 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8117 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8118 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8119 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8120 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8123 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8124 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8125 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8126 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8127 | |
| 8128 | rv = callback.WaitForResult(); |
| 8129 | EXPECT_EQ(OK, rv); |
| 8130 | |
| 8131 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8132 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8133 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8134 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8135 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8136 | |
| 8137 | std::string response_data; |
| 8138 | rv = ReadTransaction(trans.get(), &response_data); |
| 8139 | EXPECT_EQ(OK, rv); |
| 8140 | EXPECT_EQ("hello world", response_data); |
| 8141 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8142 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8143 | } |
| 8144 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8145 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8146 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8147 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8148 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8149 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8150 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8151 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8152 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8153 | ScopedVector<UploadElementReader> element_readers; |
| 8154 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8155 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8156 | temp_file, |
| 8157 | 0, |
| 8158 | kuint64max, |
| 8159 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8160 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8161 | |
| 8162 | HttpRequestInfo request; |
| 8163 | request.method = "POST"; |
| 8164 | request.url = GURL("http://www.google.com/upload"); |
| 8165 | request.upload_data_stream = &upload_data_stream; |
| 8166 | request.load_flags = 0; |
| 8167 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8168 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8169 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8170 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8171 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8172 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8173 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8176 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8178 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8180 | |
| 8181 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8182 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8183 | |
| 8184 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8185 | EXPECT_FALSE(response); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8186 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8187 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8188 | } |
| 8189 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8190 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8191 | class FakeUploadElementReader : public UploadElementReader { |
| 8192 | public: |
| 8193 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8194 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8195 | |
| 8196 | const CompletionCallback& callback() const { return callback_; } |
| 8197 | |
| 8198 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8199 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8200 | callback_ = callback; |
| 8201 | return ERR_IO_PENDING; |
| 8202 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8203 | uint64 GetContentLength() const override { return 0; } |
| 8204 | uint64 BytesRemaining() const override { return 0; } |
| 8205 | int Read(IOBuffer* buf, |
| 8206 | int buf_length, |
| 8207 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8208 | return ERR_FAILED; |
| 8209 | } |
| 8210 | |
| 8211 | private: |
| 8212 | CompletionCallback callback_; |
| 8213 | }; |
| 8214 | |
| 8215 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8216 | ScopedVector<UploadElementReader> element_readers; |
| 8217 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8218 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8219 | |
| 8220 | HttpRequestInfo request; |
| 8221 | request.method = "POST"; |
| 8222 | request.url = GURL("http://www.google.com/upload"); |
| 8223 | request.upload_data_stream = &upload_data_stream; |
| 8224 | request.load_flags = 0; |
| 8225 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8226 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8227 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8229 | |
| 8230 | StaticSocketDataProvider data; |
| 8231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8232 | |
| 8233 | TestCompletionCallback callback; |
| 8234 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8236 | base::MessageLoop::current()->RunUntilIdle(); |
| 8237 | |
| 8238 | // Transaction is pending on request body initialization. |
| 8239 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8240 | |
| 8241 | // Return Init()'s result after the transaction gets destroyed. |
| 8242 | trans.reset(); |
| 8243 | fake_reader->callback().Run(OK); // Should not crash. |
| 8244 | } |
| 8245 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8246 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8247 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8248 | |
| 8249 | HttpRequestInfo request; |
| 8250 | request.method = "GET"; |
| 8251 | request.url = GURL("http://www.google.com/"); |
| 8252 | request.load_flags = 0; |
| 8253 | |
| 8254 | // First transaction will request a resource and receive a Basic challenge |
| 8255 | // with realm="first_realm". |
| 8256 | MockWrite data_writes1[] = { |
| 8257 | MockWrite("GET / HTTP/1.1\r\n" |
| 8258 | "Host: www.google.com\r\n" |
| 8259 | "Connection: keep-alive\r\n" |
| 8260 | "\r\n"), |
| 8261 | }; |
| 8262 | MockRead data_reads1[] = { |
| 8263 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8264 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8265 | "\r\n"), |
| 8266 | }; |
| 8267 | |
| 8268 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8269 | // for first_realm. The server will reject and provide a challenge with |
| 8270 | // second_realm. |
| 8271 | MockWrite data_writes2[] = { |
| 8272 | MockWrite("GET / HTTP/1.1\r\n" |
| 8273 | "Host: www.google.com\r\n" |
| 8274 | "Connection: keep-alive\r\n" |
| 8275 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8276 | "\r\n"), |
| 8277 | }; |
| 8278 | MockRead data_reads2[] = { |
| 8279 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8280 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8281 | "\r\n"), |
| 8282 | }; |
| 8283 | |
| 8284 | // This again fails, and goes back to first_realm. Make sure that the |
| 8285 | // entry is removed from cache. |
| 8286 | MockWrite data_writes3[] = { |
| 8287 | MockWrite("GET / HTTP/1.1\r\n" |
| 8288 | "Host: www.google.com\r\n" |
| 8289 | "Connection: keep-alive\r\n" |
| 8290 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8291 | "\r\n"), |
| 8292 | }; |
| 8293 | MockRead data_reads3[] = { |
| 8294 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8295 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8296 | "\r\n"), |
| 8297 | }; |
| 8298 | |
| 8299 | // Try one last time (with the correct password) and get the resource. |
| 8300 | MockWrite data_writes4[] = { |
| 8301 | MockWrite("GET / HTTP/1.1\r\n" |
| 8302 | "Host: www.google.com\r\n" |
| 8303 | "Connection: keep-alive\r\n" |
| 8304 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8305 | "\r\n"), |
| 8306 | }; |
| 8307 | MockRead data_reads4[] = { |
| 8308 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8309 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8310 | "Content-Length: 5\r\n" |
| 8311 | "\r\n" |
| 8312 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8313 | }; |
| 8314 | |
| 8315 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8316 | data_writes1, arraysize(data_writes1)); |
| 8317 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8318 | data_writes2, arraysize(data_writes2)); |
| 8319 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8320 | data_writes3, arraysize(data_writes3)); |
| 8321 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8322 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8323 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8324 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8325 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8326 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8328 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8329 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8330 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8331 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8333 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8334 | // Issue the first request with Authorize headers. There should be a |
| 8335 | // password prompt for first_realm waiting to be filled in after the |
| 8336 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8337 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8338 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8339 | rv = callback1.WaitForResult(); |
| 8340 | EXPECT_EQ(OK, rv); |
| 8341 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8342 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8343 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8344 | ASSERT_FALSE(challenge == NULL); |
| 8345 | EXPECT_FALSE(challenge->is_proxy); |
| 8346 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8347 | EXPECT_EQ("first_realm", challenge->realm); |
| 8348 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8349 | |
| 8350 | // Issue the second request with an incorrect password. There should be a |
| 8351 | // password prompt for second_realm waiting to be filled in after the |
| 8352 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8353 | TestCompletionCallback callback2; |
| 8354 | rv = trans->RestartWithAuth( |
| 8355 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8357 | rv = callback2.WaitForResult(); |
| 8358 | EXPECT_EQ(OK, rv); |
| 8359 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8360 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8361 | challenge = response->auth_challenge.get(); |
| 8362 | ASSERT_FALSE(challenge == NULL); |
| 8363 | EXPECT_FALSE(challenge->is_proxy); |
| 8364 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8365 | EXPECT_EQ("second_realm", challenge->realm); |
| 8366 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8367 | |
| 8368 | // Issue the third request with another incorrect password. There should be |
| 8369 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8370 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8371 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8372 | TestCompletionCallback callback3; |
| 8373 | rv = trans->RestartWithAuth( |
| 8374 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8375 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8376 | rv = callback3.WaitForResult(); |
| 8377 | EXPECT_EQ(OK, rv); |
| 8378 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8379 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8380 | challenge = response->auth_challenge.get(); |
| 8381 | ASSERT_FALSE(challenge == NULL); |
| 8382 | EXPECT_FALSE(challenge->is_proxy); |
| 8383 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8384 | EXPECT_EQ("first_realm", challenge->realm); |
| 8385 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8386 | |
| 8387 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8388 | TestCompletionCallback callback4; |
| 8389 | rv = trans->RestartWithAuth( |
| 8390 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8391 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8392 | rv = callback4.WaitForResult(); |
| 8393 | EXPECT_EQ(OK, rv); |
| 8394 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8395 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8396 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8397 | } |
| 8398 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8399 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8400 | session_deps_.next_protos = SpdyNextProtos(); |
| 8401 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8402 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8403 | std::string alternate_protocol_http_header = |
| 8404 | GetAlternateProtocolHttpHeader(); |
| 8405 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8406 | MockRead data_reads[] = { |
| 8407 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8408 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8409 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8410 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8411 | }; |
| 8412 | |
| 8413 | HttpRequestInfo request; |
| 8414 | request.method = "GET"; |
| 8415 | request.url = GURL("http://www.google.com/"); |
| 8416 | request.load_flags = 0; |
| 8417 | |
| 8418 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8419 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8422 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8423 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8424 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8425 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8426 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8428 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8430 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 8431 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8432 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8433 | *session->http_server_properties(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8434 | EXPECT_FALSE( |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8435 | http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8436 | |
| 8437 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8438 | |
| 8439 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8440 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8441 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8442 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8443 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8444 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8445 | |
| 8446 | std::string response_data; |
| 8447 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8448 | EXPECT_EQ("hello world", response_data); |
| 8449 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8450 | ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8451 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8452 | http_server_properties.GetAlternateProtocol(http_host_port_pair); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8453 | AlternateProtocolInfo expected_alternate( |
| 8454 | 443, AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8455 | EXPECT_TRUE(expected_alternate.Equals(alternate)); |
| 8456 | } |
| 8457 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8458 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8459 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8460 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8461 | |
| 8462 | HttpRequestInfo request; |
| 8463 | request.method = "GET"; |
| 8464 | request.url = GURL("http://www.google.com/"); |
| 8465 | request.load_flags = 0; |
| 8466 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8467 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8468 | StaticSocketDataProvider first_data; |
| 8469 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8470 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8471 | |
| 8472 | MockRead data_reads[] = { |
| 8473 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8474 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8475 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8476 | }; |
| 8477 | StaticSocketDataProvider second_data( |
| 8478 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8479 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8480 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8481 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8482 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8483 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8484 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8485 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8486 | // port 80 (another restricted port). |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8487 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8488 | HostPortPair::FromURL(request.url), |
| 8489 | 666 /* port is ignored by MockConnect anyway */, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8490 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8491 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8492 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8493 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8494 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8496 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8498 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8499 | |
| 8500 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8501 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8502 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8503 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8504 | |
| 8505 | std::string response_data; |
| 8506 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8507 | EXPECT_EQ("hello world", response_data); |
| 8508 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8509 | ASSERT_TRUE(http_server_properties->HasAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8510 | HostPortPair::FromURL(request.url))); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8511 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8512 | http_server_properties->GetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8513 | HostPortPair::FromURL(request.url)); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8514 | EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8515 | } |
| 8516 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8517 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8518 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8519 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8520 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8521 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8522 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8523 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8524 | |
| 8525 | HttpRequestInfo restricted_port_request; |
| 8526 | restricted_port_request.method = "GET"; |
| 8527 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8528 | restricted_port_request.load_flags = 0; |
| 8529 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8530 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8531 | StaticSocketDataProvider first_data; |
| 8532 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8533 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8534 | |
| 8535 | MockRead data_reads[] = { |
| 8536 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8537 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8538 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8539 | }; |
| 8540 | StaticSocketDataProvider second_data( |
| 8541 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8542 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8543 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8544 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8545 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8546 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8547 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8548 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8549 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8550 | HostPortPair::FromURL(restricted_port_request.url), |
| 8551 | kUnrestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8552 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8553 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8554 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8555 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8556 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8558 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8559 | &restricted_port_request, |
| 8560 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8561 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8562 | // Invalid change to unrestricted port should fail. |
| 8563 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8564 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8565 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8566 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8567 | AlternateProtocolPortRestrictedPermitted) { |
| 8568 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8569 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8570 | // on a restricted port (port < 1024) if we set |
| 8571 | // enable_user_alternate_protocol_ports. |
| 8572 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8573 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8574 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8575 | |
| 8576 | HttpRequestInfo restricted_port_request; |
| 8577 | restricted_port_request.method = "GET"; |
| 8578 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8579 | restricted_port_request.load_flags = 0; |
| 8580 | |
| 8581 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8582 | StaticSocketDataProvider first_data; |
| 8583 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8584 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8585 | |
| 8586 | MockRead data_reads[] = { |
| 8587 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8588 | MockRead("hello world"), |
| 8589 | MockRead(ASYNC, OK), |
| 8590 | }; |
| 8591 | StaticSocketDataProvider second_data( |
| 8592 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8593 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8594 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8595 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8596 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8597 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8598 | session->http_server_properties(); |
| 8599 | const int kUnrestrictedAlternatePort = 1024; |
| 8600 | http_server_properties->SetAlternateProtocol( |
| 8601 | HostPortPair::FromURL(restricted_port_request.url), |
| 8602 | kUnrestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8603 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8604 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8605 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8607 | TestCompletionCallback callback; |
| 8608 | |
| 8609 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8610 | &restricted_port_request, |
| 8611 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8612 | // Change to unrestricted port should succeed. |
| 8613 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8614 | } |
| 8615 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8616 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8617 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8618 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8619 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8620 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8621 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8622 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8623 | |
| 8624 | HttpRequestInfo restricted_port_request; |
| 8625 | restricted_port_request.method = "GET"; |
| 8626 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8627 | restricted_port_request.load_flags = 0; |
| 8628 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8629 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8630 | StaticSocketDataProvider first_data; |
| 8631 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8632 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8633 | |
| 8634 | MockRead data_reads[] = { |
| 8635 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8636 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8637 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8638 | }; |
| 8639 | StaticSocketDataProvider second_data( |
| 8640 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8641 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8642 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8643 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8644 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8645 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8646 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8647 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8648 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8649 | HostPortPair::FromURL(restricted_port_request.url), |
| 8650 | kRestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8651 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8652 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8653 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8654 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8655 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8656 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8657 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8658 | &restricted_port_request, |
| 8659 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8660 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8661 | // Valid change to restricted port should pass. |
| 8662 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8663 | } |
| 8664 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8665 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8666 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8667 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8668 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8669 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8670 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8671 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8672 | |
| 8673 | HttpRequestInfo unrestricted_port_request; |
| 8674 | unrestricted_port_request.method = "GET"; |
| 8675 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8676 | unrestricted_port_request.load_flags = 0; |
| 8677 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8678 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8679 | StaticSocketDataProvider first_data; |
| 8680 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8681 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8682 | |
| 8683 | MockRead data_reads[] = { |
| 8684 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8685 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8686 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8687 | }; |
| 8688 | StaticSocketDataProvider second_data( |
| 8689 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8690 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8691 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8692 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8693 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8694 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8695 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8696 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8697 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8698 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8699 | kRestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8700 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8701 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8702 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8703 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8704 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8706 | int rv = trans->Start( |
| 8707 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8708 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8709 | // Valid change to restricted port should pass. |
| 8710 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8711 | } |
| 8712 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8713 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8714 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8715 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8716 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8717 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8718 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8719 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8720 | |
| 8721 | HttpRequestInfo unrestricted_port_request; |
| 8722 | unrestricted_port_request.method = "GET"; |
| 8723 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8724 | unrestricted_port_request.load_flags = 0; |
| 8725 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8726 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8727 | StaticSocketDataProvider first_data; |
| 8728 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8729 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8730 | |
| 8731 | MockRead data_reads[] = { |
| 8732 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8733 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8734 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8735 | }; |
| 8736 | StaticSocketDataProvider second_data( |
| 8737 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8738 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8739 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8740 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8741 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8742 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8743 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8744 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8745 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8746 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8747 | kUnrestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8748 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8749 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8750 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8751 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8752 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8754 | int rv = trans->Start( |
| 8755 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8757 | // Valid change to an unrestricted port should pass. |
| 8758 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8759 | } |
| 8760 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8761 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8762 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8763 | // protocol to an unsafe port, and that we resume the second |
| 8764 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8765 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8766 | |
| 8767 | HttpRequestInfo request; |
| 8768 | request.method = "GET"; |
| 8769 | request.url = GURL("http://www.google.com/"); |
| 8770 | request.load_flags = 0; |
| 8771 | |
| 8772 | // The alternate protocol request will error out before we attempt to connect, |
| 8773 | // so only the standard HTTP request will try to connect. |
| 8774 | MockRead data_reads[] = { |
| 8775 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8776 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8777 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8778 | }; |
| 8779 | StaticSocketDataProvider data( |
| 8780 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8782 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8783 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8784 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8785 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8786 | session->http_server_properties(); |
| 8787 | const int kUnsafePort = 7; |
| 8788 | http_server_properties->SetAlternateProtocol( |
| 8789 | HostPortPair::FromURL(request.url), |
| 8790 | kUnsafePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8791 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8792 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8793 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8795 | TestCompletionCallback callback; |
| 8796 | |
| 8797 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8798 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8799 | // The HTTP request should succeed. |
| 8800 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8801 | |
| 8802 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8803 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8804 | |
| 8805 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8806 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8807 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8808 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8809 | |
| 8810 | std::string response_data; |
| 8811 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8812 | EXPECT_EQ("hello world", response_data); |
| 8813 | } |
| 8814 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8815 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8816 | session_deps_.use_alternate_protocols = true; |
| 8817 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8818 | |
| 8819 | HttpRequestInfo request; |
| 8820 | request.method = "GET"; |
| 8821 | request.url = GURL("http://www.google.com/"); |
| 8822 | request.load_flags = 0; |
| 8823 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8824 | std::string alternate_protocol_http_header = |
| 8825 | GetAlternateProtocolHttpHeader(); |
| 8826 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8827 | MockRead data_reads[] = { |
| 8828 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8829 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8830 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8831 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 8832 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8833 | }; |
| 8834 | |
| 8835 | StaticSocketDataProvider first_transaction( |
| 8836 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8837 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8838 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8839 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8840 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8841 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8842 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8843 | scoped_ptr<SpdyFrame> req( |
| 8844 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8845 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8846 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8847 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8848 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8849 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8850 | CreateMockRead(*resp), |
| 8851 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8852 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8853 | }; |
| 8854 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8855 | DelayedSocketData spdy_data( |
| 8856 | 1, // wait for one write to finish before reading. |
| 8857 | spdy_reads, arraysize(spdy_reads), |
| 8858 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8859 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8860 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8861 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8862 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8863 | NULL, 0, NULL, 0); |
| 8864 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8865 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8866 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8867 | &hanging_non_alternate_protocol_socket); |
| 8868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8869 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8870 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8871 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8872 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8873 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8875 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8876 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8877 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8878 | |
| 8879 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8880 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8881 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8882 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8883 | |
| 8884 | std::string response_data; |
| 8885 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8886 | EXPECT_EQ("hello world", response_data); |
| 8887 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8888 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8890 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8891 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8892 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8893 | |
| 8894 | response = trans->GetResponseInfo(); |
| 8895 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8896 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8897 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8898 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8899 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8900 | |
| 8901 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8902 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8903 | } |
| 8904 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8905 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8906 | session_deps_.use_alternate_protocols = true; |
| 8907 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8908 | |
| 8909 | HttpRequestInfo request; |
| 8910 | request.method = "GET"; |
| 8911 | request.url = GURL("http://www.google.com/"); |
| 8912 | request.load_flags = 0; |
| 8913 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8914 | std::string alternate_protocol_http_header = |
| 8915 | GetAlternateProtocolHttpHeader(); |
| 8916 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8917 | MockRead data_reads[] = { |
| 8918 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8919 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8920 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8921 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8922 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8923 | }; |
| 8924 | |
| 8925 | StaticSocketDataProvider first_transaction( |
| 8926 | data_reads, arraysize(data_reads), NULL, 0); |
| 8927 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8928 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8929 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8930 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8931 | StaticSocketDataProvider hanging_socket( |
| 8932 | NULL, 0, NULL, 0); |
| 8933 | hanging_socket.set_connect_data(never_finishing_connect); |
| 8934 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 8935 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8936 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 8937 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8938 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8939 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8940 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8942 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8943 | scoped_ptr<SpdyFrame> req1( |
| 8944 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 8945 | scoped_ptr<SpdyFrame> req2( |
| 8946 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8947 | MockWrite spdy_writes[] = { |
| 8948 | CreateMockWrite(*req1), |
| 8949 | CreateMockWrite(*req2), |
| 8950 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8951 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8952 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 8953 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 8954 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8955 | MockRead spdy_reads[] = { |
| 8956 | CreateMockRead(*resp1), |
| 8957 | CreateMockRead(*data1), |
| 8958 | CreateMockRead(*resp2), |
| 8959 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8960 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8961 | }; |
| 8962 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8963 | DelayedSocketData spdy_data( |
| 8964 | 2, // wait for writes to finish before reading. |
| 8965 | spdy_reads, arraysize(spdy_reads), |
| 8966 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8967 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8968 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8969 | |
| 8970 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8971 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8972 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8973 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8974 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8975 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8977 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8978 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8979 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 8980 | |
| 8981 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 8982 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8983 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8984 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8985 | |
| 8986 | std::string response_data; |
| 8987 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 8988 | EXPECT_EQ("hello world", response_data); |
| 8989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8990 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8991 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8992 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8995 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8996 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8997 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8998 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8999 | |
| 9000 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9001 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9002 | |
| 9003 | response = trans2.GetResponseInfo(); |
| 9004 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9005 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9006 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9007 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9008 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9009 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9010 | EXPECT_EQ("hello!", response_data); |
| 9011 | |
| 9012 | response = trans3.GetResponseInfo(); |
| 9013 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9014 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9015 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9016 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9017 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9018 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9019 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9020 | } |
| 9021 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9022 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9023 | session_deps_.use_alternate_protocols = true; |
| 9024 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9025 | |
| 9026 | HttpRequestInfo request; |
| 9027 | request.method = "GET"; |
| 9028 | request.url = GURL("http://www.google.com/"); |
| 9029 | request.load_flags = 0; |
| 9030 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9031 | std::string alternate_protocol_http_header = |
| 9032 | GetAlternateProtocolHttpHeader(); |
| 9033 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9034 | MockRead data_reads[] = { |
| 9035 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9036 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9037 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9038 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9039 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9040 | }; |
| 9041 | |
| 9042 | StaticSocketDataProvider first_transaction( |
| 9043 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9044 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9045 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9046 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9047 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9049 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9050 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9051 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9052 | NULL, 0, NULL, 0); |
| 9053 | hanging_alternate_protocol_socket.set_connect_data( |
| 9054 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9055 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9056 | &hanging_alternate_protocol_socket); |
| 9057 | |
| 9058 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9059 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9061 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9062 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9063 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9064 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9065 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9067 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9068 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9069 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9070 | |
| 9071 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9072 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9073 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9074 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9075 | |
| 9076 | std::string response_data; |
| 9077 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9078 | EXPECT_EQ("hello world", response_data); |
| 9079 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9080 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9082 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9084 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9085 | |
| 9086 | response = trans->GetResponseInfo(); |
| 9087 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9088 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9089 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9090 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9091 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9092 | |
| 9093 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9094 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9095 | } |
| 9096 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9097 | class CapturingProxyResolver : public ProxyResolver { |
| 9098 | public: |
| 9099 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9100 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9101 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9102 | int GetProxyForURL(const GURL& url, |
| 9103 | ProxyInfo* results, |
| 9104 | const CompletionCallback& callback, |
| 9105 | RequestHandle* request, |
| 9106 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9107 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9108 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9109 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9110 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9111 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9112 | } |
| 9113 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9114 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9115 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9116 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9117 | NOTREACHED(); |
| 9118 | return LOAD_STATE_IDLE; |
| 9119 | } |
| 9120 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9121 | void CancelSetPacScript() override { NOTREACHED(); } |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 9122 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9123 | int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
| 9124 | const CompletionCallback& /*callback*/) override { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9125 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9126 | } |
| 9127 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9128 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9129 | |
| 9130 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9131 | std::vector<GURL> resolved_; |
| 9132 | |
| 9133 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9134 | }; |
| 9135 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9136 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9137 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9138 | session_deps_.use_alternate_protocols = true; |
| 9139 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9140 | |
| 9141 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9142 | proxy_config.set_auto_detect(true); |
| 9143 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9144 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9145 | CapturingProxyResolver* capturing_proxy_resolver = |
| 9146 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9147 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9148 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 9149 | NULL)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9150 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9151 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9152 | |
| 9153 | HttpRequestInfo request; |
| 9154 | request.method = "GET"; |
| 9155 | request.url = GURL("http://www.google.com/"); |
| 9156 | request.load_flags = 0; |
| 9157 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9158 | std::string alternate_protocol_http_header = |
| 9159 | GetAlternateProtocolHttpHeader(); |
| 9160 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9161 | MockRead data_reads[] = { |
| 9162 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9163 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9164 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9165 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9166 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9167 | }; |
| 9168 | |
| 9169 | StaticSocketDataProvider first_transaction( |
| 9170 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9171 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9172 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9173 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9174 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9176 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9177 | scoped_ptr<SpdyFrame> req( |
| 9178 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9179 | MockWrite spdy_writes[] = { |
| 9180 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9181 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9182 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9183 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9184 | }; |
| 9185 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9186 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9187 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9188 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9189 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9190 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9191 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9192 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 9193 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9194 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9195 | }; |
| 9196 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9197 | OrderedSocketData spdy_data( |
| 9198 | spdy_reads, arraysize(spdy_reads), |
| 9199 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9200 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9201 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9202 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9203 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9204 | NULL, 0, NULL, 0); |
| 9205 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9206 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9207 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9208 | &hanging_non_alternate_protocol_socket); |
| 9209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9210 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9211 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9212 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9213 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9214 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9216 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9217 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9218 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9219 | |
| 9220 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9221 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9222 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9223 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9224 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9225 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9226 | |
| 9227 | std::string response_data; |
| 9228 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9229 | EXPECT_EQ("hello world", response_data); |
| 9230 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9231 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9233 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9234 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9235 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9236 | |
| 9237 | response = trans->GetResponseInfo(); |
| 9238 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9239 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9240 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9241 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9242 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9243 | |
| 9244 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9245 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9246 | ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9247 | EXPECT_EQ("http://www.google.com/", |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9248 | capturing_proxy_resolver->resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9249 | EXPECT_EQ("https://www.google.com/", |
| 9250 | capturing_proxy_resolver->resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9251 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9252 | LoadTimingInfo load_timing_info; |
| 9253 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9254 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9255 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9256 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9257 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9258 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9259 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9260 | session_deps_.use_alternate_protocols = true; |
| 9261 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9262 | |
| 9263 | HttpRequestInfo request; |
| 9264 | request.method = "GET"; |
| 9265 | request.url = GURL("http://www.google.com/"); |
| 9266 | request.load_flags = 0; |
| 9267 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9268 | std::string alternate_protocol_http_header = |
| 9269 | GetAlternateProtocolHttpHeader(); |
| 9270 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9271 | MockRead data_reads[] = { |
| 9272 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9273 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9274 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9275 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9276 | }; |
| 9277 | |
| 9278 | StaticSocketDataProvider first_transaction( |
| 9279 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9280 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9281 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9282 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9283 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9285 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9286 | scoped_ptr<SpdyFrame> req( |
| 9287 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9288 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9289 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9290 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9291 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9292 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9293 | CreateMockRead(*resp), |
| 9294 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9295 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9296 | }; |
| 9297 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9298 | DelayedSocketData spdy_data( |
| 9299 | 1, // wait for one write to finish before reading. |
| 9300 | spdy_reads, arraysize(spdy_reads), |
| 9301 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9302 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9303 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9304 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9305 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9306 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9307 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9308 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9309 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9311 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9312 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9313 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9314 | |
| 9315 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9316 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9317 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9318 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9319 | |
| 9320 | std::string response_data; |
| 9321 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9322 | EXPECT_EQ("hello world", response_data); |
| 9323 | |
| 9324 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9325 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9326 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9327 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9328 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9329 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9330 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9331 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9332 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9333 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9335 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9336 | |
| 9337 | response = trans->GetResponseInfo(); |
| 9338 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9339 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9340 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9341 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9342 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9343 | |
| 9344 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9345 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9346 | } |
| 9347 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9348 | // GenerateAuthToken is a mighty big test. |
| 9349 | // It tests all permutation of GenerateAuthToken behavior: |
| 9350 | // - Synchronous and Asynchronous completion. |
| 9351 | // - OK or error on completion. |
| 9352 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9353 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9354 | // - Non-authenticating and authenticating backend. |
| 9355 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9356 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9357 | // problems generating an auth token for an authenticating proxy, we don't |
| 9358 | // need to test all permutations of the backend server). |
| 9359 | // |
| 9360 | // The test proceeds by going over each of the configuration cases, and |
| 9361 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9362 | // specifies both the configuration for the test as well as the expectations |
| 9363 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9364 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9365 | static const char kServer[] = "http://www.example.com"; |
| 9366 | static const char kSecureServer[] = "https://www.example.com"; |
| 9367 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9368 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9369 | |
| 9370 | enum AuthTiming { |
| 9371 | AUTH_NONE, |
| 9372 | AUTH_SYNC, |
| 9373 | AUTH_ASYNC, |
| 9374 | }; |
| 9375 | |
| 9376 | const MockWrite kGet( |
| 9377 | "GET / HTTP/1.1\r\n" |
| 9378 | "Host: www.example.com\r\n" |
| 9379 | "Connection: keep-alive\r\n\r\n"); |
| 9380 | const MockWrite kGetProxy( |
| 9381 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9382 | "Host: www.example.com\r\n" |
| 9383 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9384 | const MockWrite kGetAuth( |
| 9385 | "GET / HTTP/1.1\r\n" |
| 9386 | "Host: www.example.com\r\n" |
| 9387 | "Connection: keep-alive\r\n" |
| 9388 | "Authorization: auth_token\r\n\r\n"); |
| 9389 | const MockWrite kGetProxyAuth( |
| 9390 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9391 | "Host: www.example.com\r\n" |
| 9392 | "Proxy-Connection: keep-alive\r\n" |
| 9393 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9394 | const MockWrite kGetAuthThroughProxy( |
| 9395 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9396 | "Host: www.example.com\r\n" |
| 9397 | "Proxy-Connection: keep-alive\r\n" |
| 9398 | "Authorization: auth_token\r\n\r\n"); |
| 9399 | const MockWrite kGetAuthWithProxyAuth( |
| 9400 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9401 | "Host: www.example.com\r\n" |
| 9402 | "Proxy-Connection: keep-alive\r\n" |
| 9403 | "Proxy-Authorization: auth_token\r\n" |
| 9404 | "Authorization: auth_token\r\n\r\n"); |
| 9405 | const MockWrite kConnect( |
| 9406 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9407 | "Host: www.example.com\r\n" |
| 9408 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9409 | const MockWrite kConnectProxyAuth( |
| 9410 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9411 | "Host: www.example.com\r\n" |
| 9412 | "Proxy-Connection: keep-alive\r\n" |
| 9413 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9414 | |
| 9415 | const MockRead kSuccess( |
| 9416 | "HTTP/1.1 200 OK\r\n" |
| 9417 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9418 | "Content-Length: 3\r\n\r\n" |
| 9419 | "Yes"); |
| 9420 | const MockRead kFailure( |
| 9421 | "Should not be called."); |
| 9422 | const MockRead kServerChallenge( |
| 9423 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9424 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9425 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9426 | "Content-Length: 14\r\n\r\n" |
| 9427 | "Unauthorized\r\n"); |
| 9428 | const MockRead kProxyChallenge( |
| 9429 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9430 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9431 | "Proxy-Connection: close\r\n" |
| 9432 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9433 | "Content-Length: 14\r\n\r\n" |
| 9434 | "Unauthorized\r\n"); |
| 9435 | const MockRead kProxyConnected( |
| 9436 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9437 | |
| 9438 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9439 | // no constructors, but the C++ compiler on Windows warns about |
| 9440 | // unspecified data in compound literals. So, moved to using constructors, |
| 9441 | // and TestRound's created with the default constructor should not be used. |
| 9442 | struct TestRound { |
| 9443 | TestRound() |
| 9444 | : expected_rv(ERR_UNEXPECTED), |
| 9445 | extra_write(NULL), |
| 9446 | extra_read(NULL) { |
| 9447 | } |
| 9448 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9449 | int expected_rv_arg) |
| 9450 | : write(write_arg), |
| 9451 | read(read_arg), |
| 9452 | expected_rv(expected_rv_arg), |
| 9453 | extra_write(NULL), |
| 9454 | extra_read(NULL) { |
| 9455 | } |
| 9456 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9457 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9458 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9459 | : write(write_arg), |
| 9460 | read(read_arg), |
| 9461 | expected_rv(expected_rv_arg), |
| 9462 | extra_write(extra_write_arg), |
| 9463 | extra_read(extra_read_arg) { |
| 9464 | } |
| 9465 | MockWrite write; |
| 9466 | MockRead read; |
| 9467 | int expected_rv; |
| 9468 | const MockWrite* extra_write; |
| 9469 | const MockRead* extra_read; |
| 9470 | }; |
| 9471 | |
| 9472 | static const int kNoSSL = 500; |
| 9473 | |
| 9474 | struct TestConfig { |
| 9475 | const char* proxy_url; |
| 9476 | AuthTiming proxy_auth_timing; |
| 9477 | int proxy_auth_rv; |
| 9478 | const char* server_url; |
| 9479 | AuthTiming server_auth_timing; |
| 9480 | int server_auth_rv; |
| 9481 | int num_auth_rounds; |
| 9482 | int first_ssl_round; |
| 9483 | TestRound rounds[3]; |
| 9484 | } test_configs[] = { |
| 9485 | // Non-authenticating HTTP server with a direct connection. |
| 9486 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9487 | { TestRound(kGet, kSuccess, OK)}}, |
| 9488 | // Authenticating HTTP server with a direct connection. |
| 9489 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9490 | { TestRound(kGet, kServerChallenge, OK), |
| 9491 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9492 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9493 | { TestRound(kGet, kServerChallenge, OK), |
| 9494 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9495 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9496 | { TestRound(kGet, kServerChallenge, OK), |
| 9497 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9498 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9499 | { TestRound(kGet, kServerChallenge, OK), |
| 9500 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9501 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9502 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9503 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9504 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9505 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9506 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9507 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9508 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9509 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9510 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9511 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9512 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9513 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9514 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9515 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9516 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9517 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9518 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9519 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9520 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9521 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9522 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9523 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9524 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9525 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9526 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9527 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9528 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9529 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9530 | // Authenticating HTTP server through an authenticating proxy. |
| 9531 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9532 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9533 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9534 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9535 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9536 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9537 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9538 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9539 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9540 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9541 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9542 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9543 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9544 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9545 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9546 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9547 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9548 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9549 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9550 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9551 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9552 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9553 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9554 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9555 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9556 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9557 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9558 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9559 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9560 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9561 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9562 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9563 | // Non-authenticating HTTPS server with a direct connection. |
| 9564 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9565 | { TestRound(kGet, kSuccess, OK)}}, |
| 9566 | // Authenticating HTTPS server with a direct connection. |
| 9567 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9568 | { TestRound(kGet, kServerChallenge, OK), |
| 9569 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9570 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9571 | { TestRound(kGet, kServerChallenge, OK), |
| 9572 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9573 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9574 | { TestRound(kGet, kServerChallenge, OK), |
| 9575 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9576 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9577 | { TestRound(kGet, kServerChallenge, OK), |
| 9578 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9579 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9580 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9581 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9582 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9583 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9584 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9585 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9586 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9587 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9588 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9589 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9590 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9591 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9592 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9593 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9594 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9595 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9596 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9597 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9598 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9599 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9600 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9601 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9602 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9603 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9604 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9605 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9606 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9607 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9608 | // Authenticating HTTPS server through an authenticating proxy. |
| 9609 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9610 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9611 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9612 | &kGet, &kServerChallenge), |
| 9613 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9614 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9615 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9616 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9617 | &kGet, &kServerChallenge), |
| 9618 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9619 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9620 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9621 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9622 | &kGet, &kServerChallenge), |
| 9623 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9624 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9625 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9626 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9627 | &kGet, &kServerChallenge), |
| 9628 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9629 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9630 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9631 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9632 | &kGet, &kServerChallenge), |
| 9633 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9634 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9635 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9636 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9637 | &kGet, &kServerChallenge), |
| 9638 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9639 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9640 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9641 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9642 | &kGet, &kServerChallenge), |
| 9643 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9644 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9645 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9646 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9647 | &kGet, &kServerChallenge), |
| 9648 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9649 | }; |
| 9650 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9651 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9652 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9653 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9654 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9655 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9656 | |
| 9657 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9658 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9659 | for (int n = 0; n < 2; n++) { |
| 9660 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9661 | std::string auth_challenge = "Mock realm=proxy"; |
| 9662 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9663 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9664 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9665 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 9666 | origin, BoundNetLog()); |
| 9667 | auth_handler->SetGenerateExpectation( |
| 9668 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 9669 | test_config.proxy_auth_rv); |
| 9670 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9671 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9672 | } |
| 9673 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 9674 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9675 | std::string auth_challenge = "Mock realm=server"; |
| 9676 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9677 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9678 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9679 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9680 | origin, BoundNetLog()); |
| 9681 | auth_handler->SetGenerateExpectation( |
| 9682 | test_config.server_auth_timing == AUTH_ASYNC, |
| 9683 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9684 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9685 | } |
| 9686 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9687 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 9688 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9689 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9690 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9691 | } |
| 9692 | |
| 9693 | HttpRequestInfo request; |
| 9694 | request.method = "GET"; |
| 9695 | request.url = GURL(test_config.server_url); |
| 9696 | request.load_flags = 0; |
| 9697 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9698 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9699 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9700 | |
| 9701 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 9702 | const TestRound& read_write_round = test_config.rounds[round]; |
| 9703 | |
| 9704 | // Set up expected reads and writes. |
| 9705 | MockRead reads[2]; |
| 9706 | reads[0] = read_write_round.read; |
| 9707 | size_t length_reads = 1; |
| 9708 | if (read_write_round.extra_read) { |
| 9709 | reads[1] = *read_write_round.extra_read; |
| 9710 | length_reads = 2; |
| 9711 | } |
| 9712 | |
| 9713 | MockWrite writes[2]; |
| 9714 | writes[0] = read_write_round.write; |
| 9715 | size_t length_writes = 1; |
| 9716 | if (read_write_round.extra_write) { |
| 9717 | writes[1] = *read_write_round.extra_write; |
| 9718 | length_writes = 2; |
| 9719 | } |
| 9720 | StaticSocketDataProvider data_provider( |
| 9721 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9722 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9723 | |
| 9724 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9725 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9726 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9727 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9728 | &ssl_socket_data_provider); |
| 9729 | |
| 9730 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9731 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9732 | int rv; |
| 9733 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9734 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9735 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9736 | rv = trans.RestartWithAuth( |
| 9737 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9738 | } |
| 9739 | if (rv == ERR_IO_PENDING) |
| 9740 | rv = callback.WaitForResult(); |
| 9741 | |
| 9742 | // Compare results with expected data. |
| 9743 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9745 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9746 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9747 | } else { |
| 9748 | EXPECT_TRUE(response == NULL); |
| 9749 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 9750 | continue; |
| 9751 | } |
| 9752 | if (round + 1 < test_config.num_auth_rounds) { |
| 9753 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 9754 | } else { |
| 9755 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9756 | } |
| 9757 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 9758 | } |
| 9759 | } |
| 9760 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9761 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9762 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9763 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9764 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9765 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9766 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 9767 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 9768 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9769 | |
| 9770 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9771 | auth_handler->set_connection_based(true); |
| 9772 | std::string auth_challenge = "Mock realm=server"; |
| 9773 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9774 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9775 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9776 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9777 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9778 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9779 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9780 | int rv = OK; |
| 9781 | const HttpResponseInfo* response = NULL; |
| 9782 | HttpRequestInfo request; |
| 9783 | request.method = "GET"; |
| 9784 | request.url = origin; |
| 9785 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9786 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9787 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9788 | |
| 9789 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 9790 | // to validate that the TCP socket is not released to the pool between |
| 9791 | // each round of multi-round authentication. |
| 9792 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9793 | ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); |
| 9794 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9795 | 50, // Max sockets for pool |
| 9796 | 1, // Max sockets per group |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9797 | &transport_pool_histograms, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9798 | session_deps_.host_resolver.get(), |
| 9799 | session_deps_.socket_factory.get(), |
| 9800 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9801 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 9802 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9803 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 9804 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9805 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9806 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9807 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9808 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9809 | |
| 9810 | const MockWrite kGet( |
| 9811 | "GET / HTTP/1.1\r\n" |
| 9812 | "Host: www.example.com\r\n" |
| 9813 | "Connection: keep-alive\r\n\r\n"); |
| 9814 | const MockWrite kGetAuth( |
| 9815 | "GET / HTTP/1.1\r\n" |
| 9816 | "Host: www.example.com\r\n" |
| 9817 | "Connection: keep-alive\r\n" |
| 9818 | "Authorization: auth_token\r\n\r\n"); |
| 9819 | |
| 9820 | const MockRead kServerChallenge( |
| 9821 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9822 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9823 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9824 | "Content-Length: 14\r\n\r\n" |
| 9825 | "Unauthorized\r\n"); |
| 9826 | const MockRead kSuccess( |
| 9827 | "HTTP/1.1 200 OK\r\n" |
| 9828 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9829 | "Content-Length: 3\r\n\r\n" |
| 9830 | "Yes"); |
| 9831 | |
| 9832 | MockWrite writes[] = { |
| 9833 | // First round |
| 9834 | kGet, |
| 9835 | // Second round |
| 9836 | kGetAuth, |
| 9837 | // Third round |
| 9838 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9839 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9840 | kGetAuth, |
| 9841 | // Competing request |
| 9842 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9843 | }; |
| 9844 | MockRead reads[] = { |
| 9845 | // First round |
| 9846 | kServerChallenge, |
| 9847 | // Second round |
| 9848 | kServerChallenge, |
| 9849 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9850 | kServerChallenge, |
| 9851 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9852 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9853 | // Competing response |
| 9854 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9855 | }; |
| 9856 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 9857 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9858 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9859 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9860 | const char* const kSocketGroup = "www.example.com:80"; |
| 9861 | |
| 9862 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9863 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9864 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9865 | if (rv == ERR_IO_PENDING) |
| 9866 | rv = callback.WaitForResult(); |
| 9867 | EXPECT_EQ(OK, rv); |
| 9868 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9869 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9870 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9871 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9872 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9873 | // In between rounds, another request comes in for the same domain. |
| 9874 | // It should not be able to grab the TCP socket that trans has already |
| 9875 | // claimed. |
| 9876 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9878 | TestCompletionCallback callback_compete; |
| 9879 | rv = trans_compete->Start( |
| 9880 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9881 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9882 | // callback_compete.WaitForResult at this point would stall forever, |
| 9883 | // since the HttpNetworkTransaction does not release the request back to |
| 9884 | // the pool until after authentication completes. |
| 9885 | |
| 9886 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9887 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9888 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9889 | if (rv == ERR_IO_PENDING) |
| 9890 | rv = callback.WaitForResult(); |
| 9891 | EXPECT_EQ(OK, rv); |
| 9892 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9893 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9894 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9895 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9896 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9897 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9898 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9899 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9900 | if (rv == ERR_IO_PENDING) |
| 9901 | rv = callback.WaitForResult(); |
| 9902 | EXPECT_EQ(OK, rv); |
| 9903 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9904 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9905 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9906 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9907 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9908 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9909 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9910 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9911 | if (rv == ERR_IO_PENDING) |
| 9912 | rv = callback.WaitForResult(); |
| 9913 | EXPECT_EQ(OK, rv); |
| 9914 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9915 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9916 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9917 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9918 | |
| 9919 | // Read the body since the fourth round was successful. This will also |
| 9920 | // release the socket back to the pool. |
| 9921 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9922 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9923 | if (rv == ERR_IO_PENDING) |
| 9924 | rv = callback.WaitForResult(); |
| 9925 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9926 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9927 | EXPECT_EQ(0, rv); |
| 9928 | // There are still 0 idle sockets, since the trans_compete transaction |
| 9929 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9930 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9931 | |
| 9932 | // The competing request can now finish. Wait for the headers and then |
| 9933 | // read the body. |
| 9934 | rv = callback_compete.WaitForResult(); |
| 9935 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9936 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9937 | if (rv == ERR_IO_PENDING) |
| 9938 | rv = callback.WaitForResult(); |
| 9939 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9940 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9941 | EXPECT_EQ(0, rv); |
| 9942 | |
| 9943 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9944 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9945 | } |
| 9946 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9947 | // This tests the case that a request is issued via http instead of spdy after |
| 9948 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9949 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9950 | session_deps_.use_alternate_protocols = true; |
| 9951 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 9952 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9953 | session_deps_.next_protos = next_protos; |
| 9954 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9955 | HttpRequestInfo request; |
| 9956 | request.method = "GET"; |
| 9957 | request.url = GURL("https://www.google.com/"); |
| 9958 | request.load_flags = 0; |
| 9959 | |
| 9960 | MockWrite data_writes[] = { |
| 9961 | MockWrite("GET / HTTP/1.1\r\n" |
| 9962 | "Host: www.google.com\r\n" |
| 9963 | "Connection: keep-alive\r\n\r\n"), |
| 9964 | }; |
| 9965 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9966 | std::string alternate_protocol_http_header = |
| 9967 | GetAlternateProtocolHttpHeader(); |
| 9968 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9969 | MockRead data_reads[] = { |
| 9970 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9971 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9972 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9973 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9974 | }; |
| 9975 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9976 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9977 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 9978 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 9979 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9980 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9982 | |
| 9983 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9984 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9987 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9988 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9989 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9990 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9991 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9993 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9994 | |
| 9995 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9996 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9997 | |
| 9998 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9999 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10000 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10001 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10002 | |
| 10003 | std::string response_data; |
| 10004 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10005 | EXPECT_EQ("hello world", response_data); |
| 10006 | |
| 10007 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10008 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10009 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10010 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10011 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10012 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10013 | // followed by an immediate server closing of the socket. |
| 10014 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10015 | session_deps_.use_alternate_protocols = true; |
| 10016 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10017 | |
| 10018 | HttpRequestInfo request; |
| 10019 | request.method = "GET"; |
| 10020 | request.url = GURL("https://www.google.com/"); |
| 10021 | request.load_flags = 0; |
| 10022 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10023 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10024 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10025 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10026 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10027 | scoped_ptr<SpdyFrame> req( |
| 10028 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 10029 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10030 | |
| 10031 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10032 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10033 | }; |
| 10034 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10035 | DelayedSocketData spdy_data( |
| 10036 | 0, // don't wait in this case, immediate hangup. |
| 10037 | spdy_reads, arraysize(spdy_reads), |
| 10038 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10039 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10041 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10042 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10043 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10044 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10045 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10047 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10048 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10049 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10050 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10051 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10052 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10053 | // it gets it. This is needed since the auth handler may get destroyed |
| 10054 | // before we get a chance to query it. |
| 10055 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10056 | public: |
| 10057 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10058 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10059 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10060 | |
| 10061 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10062 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10063 | const HttpRequestInfo* request, |
| 10064 | const CompletionCallback& callback, |
| 10065 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10066 | *url_ = request->url; |
| 10067 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10068 | credentials, request, callback, auth_token); |
| 10069 | } |
| 10070 | |
| 10071 | private: |
| 10072 | GURL* url_; |
| 10073 | }; |
| 10074 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10075 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10076 | // This test ensures that the URL passed into the proxy is upgraded |
| 10077 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10078 | session_deps_.use_alternate_protocols = true; |
| 10079 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10080 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10081 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10082 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 10083 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10084 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10085 | GURL request_url; |
| 10086 | { |
| 10087 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10088 | new HttpAuthHandlerMock::Factory(); |
| 10089 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10090 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10091 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10092 | auth_factory->set_do_init_from_challenge(true); |
| 10093 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10094 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10095 | |
| 10096 | HttpRequestInfo request; |
| 10097 | request.method = "GET"; |
| 10098 | request.url = GURL("http://www.google.com"); |
| 10099 | request.load_flags = 0; |
| 10100 | |
| 10101 | // First round goes unauthenticated through the proxy. |
| 10102 | MockWrite data_writes_1[] = { |
| 10103 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10104 | "Host: www.google.com\r\n" |
| 10105 | "Proxy-Connection: keep-alive\r\n" |
| 10106 | "\r\n"), |
| 10107 | }; |
| 10108 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10109 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10110 | MockRead("HTTP/1.1 200 OK\r\n" |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10111 | "Alternate-Protocol: 443:npn-spdy/2\r\n" |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10112 | "Proxy-Connection: close\r\n" |
| 10113 | "\r\n"), |
| 10114 | }; |
| 10115 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10116 | data_writes_1, arraysize(data_writes_1)); |
| 10117 | |
| 10118 | // Second round tries to tunnel to www.google.com due to the |
| 10119 | // Alternate-Protocol announcement in the first round. It fails due |
| 10120 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10121 | // After the failure, a tunnel is established to www.google.com using |
| 10122 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10123 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10124 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10125 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10126 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10127 | // to obtain a new one. |
| 10128 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10129 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10130 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10131 | // establishment and SPDY framing issues. Alas, the |
| 10132 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10133 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10134 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10135 | scoped_ptr<SpdyFrame> req( |
| 10136 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10137 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10138 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10139 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10140 | MockWrite data_writes_2[] = { |
| 10141 | // First connection attempt without Proxy-Authorization. |
| 10142 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10143 | "Host: www.google.com\r\n" |
| 10144 | "Proxy-Connection: keep-alive\r\n" |
| 10145 | "\r\n"), |
| 10146 | |
| 10147 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10148 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10149 | "Host: www.google.com\r\n" |
| 10150 | "Proxy-Connection: keep-alive\r\n" |
| 10151 | "Proxy-Authorization: auth_token\r\n" |
| 10152 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10153 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10154 | // SPDY request |
| 10155 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10156 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10157 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10158 | "Proxy-Authenticate: Mock\r\n" |
| 10159 | "Proxy-Connection: close\r\n" |
| 10160 | "\r\n"); |
| 10161 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10162 | MockRead data_reads_2[] = { |
| 10163 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10164 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 10165 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10166 | arraysize(kRejectConnectResponse) - 1, 1), |
| 10167 | |
| 10168 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10169 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10170 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10171 | |
| 10172 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10173 | CreateMockRead(*resp.get(), 6), |
| 10174 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10175 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10176 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10177 | OrderedSocketData data_2( |
| 10178 | data_reads_2, arraysize(data_reads_2), |
| 10179 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10180 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10181 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10182 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10183 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10184 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10185 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10186 | NULL, 0, NULL, 0); |
| 10187 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10188 | never_finishing_connect); |
| 10189 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10190 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10191 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10192 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10193 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10194 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10195 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10196 | |
| 10197 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10198 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10199 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10200 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10201 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10203 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10204 | |
| 10205 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10206 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10207 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10209 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10210 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10211 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10212 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10213 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10214 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10215 | |
| 10216 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10217 | TestCompletionCallback callback_3; |
| 10218 | rv = trans_2->RestartWithAuth( |
| 10219 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10220 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10221 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10222 | |
| 10223 | // After all that work, these two lines (or actually, just the scheme) are |
| 10224 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10225 | EXPECT_EQ("https", request_url.scheme()); |
| 10226 | EXPECT_EQ("www.google.com", request_url.host()); |
| 10227 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10228 | LoadTimingInfo load_timing_info; |
| 10229 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10230 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10231 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10232 | } |
| 10233 | |
| 10234 | // Test that if we cancel the transaction as the connection is completing, that |
| 10235 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10236 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10237 | // Setup everything about the connection to complete synchronously, so that |
| 10238 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10239 | // for is the callback from the HttpStreamRequest. |
| 10240 | // Then cancel the transaction. |
| 10241 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10242 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10243 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10244 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10245 | MockRead(SYNCHRONOUS, "hello world"), |
| 10246 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10247 | }; |
| 10248 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10249 | HttpRequestInfo request; |
| 10250 | request.method = "GET"; |
| 10251 | request.url = GURL("http://www.google.com/"); |
| 10252 | request.load_flags = 0; |
| 10253 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10254 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10255 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10256 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10257 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10258 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10259 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10260 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10261 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10263 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10264 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10265 | CapturingBoundNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10266 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10267 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10268 | trans.reset(); // Cancel the transaction here. |
| 10269 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10270 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10271 | } |
| 10272 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10273 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10274 | // stream is drained properly and added back to the socket pool. The main |
| 10275 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10276 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10277 | // deleted. |
| 10278 | // See http://crbug.com/368418 |
| 10279 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10280 | MockRead data_reads[] = { |
| 10281 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10282 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10283 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10284 | MockRead(ASYNC, "1"), |
| 10285 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10286 | // HttpNetworkTransaction has been deleted. |
| 10287 | MockRead(ASYNC, "2"), |
| 10288 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10289 | }; |
| 10290 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10292 | |
| 10293 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10294 | |
| 10295 | { |
| 10296 | HttpRequestInfo request; |
| 10297 | request.method = "GET"; |
| 10298 | request.url = GURL("http://www.google.com/"); |
| 10299 | request.load_flags = 0; |
| 10300 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10301 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10302 | TestCompletionCallback callback; |
| 10303 | |
| 10304 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10306 | callback.WaitForResult(); |
| 10307 | |
| 10308 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10309 | ASSERT_TRUE(response != NULL); |
| 10310 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10311 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10312 | |
| 10313 | // The transaction and HttpRequestInfo are deleted. |
| 10314 | } |
| 10315 | |
| 10316 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10317 | base::MessageLoop::current()->RunUntilIdle(); |
| 10318 | |
| 10319 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10320 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10321 | } |
| 10322 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10323 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10324 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10325 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10326 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10327 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10328 | session_deps_.net_log = log.bound().net_log(); |
| 10329 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10330 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10331 | HttpRequestInfo request; |
| 10332 | request.method = "GET"; |
| 10333 | request.url = GURL("http://www.google.com/"); |
| 10334 | |
| 10335 | MockWrite data_writes1[] = { |
| 10336 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10337 | "Host: www.google.com\r\n" |
| 10338 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10339 | }; |
| 10340 | |
| 10341 | MockRead data_reads1[] = { |
| 10342 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10343 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10344 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10345 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10346 | }; |
| 10347 | |
| 10348 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10349 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10350 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10352 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10353 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10354 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10355 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10356 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10357 | trans->SetBeforeProxyHeadersSentCallback( |
| 10358 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10359 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10361 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10362 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10363 | |
| 10364 | rv = callback1.WaitForResult(); |
| 10365 | EXPECT_EQ(OK, rv); |
| 10366 | |
| 10367 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10368 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10369 | |
| 10370 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10371 | EXPECT_EQ(200, response->headers->response_code()); |
| 10372 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10373 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10374 | EXPECT_TRUE( |
| 10375 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10376 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10377 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10378 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10379 | |
| 10380 | LoadTimingInfo load_timing_info; |
| 10381 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10382 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10383 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10384 | } |
| 10385 | |
| 10386 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10387 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10388 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10389 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10390 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10391 | session_deps_.net_log = log.bound().net_log(); |
| 10392 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10393 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10394 | HttpRequestInfo request; |
| 10395 | request.method = "GET"; |
| 10396 | request.url = GURL("https://www.google.com/"); |
| 10397 | |
| 10398 | // Since we have proxy, should try to establish tunnel. |
| 10399 | MockWrite data_writes1[] = { |
| 10400 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10401 | "Host: www.google.com\r\n" |
| 10402 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10403 | |
| 10404 | MockWrite("GET / HTTP/1.1\r\n" |
| 10405 | "Host: www.google.com\r\n" |
| 10406 | "Connection: keep-alive\r\n\r\n"), |
| 10407 | }; |
| 10408 | |
| 10409 | MockRead data_reads1[] = { |
| 10410 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 10411 | |
| 10412 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10413 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10414 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10415 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10416 | }; |
| 10417 | |
| 10418 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10419 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10420 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10421 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10424 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10425 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10426 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10427 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10429 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10431 | |
| 10432 | rv = callback1.WaitForResult(); |
| 10433 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10434 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10435 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10436 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10437 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10438 | NetLog::PHASE_NONE); |
| 10439 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10440 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10441 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10442 | NetLog::PHASE_NONE); |
| 10443 | |
| 10444 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10445 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10446 | |
| 10447 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10448 | EXPECT_EQ(200, response->headers->response_code()); |
| 10449 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10450 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10451 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10452 | EXPECT_TRUE( |
| 10453 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10454 | |
| 10455 | LoadTimingInfo load_timing_info; |
| 10456 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10457 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10458 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10459 | } |
| 10460 | |
| 10461 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 10462 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10463 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10464 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10465 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10466 | session_deps_.net_log = log.bound().net_log(); |
| 10467 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10468 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10469 | HttpRequestInfo request; |
| 10470 | request.method = "GET"; |
| 10471 | request.url = GURL("https://www.google.com/"); |
| 10472 | |
| 10473 | // Since we have proxy, should try to establish tunnel. |
| 10474 | MockWrite data_writes1[] = { |
| 10475 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10476 | "Host: www.google.com\r\n" |
| 10477 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10478 | |
| 10479 | MockWrite("GET / HTTP/1.1\r\n" |
| 10480 | "Host: www.google.com\r\n" |
| 10481 | "Connection: keep-alive\r\n\r\n"), |
| 10482 | }; |
| 10483 | |
| 10484 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10485 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10486 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10487 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10488 | }; |
| 10489 | |
| 10490 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10491 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10492 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10493 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10496 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10497 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10498 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10499 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10501 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10502 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10503 | |
| 10504 | rv = callback1.WaitForResult(); |
| 10505 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10506 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10507 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10508 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10509 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10510 | NetLog::PHASE_NONE); |
| 10511 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10512 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10513 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10514 | NetLog::PHASE_NONE); |
| 10515 | } |
| 10516 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10517 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10518 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10519 | scoped_ptr<SpdyFrame> req( |
| 10520 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10521 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 10522 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10523 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10524 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10525 | MockRead spdy_reads[] = { |
| 10526 | CreateMockRead(*resp), |
| 10527 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10528 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10529 | }; |
| 10530 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10531 | DelayedSocketData spdy_data( |
| 10532 | 1, // wait for one write to finish before reading. |
| 10533 | spdy_reads, arraysize(spdy_reads), |
| 10534 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10535 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10536 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10537 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10538 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10539 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10540 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10541 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10542 | |
| 10543 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10544 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10545 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10546 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10547 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10548 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10549 | |
| 10550 | HttpRequestInfo request; |
| 10551 | request.method = "GET"; |
| 10552 | request.url = GURL("https://www.google.com/"); |
| 10553 | request.load_flags = 0; |
| 10554 | |
| 10555 | // This is the important line that marks this as a preconnect. |
| 10556 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10557 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10558 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10559 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10560 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10561 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10562 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10563 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10564 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10565 | } |
| 10566 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10567 | // Given a net error, cause that error to be returned from the first Write() |
| 10568 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10569 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10570 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10571 | net::HttpRequestInfo request_info; |
| 10572 | request_info.url = GURL("https://www.example.com/"); |
| 10573 | request_info.method = "GET"; |
| 10574 | request_info.load_flags = net::LOAD_NORMAL; |
| 10575 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10576 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10577 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10578 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10579 | }; |
| 10580 | net::StaticSocketDataProvider data(NULL, 0, |
| 10581 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10582 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10584 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10585 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10586 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10587 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10589 | TestCompletionCallback callback; |
| 10590 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10591 | if (rv == net::ERR_IO_PENDING) |
| 10592 | rv = callback.WaitForResult(); |
| 10593 | ASSERT_EQ(error, rv); |
| 10594 | } |
| 10595 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10596 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10597 | // Just check a grab bag of cert errors. |
| 10598 | static const int kErrors[] = { |
| 10599 | ERR_CERT_COMMON_NAME_INVALID, |
| 10600 | ERR_CERT_AUTHORITY_INVALID, |
| 10601 | ERR_CERT_DATE_INVALID, |
| 10602 | }; |
| 10603 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10604 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10605 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10606 | } |
| 10607 | } |
| 10608 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10609 | // Ensure that a client certificate is removed from the SSL client auth |
| 10610 | // cache when: |
| 10611 | // 1) No proxy is involved. |
| 10612 | // 2) TLS False Start is disabled. |
| 10613 | // 3) The initial TLS handshake requests a client certificate. |
| 10614 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10615 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10616 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10617 | net::HttpRequestInfo request_info; |
| 10618 | request_info.url = GURL("https://www.example.com/"); |
| 10619 | request_info.method = "GET"; |
| 10620 | request_info.load_flags = net::LOAD_NORMAL; |
| 10621 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10622 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10623 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10624 | |
| 10625 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 10626 | // CertificateRequest is received for the first time, the handshake will |
| 10627 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10628 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10629 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10631 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10632 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10633 | |
| 10634 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 10635 | // False Start is not being used, the result of the SSL handshake will be |
| 10636 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 10637 | // matches the result of a server sending a handshake_failure alert, |
| 10638 | // rather than a Finished message, because it requires a client |
| 10639 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10640 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10641 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10642 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10643 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10644 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10645 | |
| 10646 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 10647 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10648 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 10649 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10650 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10651 | // requiring a client certificate, this fallback handshake should also |
| 10652 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10653 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10654 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10656 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10657 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10658 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10659 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 10660 | // connection to a server fails during an SSL handshake, |
| 10661 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 10662 | // connection was attempted with TLSv1. This is transparent to the caller |
| 10663 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10664 | // requiring a client certificate, this fallback handshake should also |
| 10665 | // fail. |
| 10666 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10667 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10668 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10669 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10670 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10671 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10672 | // Need one more if TLSv1.2 is enabled. |
| 10673 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10674 | ssl_data5.cert_request_info = cert_request.get(); |
| 10675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10676 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 10677 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10678 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10679 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10680 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10681 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10682 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10683 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10684 | TestCompletionCallback callback; |
| 10685 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10686 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10687 | |
| 10688 | // Complete the SSL handshake, which should abort due to requiring a |
| 10689 | // client certificate. |
| 10690 | rv = callback.WaitForResult(); |
| 10691 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10692 | |
| 10693 | // Indicate that no certificate should be supplied. From the perspective |
| 10694 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10695 | // certificate, so this is the same as supply a |
| 10696 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10697 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10698 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10699 | |
| 10700 | // Ensure the certificate was added to the client auth cache before |
| 10701 | // allowing the connection to continue restarting. |
| 10702 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10703 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10704 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10705 | ASSERT_EQ(NULL, client_cert.get()); |
| 10706 | |
| 10707 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10708 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10709 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10710 | rv = callback.WaitForResult(); |
| 10711 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10712 | |
| 10713 | // Ensure that the client certificate is removed from the cache on a |
| 10714 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10715 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10716 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10717 | } |
| 10718 | |
| 10719 | // Ensure that a client certificate is removed from the SSL client auth |
| 10720 | // cache when: |
| 10721 | // 1) No proxy is involved. |
| 10722 | // 2) TLS False Start is enabled. |
| 10723 | // 3) The initial TLS handshake requests a client certificate. |
| 10724 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10725 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10726 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10727 | net::HttpRequestInfo request_info; |
| 10728 | request_info.url = GURL("https://www.example.com/"); |
| 10729 | request_info.method = "GET"; |
| 10730 | request_info.load_flags = net::LOAD_NORMAL; |
| 10731 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10732 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10733 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10734 | |
| 10735 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 10736 | // return successfully after reading up to the peer's Certificate message. |
| 10737 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 10738 | // enqueue application data to be sent in the same packet as the |
| 10739 | // ChangeCipherSpec and Finished messages. |
| 10740 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 10741 | // called, which expects to process the peer's ChangeCipherSpec and |
| 10742 | // Finished messages. If there was an error negotiating with the peer, |
| 10743 | // such as due to the peer requiring a client certificate when none was |
| 10744 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 10745 | // called. |
| 10746 | |
| 10747 | // Like the non-False Start case, when a client certificate is requested by |
| 10748 | // the peer, the handshake is aborted during the Connect() call. |
| 10749 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10750 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10751 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10753 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10755 | |
| 10756 | // When a client certificate is supplied, Connect() will not be aborted |
| 10757 | // when the peer requests the certificate. Instead, the handshake will |
| 10758 | // artificially succeed, allowing the caller to write the HTTP request to |
| 10759 | // the socket. The handshake messages are not processed until Read() is |
| 10760 | // called, which then detects that the handshake was aborted, due to the |
| 10761 | // peer sending a handshake_failure because it requires a client |
| 10762 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10763 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10764 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10766 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10767 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10768 | }; |
| 10769 | net::StaticSocketDataProvider data2( |
| 10770 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10771 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10772 | |
| 10773 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10774 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 10775 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10776 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10777 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10779 | net::StaticSocketDataProvider data3( |
| 10780 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10781 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10782 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10783 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 10784 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 10785 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 10786 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10788 | net::StaticSocketDataProvider data4( |
| 10789 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10790 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10791 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10792 | // Need one more if TLSv1.2 is enabled. |
| 10793 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 10794 | ssl_data5.cert_request_info = cert_request.get(); |
| 10795 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10796 | net::StaticSocketDataProvider data5( |
| 10797 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 10798 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10799 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10800 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10801 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10802 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10803 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10804 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10805 | TestCompletionCallback callback; |
| 10806 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10807 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10808 | |
| 10809 | // Complete the SSL handshake, which should abort due to requiring a |
| 10810 | // client certificate. |
| 10811 | rv = callback.WaitForResult(); |
| 10812 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10813 | |
| 10814 | // Indicate that no certificate should be supplied. From the perspective |
| 10815 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10816 | // certificate, so this is the same as supply a |
| 10817 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10818 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10819 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10820 | |
| 10821 | // Ensure the certificate was added to the client auth cache before |
| 10822 | // allowing the connection to continue restarting. |
| 10823 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10824 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10825 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10826 | ASSERT_EQ(NULL, client_cert.get()); |
| 10827 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10828 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10829 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10830 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10831 | rv = callback.WaitForResult(); |
| 10832 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10833 | |
| 10834 | // Ensure that the client certificate is removed from the cache on a |
| 10835 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10836 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10837 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10838 | } |
| 10839 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10840 | // Ensure that a client certificate is removed from the SSL client auth |
| 10841 | // cache when: |
| 10842 | // 1) An HTTPS proxy is involved. |
| 10843 | // 3) The HTTPS proxy requests a client certificate. |
| 10844 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 10845 | // proxy. |
| 10846 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 10847 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10848 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10849 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10850 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10851 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10852 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10853 | |
| 10854 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10855 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10856 | |
| 10857 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 10858 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 10859 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 10860 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10861 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10862 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10864 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10865 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10866 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10867 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10868 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10869 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10870 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10871 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10872 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10873 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 10874 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10875 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10876 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10878 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10879 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10880 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10881 | |
| 10882 | net::HttpRequestInfo requests[2]; |
| 10883 | requests[0].url = GURL("https://www.example.com/"); |
| 10884 | requests[0].method = "GET"; |
| 10885 | requests[0].load_flags = net::LOAD_NORMAL; |
| 10886 | |
| 10887 | requests[1].url = GURL("http://www.example.com/"); |
| 10888 | requests[1].method = "GET"; |
| 10889 | requests[1].load_flags = net::LOAD_NORMAL; |
| 10890 | |
| 10891 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10892 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 10893 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10894 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10896 | |
| 10897 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10898 | TestCompletionCallback callback; |
| 10899 | int rv = trans->Start( |
| 10900 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10901 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10902 | |
| 10903 | // Complete the SSL handshake, which should abort due to requiring a |
| 10904 | // client certificate. |
| 10905 | rv = callback.WaitForResult(); |
| 10906 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10907 | |
| 10908 | // Indicate that no certificate should be supplied. From the perspective |
| 10909 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10910 | // certificate, so this is the same as supply a |
| 10911 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10912 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10913 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10914 | |
| 10915 | // Ensure the certificate was added to the client auth cache before |
| 10916 | // allowing the connection to continue restarting. |
| 10917 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10918 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10919 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10920 | ASSERT_EQ(NULL, client_cert.get()); |
| 10921 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 10922 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10923 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10924 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10925 | |
| 10926 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 10927 | // then consume ssl_data3, which should also fail. The result code is |
| 10928 | // checked against what ssl_data3 should return. |
| 10929 | rv = callback.WaitForResult(); |
| 10930 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 10931 | |
| 10932 | // Now that the new handshake has failed, ensure that the client |
| 10933 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10934 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10935 | HostPortPair("proxy", 70), &client_cert)); |
| 10936 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10937 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10938 | } |
| 10939 | } |
| 10940 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10941 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 10942 | // TEST_P is a macro that expands directly to code that stringizes the |
| 10943 | // arguments. As a result, macros passed as parameters (such as prefix |
| 10944 | // or test_case_name) will not be expanded by the preprocessor. To |
| 10945 | // work around this, indirect the macro for TEST_P, so that the |
| 10946 | // pre-processor will expand macros such as MAYBE_test_name before |
| 10947 | // instantiating the test. |
| 10948 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 10949 | TEST_P(test_case_name, test_name) |
| 10950 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10951 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 10952 | #if defined(OS_WIN) |
| 10953 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 10954 | #else |
| 10955 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 10956 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10957 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10958 | session_deps_.use_alternate_protocols = true; |
| 10959 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10960 | |
| 10961 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10962 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 10963 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 10964 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10965 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10966 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10967 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10968 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10970 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10971 | scoped_ptr<SpdyFrame> host1_req( |
| 10972 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10973 | scoped_ptr<SpdyFrame> host2_req( |
| 10974 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10975 | MockWrite spdy_writes[] = { |
| 10976 | CreateMockWrite(*host1_req, 1), |
| 10977 | CreateMockWrite(*host2_req, 4), |
| 10978 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10979 | scoped_ptr<SpdyFrame> host1_resp( |
| 10980 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10981 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10982 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10983 | scoped_ptr<SpdyFrame> host2_resp( |
| 10984 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10985 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10986 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10987 | MockRead spdy_reads[] = { |
| 10988 | CreateMockRead(*host1_resp, 2), |
| 10989 | CreateMockRead(*host1_resp_body, 3), |
| 10990 | CreateMockRead(*host2_resp, 5), |
| 10991 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10992 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10993 | }; |
| 10994 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10995 | IPAddressNumber ip; |
| 10996 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 10997 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10998 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10999 | OrderedSocketData spdy_data( |
| 11000 | connect, |
| 11001 | spdy_reads, arraysize(spdy_reads), |
| 11002 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11003 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11004 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11005 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11006 | HttpRequestInfo request1; |
| 11007 | request1.method = "GET"; |
| 11008 | request1.url = GURL("https://www.google.com/"); |
| 11009 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11010 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11012 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11013 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11014 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11015 | |
| 11016 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11017 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11018 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11019 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11020 | |
| 11021 | std::string response_data; |
| 11022 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11023 | EXPECT_EQ("hello!", response_data); |
| 11024 | |
| 11025 | // Preload www.gmail.com into HostCache. |
| 11026 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11027 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11028 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11029 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11030 | DEFAULT_PRIORITY, |
| 11031 | &ignored, |
| 11032 | callback.callback(), |
| 11033 | NULL, |
| 11034 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11036 | rv = callback.WaitForResult(); |
| 11037 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11038 | |
| 11039 | HttpRequestInfo request2; |
| 11040 | request2.method = "GET"; |
| 11041 | request2.url = GURL("https://www.gmail.com/"); |
| 11042 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11043 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11045 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11046 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11047 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11048 | |
| 11049 | response = trans2.GetResponseInfo(); |
| 11050 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11051 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11052 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11053 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11054 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11055 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11056 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11057 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11058 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11059 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11060 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11061 | session_deps_.use_alternate_protocols = true; |
| 11062 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11063 | |
| 11064 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11065 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11066 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11067 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11068 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11069 | |
| 11070 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11071 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11073 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11074 | scoped_ptr<SpdyFrame> host1_req( |
| 11075 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11076 | scoped_ptr<SpdyFrame> host2_req( |
| 11077 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11078 | MockWrite spdy_writes[] = { |
| 11079 | CreateMockWrite(*host1_req, 1), |
| 11080 | CreateMockWrite(*host2_req, 4), |
| 11081 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11082 | scoped_ptr<SpdyFrame> host1_resp( |
| 11083 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11084 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11085 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11086 | scoped_ptr<SpdyFrame> host2_resp( |
| 11087 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11088 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11089 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11090 | MockRead spdy_reads[] = { |
| 11091 | CreateMockRead(*host1_resp, 2), |
| 11092 | CreateMockRead(*host1_resp_body, 3), |
| 11093 | CreateMockRead(*host2_resp, 5), |
| 11094 | CreateMockRead(*host2_resp_body, 6), |
| 11095 | MockRead(ASYNC, 0, 7), |
| 11096 | }; |
| 11097 | |
| 11098 | IPAddressNumber ip; |
| 11099 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11100 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11101 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11102 | OrderedSocketData spdy_data( |
| 11103 | connect, |
| 11104 | spdy_reads, arraysize(spdy_reads), |
| 11105 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11106 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11107 | |
| 11108 | TestCompletionCallback callback; |
| 11109 | HttpRequestInfo request1; |
| 11110 | request1.method = "GET"; |
| 11111 | request1.url = GURL("https://www.google.com/"); |
| 11112 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11113 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11114 | |
| 11115 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11116 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11117 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11118 | |
| 11119 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11120 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11121 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11122 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11123 | |
| 11124 | std::string response_data; |
| 11125 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11126 | EXPECT_EQ("hello!", response_data); |
| 11127 | |
| 11128 | HttpRequestInfo request2; |
| 11129 | request2.method = "GET"; |
| 11130 | request2.url = GURL("https://www.gmail.com/"); |
| 11131 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11132 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11133 | |
| 11134 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11135 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11136 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11137 | |
| 11138 | response = trans2.GetResponseInfo(); |
| 11139 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11140 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11141 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11142 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11143 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11144 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11145 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11146 | } |
| 11147 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11148 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 11149 | public: |
| 11150 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11151 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11152 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11153 | |
| 11154 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11155 | |
| 11156 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11157 | int Resolve(const RequestInfo& info, |
| 11158 | RequestPriority priority, |
| 11159 | AddressList* addresses, |
| 11160 | const CompletionCallback& callback, |
| 11161 | RequestHandle* out_req, |
| 11162 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11163 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11164 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11165 | } |
| 11166 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11167 | int ResolveFromCache(const RequestInfo& info, |
| 11168 | AddressList* addresses, |
| 11169 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11170 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11171 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11172 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11173 | return rv; |
| 11174 | } |
| 11175 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11176 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11177 | host_resolver_.CancelRequest(req); |
| 11178 | } |
| 11179 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11180 | MockCachingHostResolver* GetMockHostResolver() { |
| 11181 | return &host_resolver_; |
| 11182 | } |
| 11183 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11184 | private: |
| 11185 | MockCachingHostResolver host_resolver_; |
| 11186 | const HostPortPair host_port_; |
| 11187 | }; |
| 11188 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11189 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11190 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11191 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11192 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11193 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11194 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11195 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11196 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11197 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 11198 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11199 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 11200 | // prefix doesn't work with parametrized tests). |
| 11201 | #if defined(OS_WIN) |
| 11202 | return; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11203 | #else |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11204 | session_deps_.use_alternate_protocols = true; |
| 11205 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11206 | |
| 11207 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11208 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11209 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11210 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11211 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11212 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11213 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11214 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11215 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11216 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11217 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11219 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11220 | scoped_ptr<SpdyFrame> host1_req( |
| 11221 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11222 | scoped_ptr<SpdyFrame> host2_req( |
| 11223 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11224 | MockWrite spdy_writes[] = { |
| 11225 | CreateMockWrite(*host1_req, 1), |
| 11226 | CreateMockWrite(*host2_req, 4), |
| 11227 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11228 | scoped_ptr<SpdyFrame> host1_resp( |
| 11229 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11230 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11231 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11232 | scoped_ptr<SpdyFrame> host2_resp( |
| 11233 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11234 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11235 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11236 | MockRead spdy_reads[] = { |
| 11237 | CreateMockRead(*host1_resp, 2), |
| 11238 | CreateMockRead(*host1_resp_body, 3), |
| 11239 | CreateMockRead(*host2_resp, 5), |
| 11240 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11241 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11242 | }; |
| 11243 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11244 | IPAddressNumber ip; |
| 11245 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11246 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11247 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11248 | OrderedSocketData spdy_data( |
| 11249 | connect, |
| 11250 | spdy_reads, arraysize(spdy_reads), |
| 11251 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11252 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11253 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11254 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11255 | HttpRequestInfo request1; |
| 11256 | request1.method = "GET"; |
| 11257 | request1.url = GURL("https://www.google.com/"); |
| 11258 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11259 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11261 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11262 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11263 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11264 | |
| 11265 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11266 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11267 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11268 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11269 | |
| 11270 | std::string response_data; |
| 11271 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11272 | EXPECT_EQ("hello!", response_data); |
| 11273 | |
| 11274 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11275 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11276 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11277 | rv = host_resolver.Resolve(resolve_info, |
| 11278 | DEFAULT_PRIORITY, |
| 11279 | &ignored, |
| 11280 | callback.callback(), |
| 11281 | NULL, |
| 11282 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11283 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11284 | rv = callback.WaitForResult(); |
| 11285 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11286 | |
| 11287 | HttpRequestInfo request2; |
| 11288 | request2.method = "GET"; |
| 11289 | request2.url = GURL("https://www.gmail.com/"); |
| 11290 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11291 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11293 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11294 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11295 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11296 | |
| 11297 | response = trans2.GetResponseInfo(); |
| 11298 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11299 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11300 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11301 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11302 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11303 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11304 | EXPECT_EQ("hello!", response_data); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11305 | #endif |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11306 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11307 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11308 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11309 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11310 | const std::string https_url = "https://www.google.com/"; |
| 11311 | const std::string http_url = "http://www.google.com:443/"; |
| 11312 | |
| 11313 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11314 | scoped_ptr<SpdyFrame> req1( |
| 11315 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11316 | |
| 11317 | MockWrite writes1[] = { |
| 11318 | CreateMockWrite(*req1, 0), |
| 11319 | }; |
| 11320 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11321 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11322 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11323 | MockRead reads1[] = { |
| 11324 | CreateMockRead(*resp1, 1), |
| 11325 | CreateMockRead(*body1, 2), |
| 11326 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11327 | }; |
| 11328 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11329 | DelayedSocketData data1( |
| 11330 | 1, reads1, arraysize(reads1), |
| 11331 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11332 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11333 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11334 | |
| 11335 | // HTTP GET for the HTTP URL |
| 11336 | MockWrite writes2[] = { |
| 11337 | MockWrite(ASYNC, 4, |
| 11338 | "GET / HTTP/1.1\r\n" |
| 11339 | "Host: www.google.com:443\r\n" |
| 11340 | "Connection: keep-alive\r\n\r\n"), |
| 11341 | }; |
| 11342 | |
| 11343 | MockRead reads2[] = { |
| 11344 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11345 | MockRead(ASYNC, 6, "hello"), |
| 11346 | MockRead(ASYNC, 7, OK), |
| 11347 | }; |
| 11348 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11349 | DelayedSocketData data2( |
| 11350 | 1, reads2, arraysize(reads2), |
| 11351 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11352 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11353 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11354 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11355 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11356 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11357 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11358 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11359 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11360 | |
| 11361 | // Start the first transaction to set up the SpdySession |
| 11362 | HttpRequestInfo request1; |
| 11363 | request1.method = "GET"; |
| 11364 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11365 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11366 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11367 | TestCompletionCallback callback1; |
| 11368 | EXPECT_EQ(ERR_IO_PENDING, |
| 11369 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11370 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11371 | |
| 11372 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11373 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11374 | |
| 11375 | // Now, start the HTTP request |
| 11376 | HttpRequestInfo request2; |
| 11377 | request2.method = "GET"; |
| 11378 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11379 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11380 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11381 | TestCompletionCallback callback2; |
| 11382 | EXPECT_EQ(ERR_IO_PENDING, |
| 11383 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11384 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11385 | |
| 11386 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11387 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11388 | } |
| 11389 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11390 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11391 | const std::string https_url = "https://www.google.com/"; |
| 11392 | const std::string http_url = "http://www.google.com:443/"; |
| 11393 | |
| 11394 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
[email protected] | 9075f51c | 2013-08-15 17:53:54 | [diff] [blame] | 11395 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 11396 | LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11397 | scoped_ptr<SpdyFrame> req1( |
| 11398 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11399 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 11400 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11401 | |
| 11402 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11403 | SpdyHeaderBlock req2_block; |
| 11404 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
| 11405 | req2_block[spdy_util_.GetPathKey()] = |
| 11406 | spdy_util_.is_spdy2() ? http_url.c_str() : "/"; |
| 11407 | req2_block[spdy_util_.GetHostKey()] = "www.google.com:443"; |
| 11408 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 11409 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11410 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11411 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11412 | |
| 11413 | MockWrite writes1[] = { |
| 11414 | CreateMockWrite(*connect, 0), |
| 11415 | CreateMockWrite(*wrapped_req1, 2), |
| 11416 | CreateMockWrite(*req2, 5), |
| 11417 | }; |
| 11418 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11419 | scoped_ptr<SpdyFrame> conn_resp( |
| 11420 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11421 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11422 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11423 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 11424 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 11425 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 11426 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 11427 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11428 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11429 | MockRead reads1[] = { |
| 11430 | CreateMockRead(*conn_resp, 1), |
| 11431 | CreateMockRead(*wrapped_resp1, 3), |
| 11432 | CreateMockRead(*wrapped_body1, 4), |
| 11433 | CreateMockRead(*resp2, 6), |
| 11434 | CreateMockRead(*body2, 7), |
| 11435 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 11436 | }; |
| 11437 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11438 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 11439 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11440 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11441 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11442 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11443 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11444 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 11445 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11446 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11447 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11448 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11449 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11450 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11451 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11452 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11453 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11454 | |
| 11455 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11456 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11457 | |
| 11458 | // Start the first transaction to set up the SpdySession |
| 11459 | HttpRequestInfo request1; |
| 11460 | request1.method = "GET"; |
| 11461 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11462 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11463 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11464 | TestCompletionCallback callback1; |
| 11465 | EXPECT_EQ(ERR_IO_PENDING, |
| 11466 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11467 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11468 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11469 | |
| 11470 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11471 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11472 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11473 | LoadTimingInfo load_timing_info1; |
| 11474 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 11475 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 11476 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11477 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11478 | // Now, start the HTTP request |
| 11479 | HttpRequestInfo request2; |
| 11480 | request2.method = "GET"; |
| 11481 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11482 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11483 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11484 | TestCompletionCallback callback2; |
| 11485 | EXPECT_EQ(ERR_IO_PENDING, |
| 11486 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11487 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11488 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11489 | |
| 11490 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11491 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11492 | |
| 11493 | LoadTimingInfo load_timing_info2; |
| 11494 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 11495 | // The established SPDY sessions is considered reused by the HTTP request. |
| 11496 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 11497 | // HTTP requests over a SPDY session should have a different connection |
| 11498 | // socket_log_id than requests over a tunnel. |
| 11499 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11500 | } |
| 11501 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11502 | TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11503 | session_deps_.force_spdy_always = true; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11504 | const std::string https_url = "https://www.google.com/"; |
| 11505 | const std::string http_url = "http://www.google.com:443/"; |
| 11506 | |
| 11507 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11508 | scoped_ptr<SpdyFrame> req1( |
| 11509 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11510 | // SPDY GET for the HTTP URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11511 | scoped_ptr<SpdyFrame> req2( |
| 11512 | spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11513 | |
| 11514 | MockWrite writes[] = { |
| 11515 | CreateMockWrite(*req1, 1), |
| 11516 | CreateMockWrite(*req2, 4), |
| 11517 | }; |
| 11518 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11519 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11520 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11521 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11522 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11523 | MockRead reads[] = { |
| 11524 | CreateMockRead(*resp1, 2), |
| 11525 | CreateMockRead(*body1, 3), |
| 11526 | CreateMockRead(*resp2, 5), |
| 11527 | CreateMockRead(*body2, 6), |
| 11528 | MockRead(ASYNC, ERR_IO_PENDING, 7) |
| 11529 | }; |
| 11530 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11531 | OrderedSocketData data(reads, arraysize(reads), |
| 11532 | writes, arraysize(writes)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11533 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11534 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11535 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11538 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11539 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11540 | |
| 11541 | // Start the first transaction to set up the SpdySession |
| 11542 | HttpRequestInfo request1; |
| 11543 | request1.method = "GET"; |
| 11544 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11545 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11546 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11547 | TestCompletionCallback callback1; |
| 11548 | EXPECT_EQ(ERR_IO_PENDING, |
| 11549 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11550 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11551 | |
| 11552 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11553 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11554 | |
| 11555 | // Now, start the HTTP request |
| 11556 | HttpRequestInfo request2; |
| 11557 | request2.method = "GET"; |
| 11558 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11559 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11560 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11561 | TestCompletionCallback callback2; |
| 11562 | EXPECT_EQ(ERR_IO_PENDING, |
| 11563 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11564 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11565 | |
| 11566 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11567 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11568 | } |
| 11569 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11570 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11571 | // that we do not pool other origins that resolve to the same IP when |
| 11572 | // the certificate does not match the new origin. |
| 11573 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11574 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11575 | const std::string url1 = "http://www.google.com/"; |
| 11576 | const std::string url2 = "https://mail.google.com/"; |
| 11577 | const std::string ip_addr = "1.2.3.4"; |
| 11578 | |
| 11579 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11580 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11581 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11582 | scoped_ptr<SpdyFrame> req1( |
| 11583 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11584 | |
| 11585 | MockWrite writes1[] = { |
| 11586 | CreateMockWrite(*req1, 0), |
| 11587 | }; |
| 11588 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11589 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11590 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11591 | MockRead reads1[] = { |
| 11592 | CreateMockRead(*resp1, 1), |
| 11593 | CreateMockRead(*body1, 2), |
| 11594 | MockRead(ASYNC, OK, 3) // EOF |
| 11595 | }; |
| 11596 | |
| 11597 | scoped_ptr<DeterministicSocketData> data1( |
| 11598 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11599 | writes1, arraysize(writes1))); |
| 11600 | IPAddressNumber ip; |
| 11601 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11602 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11603 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11604 | data1->set_connect_data(connect_data1); |
| 11605 | |
| 11606 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11607 | scoped_ptr<SpdyFrame> req2( |
| 11608 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11609 | |
| 11610 | MockWrite writes2[] = { |
| 11611 | CreateMockWrite(*req2, 0), |
| 11612 | }; |
| 11613 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11614 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11615 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11616 | MockRead reads2[] = { |
| 11617 | CreateMockRead(*resp2, 1), |
| 11618 | CreateMockRead(*body2, 2), |
| 11619 | MockRead(ASYNC, OK, 3) // EOF |
| 11620 | }; |
| 11621 | |
| 11622 | scoped_ptr<DeterministicSocketData> data2( |
| 11623 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11624 | writes2, arraysize(writes2))); |
| 11625 | MockConnect connect_data2(ASYNC, OK); |
| 11626 | data2->set_connect_data(connect_data2); |
| 11627 | |
| 11628 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11629 | // all others direct. |
| 11630 | ProxyConfig proxy_config; |
| 11631 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 11632 | CapturingProxyResolver* capturing_proxy_resolver = |
| 11633 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11634 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11635 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 11636 | NULL)); |
| 11637 | |
| 11638 | // Load a valid cert. Note, that this does not need to |
| 11639 | // be valid for proxy because the MockSSLClientSocket does |
| 11640 | // not actually verify it. But SpdySession will use this |
| 11641 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11642 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11643 | scoped_refptr<X509Certificate> server_cert( |
| 11644 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11645 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11646 | |
| 11647 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11648 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11649 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11650 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11651 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11652 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11653 | |
| 11654 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11655 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11656 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11657 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11658 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11659 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11660 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11661 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11662 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11663 | |
| 11664 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11665 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11666 | |
| 11667 | // Start the first transaction to set up the SpdySession |
| 11668 | HttpRequestInfo request1; |
| 11669 | request1.method = "GET"; |
| 11670 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11671 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11672 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11673 | TestCompletionCallback callback1; |
| 11674 | ASSERT_EQ(ERR_IO_PENDING, |
| 11675 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11676 | data1->RunFor(3); |
| 11677 | |
| 11678 | ASSERT_TRUE(callback1.have_result()); |
| 11679 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11680 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11681 | |
| 11682 | // Now, start the HTTP request |
| 11683 | HttpRequestInfo request2; |
| 11684 | request2.method = "GET"; |
| 11685 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11686 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11687 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11688 | TestCompletionCallback callback2; |
| 11689 | EXPECT_EQ(ERR_IO_PENDING, |
| 11690 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11691 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11692 | data2->RunFor(3); |
| 11693 | |
| 11694 | ASSERT_TRUE(callback2.have_result()); |
| 11695 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11696 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11697 | } |
| 11698 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11699 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11700 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11701 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 11702 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11703 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11704 | const std::string https_url = "https://www.google.com/"; |
| 11705 | |
| 11706 | MockRead reads1[] = { |
| 11707 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11708 | }; |
| 11709 | |
| 11710 | scoped_ptr<DeterministicSocketData> data1( |
| 11711 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11712 | data1->SetStop(1); |
| 11713 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11714 | scoped_ptr<SpdyFrame> req2( |
| 11715 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11716 | MockWrite writes2[] = { |
| 11717 | CreateMockWrite(*req2, 0), |
| 11718 | }; |
| 11719 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11720 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11721 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11722 | MockRead reads2[] = { |
| 11723 | CreateMockRead(*resp2, 1), |
| 11724 | CreateMockRead(*body2, 2), |
| 11725 | MockRead(ASYNC, OK, 3) // EOF |
| 11726 | }; |
| 11727 | |
| 11728 | scoped_ptr<DeterministicSocketData> data2( |
| 11729 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11730 | writes2, arraysize(writes2))); |
| 11731 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11732 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11733 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11734 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11735 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11736 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11737 | |
| 11738 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11739 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11740 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11741 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11742 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11743 | |
| 11744 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11745 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11746 | |
| 11747 | // Start the first transaction to set up the SpdySession and verify that |
| 11748 | // connection was closed. |
| 11749 | HttpRequestInfo request1; |
| 11750 | request1.method = "GET"; |
| 11751 | request1.url = GURL(https_url); |
| 11752 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11753 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11754 | TestCompletionCallback callback1; |
| 11755 | EXPECT_EQ(ERR_IO_PENDING, |
| 11756 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11757 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11758 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11759 | |
| 11760 | // Now, start the second request and make sure it succeeds. |
| 11761 | HttpRequestInfo request2; |
| 11762 | request2.method = "GET"; |
| 11763 | request2.url = GURL(https_url); |
| 11764 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11765 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11766 | TestCompletionCallback callback2; |
| 11767 | EXPECT_EQ(ERR_IO_PENDING, |
| 11768 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11769 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11770 | 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] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11777 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11778 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11779 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 11780 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11781 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 11782 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11783 | |
| 11784 | // Use two different hosts with different IPs so they don't get pooled. |
| 11785 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 11786 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 11787 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11788 | |
| 11789 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11790 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11791 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11792 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11794 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11795 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11796 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11797 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 11798 | MockWrite spdy1_writes[] = { |
| 11799 | CreateMockWrite(*host1_req, 1), |
| 11800 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11801 | scoped_ptr<SpdyFrame> host1_resp( |
| 11802 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11803 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11804 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11805 | MockRead spdy1_reads[] = { |
| 11806 | CreateMockRead(*host1_resp, 2), |
| 11807 | CreateMockRead(*host1_resp_body, 3), |
| 11808 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11809 | }; |
| 11810 | |
| 11811 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 11812 | new OrderedSocketData( |
| 11813 | spdy1_reads, arraysize(spdy1_reads), |
| 11814 | spdy1_writes, arraysize(spdy1_writes))); |
| 11815 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 11816 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11817 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11818 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 11819 | MockWrite spdy2_writes[] = { |
| 11820 | CreateMockWrite(*host2_req, 1), |
| 11821 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11822 | scoped_ptr<SpdyFrame> host2_resp( |
| 11823 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11824 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11825 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11826 | MockRead spdy2_reads[] = { |
| 11827 | CreateMockRead(*host2_resp, 2), |
| 11828 | CreateMockRead(*host2_resp_body, 3), |
| 11829 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11830 | }; |
| 11831 | |
| 11832 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 11833 | new OrderedSocketData( |
| 11834 | spdy2_reads, arraysize(spdy2_reads), |
| 11835 | spdy2_writes, arraysize(spdy2_writes))); |
| 11836 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 11837 | |
| 11838 | MockWrite http_write[] = { |
| 11839 | MockWrite("GET / HTTP/1.1\r\n" |
| 11840 | "Host: www.a.com\r\n" |
| 11841 | "Connection: keep-alive\r\n\r\n"), |
| 11842 | }; |
| 11843 | |
| 11844 | MockRead http_read[] = { |
| 11845 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11846 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11847 | MockRead("Content-Length: 6\r\n\r\n"), |
| 11848 | MockRead("hello!"), |
| 11849 | }; |
| 11850 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 11851 | http_write, arraysize(http_write)); |
| 11852 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11853 | |
| 11854 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11855 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11856 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11857 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11858 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11859 | |
| 11860 | TestCompletionCallback callback; |
| 11861 | HttpRequestInfo request1; |
| 11862 | request1.method = "GET"; |
| 11863 | request1.url = GURL("https://www.a.com/"); |
| 11864 | request1.load_flags = 0; |
| 11865 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11866 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11867 | |
| 11868 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 11869 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11870 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11871 | |
| 11872 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11873 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11874 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11875 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11876 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11877 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11878 | |
| 11879 | std::string response_data; |
| 11880 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11881 | EXPECT_EQ("hello!", response_data); |
| 11882 | trans.reset(); |
| 11883 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11884 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11885 | |
| 11886 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11887 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11888 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11889 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11890 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11891 | HttpRequestInfo request2; |
| 11892 | request2.method = "GET"; |
| 11893 | request2.url = GURL("https://www.b.com/"); |
| 11894 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11895 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11896 | |
| 11897 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 11898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11899 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11900 | |
| 11901 | response = trans->GetResponseInfo(); |
| 11902 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11903 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11904 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11905 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11906 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11907 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11908 | EXPECT_EQ("hello!", response_data); |
| 11909 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11910 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11911 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11912 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11913 | |
| 11914 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11915 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11916 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11917 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11918 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11919 | HttpRequestInfo request3; |
| 11920 | request3.method = "GET"; |
| 11921 | request3.url = GURL("http://www.a.com/"); |
| 11922 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11923 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11924 | |
| 11925 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 11926 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11927 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11928 | |
| 11929 | response = trans->GetResponseInfo(); |
| 11930 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11931 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11932 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11933 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11934 | EXPECT_FALSE(response->was_npn_negotiated); |
| 11935 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11936 | EXPECT_EQ("hello!", response_data); |
| 11937 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11938 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11939 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11940 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11941 | } |
| 11942 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11943 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 11944 | HttpRequestInfo request; |
| 11945 | request.method = "GET"; |
| 11946 | request.url = GURL("http://www.google.com/"); |
| 11947 | request.load_flags = 0; |
| 11948 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 11949 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11950 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11951 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11952 | |
| 11953 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 11954 | StaticSocketDataProvider data; |
| 11955 | data.set_connect_data(mock_connect); |
| 11956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11957 | |
| 11958 | TestCompletionCallback callback; |
| 11959 | |
| 11960 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11961 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11962 | |
| 11963 | rv = callback.WaitForResult(); |
| 11964 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11965 | |
| 11966 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11967 | |
| 11968 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11969 | HttpRequestHeaders request_headers; |
| 11970 | trans->GetFullRequestHeaders(&request_headers); |
| 11971 | } |
| 11972 | |
| 11973 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 11974 | HttpRequestInfo request; |
| 11975 | request.method = "GET"; |
| 11976 | request.url = GURL("http://www.google.com/"); |
| 11977 | request.load_flags = 0; |
| 11978 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 11979 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11980 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11981 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11982 | |
| 11983 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11984 | StaticSocketDataProvider data; |
| 11985 | data.set_connect_data(mock_connect); |
| 11986 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11987 | |
| 11988 | TestCompletionCallback callback; |
| 11989 | |
| 11990 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11991 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11992 | |
| 11993 | rv = callback.WaitForResult(); |
| 11994 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11995 | |
| 11996 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11997 | |
| 11998 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11999 | HttpRequestHeaders request_headers; |
| 12000 | trans->GetFullRequestHeaders(&request_headers); |
| 12001 | } |
| 12002 | |
| 12003 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12004 | HttpRequestInfo request; |
| 12005 | request.method = "GET"; |
| 12006 | request.url = GURL("http://www.google.com/"); |
| 12007 | request.load_flags = 0; |
| 12008 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12009 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12010 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12011 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12012 | |
| 12013 | MockWrite data_writes[] = { |
| 12014 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12015 | }; |
| 12016 | MockRead data_reads[] = { |
| 12017 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12018 | }; |
| 12019 | |
| 12020 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12021 | data_writes, arraysize(data_writes)); |
| 12022 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12023 | |
| 12024 | TestCompletionCallback callback; |
| 12025 | |
| 12026 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12027 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12028 | |
| 12029 | rv = callback.WaitForResult(); |
| 12030 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12031 | |
| 12032 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12033 | |
| 12034 | HttpRequestHeaders request_headers; |
| 12035 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12036 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12037 | } |
| 12038 | |
| 12039 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12040 | HttpRequestInfo request; |
| 12041 | request.method = "GET"; |
| 12042 | request.url = GURL("http://www.google.com/"); |
| 12043 | request.load_flags = 0; |
| 12044 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12045 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12046 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12047 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12048 | |
| 12049 | MockWrite data_writes[] = { |
| 12050 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12051 | }; |
| 12052 | MockRead data_reads[] = { |
| 12053 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12054 | }; |
| 12055 | |
| 12056 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12057 | data_writes, arraysize(data_writes)); |
| 12058 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12059 | |
| 12060 | TestCompletionCallback callback; |
| 12061 | |
| 12062 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12063 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12064 | |
| 12065 | rv = callback.WaitForResult(); |
| 12066 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12067 | |
| 12068 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12069 | |
| 12070 | HttpRequestHeaders request_headers; |
| 12071 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12072 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12073 | } |
| 12074 | |
| 12075 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12076 | HttpRequestInfo request; |
| 12077 | request.method = "GET"; |
| 12078 | request.url = GURL("http://www.google.com/"); |
| 12079 | request.load_flags = 0; |
| 12080 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12081 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12082 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12084 | |
| 12085 | MockWrite data_writes[] = { |
| 12086 | MockWrite("GET / HTTP/1.1\r\n" |
| 12087 | "Host: www.google.com\r\n" |
| 12088 | "Connection: keep-alive\r\n\r\n"), |
| 12089 | }; |
| 12090 | MockRead data_reads[] = { |
| 12091 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12092 | }; |
| 12093 | |
| 12094 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12095 | data_writes, arraysize(data_writes)); |
| 12096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12097 | |
| 12098 | TestCompletionCallback callback; |
| 12099 | |
| 12100 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12101 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12102 | |
| 12103 | rv = callback.WaitForResult(); |
| 12104 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12105 | |
| 12106 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12107 | |
| 12108 | HttpRequestHeaders request_headers; |
| 12109 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12110 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12111 | } |
| 12112 | |
| 12113 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 12114 | HttpRequestInfo request; |
| 12115 | request.method = "GET"; |
| 12116 | request.url = GURL("http://www.google.com/"); |
| 12117 | request.load_flags = 0; |
| 12118 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12119 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12120 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12122 | |
| 12123 | MockWrite data_writes[] = { |
| 12124 | MockWrite("GET / HTTP/1.1\r\n" |
| 12125 | "Host: www.google.com\r\n" |
| 12126 | "Connection: keep-alive\r\n\r\n"), |
| 12127 | }; |
| 12128 | MockRead data_reads[] = { |
| 12129 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 12130 | }; |
| 12131 | |
| 12132 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12133 | data_writes, arraysize(data_writes)); |
| 12134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12135 | |
| 12136 | TestCompletionCallback callback; |
| 12137 | |
| 12138 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12139 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12140 | |
| 12141 | rv = callback.WaitForResult(); |
| 12142 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12143 | |
| 12144 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12145 | |
| 12146 | HttpRequestHeaders request_headers; |
| 12147 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12148 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12149 | } |
| 12150 | |
| 12151 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 12152 | HttpRequestInfo request; |
| 12153 | request.method = "GET"; |
| 12154 | request.url = GURL("http://www.google.com/"); |
| 12155 | request.load_flags = 0; |
| 12156 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 12157 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12158 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12159 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12160 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12161 | |
| 12162 | MockWrite data_writes[] = { |
| 12163 | MockWrite("GET / HTTP/1.1\r\n" |
| 12164 | "Host: www.google.com\r\n" |
| 12165 | "Connection: keep-alive\r\n" |
| 12166 | "X-Foo: bar\r\n\r\n"), |
| 12167 | }; |
| 12168 | MockRead data_reads[] = { |
| 12169 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12170 | "Content-Length: 5\r\n\r\n" |
| 12171 | "hello"), |
| 12172 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 12173 | }; |
| 12174 | |
| 12175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12176 | data_writes, arraysize(data_writes)); |
| 12177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12178 | |
| 12179 | TestCompletionCallback callback; |
| 12180 | |
| 12181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12183 | |
| 12184 | rv = callback.WaitForResult(); |
| 12185 | EXPECT_EQ(OK, rv); |
| 12186 | |
| 12187 | HttpRequestHeaders request_headers; |
| 12188 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12189 | std::string foo; |
| 12190 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 12191 | EXPECT_EQ("bar", foo); |
| 12192 | } |
| 12193 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12194 | namespace { |
| 12195 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12196 | // Fake HttpStreamBase that simply records calls to SetPriority(). |
| 12197 | class FakeStream : public HttpStreamBase, |
| 12198 | public base::SupportsWeakPtr<FakeStream> { |
| 12199 | public: |
| 12200 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12201 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12202 | |
| 12203 | RequestPriority priority() const { return priority_; } |
| 12204 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12205 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12206 | RequestPriority priority, |
| 12207 | const BoundNetLog& net_log, |
| 12208 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12209 | return ERR_IO_PENDING; |
| 12210 | } |
| 12211 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12212 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12213 | HttpResponseInfo* response, |
| 12214 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12215 | ADD_FAILURE(); |
| 12216 | return ERR_UNEXPECTED; |
| 12217 | } |
| 12218 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12219 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12220 | ADD_FAILURE(); |
| 12221 | return ERR_UNEXPECTED; |
| 12222 | } |
| 12223 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12224 | int ReadResponseBody(IOBuffer* buf, |
| 12225 | int buf_len, |
| 12226 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12227 | ADD_FAILURE(); |
| 12228 | return ERR_UNEXPECTED; |
| 12229 | } |
| 12230 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12231 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12232 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12233 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12234 | ADD_FAILURE(); |
| 12235 | return false; |
| 12236 | } |
| 12237 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12238 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12239 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12240 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12241 | ADD_FAILURE(); |
| 12242 | return false; |
| 12243 | } |
| 12244 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12245 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12246 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12247 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12248 | ADD_FAILURE(); |
| 12249 | return false; |
| 12250 | } |
| 12251 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12252 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 12253 | ADD_FAILURE(); |
| 12254 | return 0; |
| 12255 | } |
| 12256 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12257 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12258 | ADD_FAILURE(); |
| 12259 | return false; |
| 12260 | } |
| 12261 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12262 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 12263 | |
| 12264 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12265 | ADD_FAILURE(); |
| 12266 | } |
| 12267 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12268 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12269 | ADD_FAILURE(); |
| 12270 | return false; |
| 12271 | } |
| 12272 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12273 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12274 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12275 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12276 | |
| 12277 | private: |
| 12278 | RequestPriority priority_; |
| 12279 | |
| 12280 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 12281 | }; |
| 12282 | |
| 12283 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 12284 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12285 | class FakeStreamRequest : public HttpStreamRequest, |
| 12286 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 12287 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12288 | FakeStreamRequest(RequestPriority priority, |
| 12289 | HttpStreamRequest::Delegate* delegate) |
| 12290 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12291 | delegate_(delegate), |
| 12292 | websocket_stream_create_helper_(NULL) {} |
| 12293 | |
| 12294 | FakeStreamRequest(RequestPriority priority, |
| 12295 | HttpStreamRequest::Delegate* delegate, |
| 12296 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 12297 | : priority_(priority), |
| 12298 | delegate_(delegate), |
| 12299 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12300 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12301 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12302 | |
| 12303 | RequestPriority priority() const { return priority_; } |
| 12304 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12305 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 12306 | websocket_stream_create_helper() const { |
| 12307 | return websocket_stream_create_helper_; |
| 12308 | } |
| 12309 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12310 | // Create a new FakeStream and pass it to the request's |
| 12311 | // delegate. Returns a weak pointer to the FakeStream. |
| 12312 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 12313 | FakeStream* fake_stream = new FakeStream(priority_); |
| 12314 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 12315 | // immediately delete |fake_stream|. |
| 12316 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 12317 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 12318 | return weak_stream; |
| 12319 | } |
| 12320 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12321 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12322 | ADD_FAILURE(); |
| 12323 | return ERR_UNEXPECTED; |
| 12324 | } |
| 12325 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12326 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12327 | ADD_FAILURE(); |
| 12328 | return LoadState(); |
| 12329 | } |
| 12330 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12331 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12332 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12333 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12334 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12335 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12336 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12337 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12338 | |
| 12339 | private: |
| 12340 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12341 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12342 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12343 | |
| 12344 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 12345 | }; |
| 12346 | |
| 12347 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 12348 | class FakeStreamFactory : public HttpStreamFactory { |
| 12349 | public: |
| 12350 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12351 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12352 | |
| 12353 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 12354 | // RequestStream() (which may be NULL if it was destroyed already). |
| 12355 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 12356 | return last_stream_request_; |
| 12357 | } |
| 12358 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12359 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 12360 | RequestPriority priority, |
| 12361 | const SSLConfig& server_ssl_config, |
| 12362 | const SSLConfig& proxy_ssl_config, |
| 12363 | HttpStreamRequest::Delegate* delegate, |
| 12364 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12365 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12366 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12367 | return fake_request; |
| 12368 | } |
| 12369 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12370 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12371 | const HttpRequestInfo& info, |
| 12372 | RequestPriority priority, |
| 12373 | const SSLConfig& server_ssl_config, |
| 12374 | const SSLConfig& proxy_ssl_config, |
| 12375 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 12376 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12377 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12378 | FakeStreamRequest* fake_request = |
| 12379 | new FakeStreamRequest(priority, delegate, create_helper); |
| 12380 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12381 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12382 | } |
| 12383 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12384 | void PreconnectStreams(int num_streams, |
| 12385 | const HttpRequestInfo& info, |
| 12386 | RequestPriority priority, |
| 12387 | const SSLConfig& server_ssl_config, |
| 12388 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12389 | ADD_FAILURE(); |
| 12390 | } |
| 12391 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12392 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12393 | ADD_FAILURE(); |
| 12394 | return NULL; |
| 12395 | } |
| 12396 | |
| 12397 | private: |
| 12398 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 12399 | |
| 12400 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 12401 | }; |
| 12402 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12403 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 12404 | // worth doing. |
| 12405 | class FakeWebSocketStreamCreateHelper : |
| 12406 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 12407 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12408 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 12409 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12410 | bool using_proxy) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12411 | NOTREACHED(); |
| 12412 | return NULL; |
| 12413 | } |
| 12414 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12415 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12416 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12417 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12418 | NOTREACHED(); |
| 12419 | return NULL; |
| 12420 | }; |
| 12421 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12422 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12423 | |
| 12424 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 12425 | NOTREACHED(); |
| 12426 | return scoped_ptr<WebSocketStream>(); |
| 12427 | } |
| 12428 | }; |
| 12429 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12430 | } // namespace |
| 12431 | |
| 12432 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 12433 | // stream request on start. |
| 12434 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 12435 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12436 | HttpNetworkSessionPeer peer(session); |
| 12437 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12438 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12439 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12440 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12441 | |
| 12442 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 12443 | |
| 12444 | HttpRequestInfo request; |
| 12445 | TestCompletionCallback callback; |
| 12446 | EXPECT_EQ(ERR_IO_PENDING, |
| 12447 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12448 | |
| 12449 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12450 | fake_factory->last_stream_request(); |
| 12451 | ASSERT_TRUE(fake_request != NULL); |
| 12452 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12453 | } |
| 12454 | |
| 12455 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12456 | // updates to its stream request. |
| 12457 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 12458 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12459 | HttpNetworkSessionPeer peer(session); |
| 12460 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12461 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12462 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12463 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12464 | |
| 12465 | HttpRequestInfo request; |
| 12466 | TestCompletionCallback callback; |
| 12467 | EXPECT_EQ(ERR_IO_PENDING, |
| 12468 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12469 | |
| 12470 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12471 | fake_factory->last_stream_request(); |
| 12472 | ASSERT_TRUE(fake_request != NULL); |
| 12473 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12474 | |
| 12475 | trans.SetPriority(LOWEST); |
| 12476 | ASSERT_TRUE(fake_request != NULL); |
| 12477 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 12478 | } |
| 12479 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12480 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12481 | // updates to its stream. |
| 12482 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 12483 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12484 | HttpNetworkSessionPeer peer(session); |
| 12485 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12486 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12487 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12488 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12489 | |
| 12490 | HttpRequestInfo request; |
| 12491 | TestCompletionCallback callback; |
| 12492 | EXPECT_EQ(ERR_IO_PENDING, |
| 12493 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12494 | |
| 12495 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12496 | fake_factory->last_stream_request(); |
| 12497 | ASSERT_TRUE(fake_request != NULL); |
| 12498 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 12499 | ASSERT_TRUE(fake_stream != NULL); |
| 12500 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 12501 | |
| 12502 | trans.SetPriority(LOWEST); |
| 12503 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 12504 | } |
| 12505 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12506 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 12507 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 12508 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 12509 | // that the different schemes work. |
| 12510 | std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"}; |
| 12511 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 12512 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12513 | HttpNetworkSessionPeer peer(session); |
| 12514 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12515 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 12516 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12517 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 12518 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12519 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12520 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 12521 | &websocket_stream_create_helper); |
| 12522 | |
| 12523 | HttpRequestInfo request; |
| 12524 | TestCompletionCallback callback; |
| 12525 | request.method = "GET"; |
| 12526 | request.url = GURL(test_cases[i]); |
| 12527 | |
| 12528 | EXPECT_EQ(ERR_IO_PENDING, |
| 12529 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12530 | |
| 12531 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12532 | fake_factory->last_stream_request(); |
| 12533 | ASSERT_TRUE(fake_request != NULL); |
| 12534 | EXPECT_EQ(&websocket_stream_create_helper, |
| 12535 | fake_request->websocket_stream_create_helper()); |
| 12536 | } |
| 12537 | } |
| 12538 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12539 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 12540 | // if the transport socket pool is stalled on the global socket limit. |
| 12541 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 12542 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12543 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12544 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12545 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12546 | |
| 12547 | // Set up SSL request. |
| 12548 | |
| 12549 | HttpRequestInfo ssl_request; |
| 12550 | ssl_request.method = "GET"; |
| 12551 | ssl_request.url = GURL("https://www.google.com/"); |
| 12552 | |
| 12553 | MockWrite ssl_writes[] = { |
| 12554 | MockWrite("GET / HTTP/1.1\r\n" |
| 12555 | "Host: www.google.com\r\n" |
| 12556 | "Connection: keep-alive\r\n\r\n"), |
| 12557 | }; |
| 12558 | MockRead ssl_reads[] = { |
| 12559 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12560 | MockRead("Content-Length: 11\r\n\r\n"), |
| 12561 | MockRead("hello world"), |
| 12562 | MockRead(SYNCHRONOUS, OK), |
| 12563 | }; |
| 12564 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 12565 | ssl_writes, arraysize(ssl_writes)); |
| 12566 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12567 | |
| 12568 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12570 | |
| 12571 | // Set up HTTP request. |
| 12572 | |
| 12573 | HttpRequestInfo http_request; |
| 12574 | http_request.method = "GET"; |
| 12575 | http_request.url = GURL("http://www.google.com/"); |
| 12576 | |
| 12577 | MockWrite http_writes[] = { |
| 12578 | MockWrite("GET / HTTP/1.1\r\n" |
| 12579 | "Host: www.google.com\r\n" |
| 12580 | "Connection: keep-alive\r\n\r\n"), |
| 12581 | }; |
| 12582 | MockRead http_reads[] = { |
| 12583 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12584 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12585 | MockRead("falafel"), |
| 12586 | MockRead(SYNCHRONOUS, OK), |
| 12587 | }; |
| 12588 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12589 | http_writes, arraysize(http_writes)); |
| 12590 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12591 | |
| 12592 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12593 | |
| 12594 | // Start the SSL request. |
| 12595 | TestCompletionCallback ssl_callback; |
| 12596 | scoped_ptr<HttpTransaction> ssl_trans( |
| 12597 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12598 | ASSERT_EQ(ERR_IO_PENDING, |
| 12599 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 12600 | BoundNetLog())); |
| 12601 | |
| 12602 | // Start the HTTP request. Pool should stall. |
| 12603 | TestCompletionCallback http_callback; |
| 12604 | scoped_ptr<HttpTransaction> http_trans( |
| 12605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12606 | ASSERT_EQ(ERR_IO_PENDING, |
| 12607 | http_trans->Start(&http_request, http_callback.callback(), |
| 12608 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12609 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12610 | |
| 12611 | // Wait for response from SSL request. |
| 12612 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 12613 | std::string response_data; |
| 12614 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 12615 | EXPECT_EQ("hello world", response_data); |
| 12616 | |
| 12617 | // The SSL socket should automatically be closed, so the HTTP request can |
| 12618 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12619 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 12620 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12621 | |
| 12622 | // The HTTP request can now complete. |
| 12623 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12624 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12625 | EXPECT_EQ("falafel", response_data); |
| 12626 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12627 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12628 | } |
| 12629 | |
| 12630 | // Tests that when a SSL connection is established but there's no corresponding |
| 12631 | // request that needs it, the new socket is closed if the transport socket pool |
| 12632 | // is stalled on the global socket limit. |
| 12633 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 12634 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12635 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12636 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12637 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12638 | |
| 12639 | // Set up an ssl request. |
| 12640 | |
| 12641 | HttpRequestInfo ssl_request; |
| 12642 | ssl_request.method = "GET"; |
| 12643 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 12644 | |
| 12645 | // No data will be sent on the SSL socket. |
| 12646 | StaticSocketDataProvider ssl_data; |
| 12647 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12648 | |
| 12649 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12650 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12651 | |
| 12652 | // Set up HTTP request. |
| 12653 | |
| 12654 | HttpRequestInfo http_request; |
| 12655 | http_request.method = "GET"; |
| 12656 | http_request.url = GURL("http://www.google.com/"); |
| 12657 | |
| 12658 | MockWrite http_writes[] = { |
| 12659 | MockWrite("GET / HTTP/1.1\r\n" |
| 12660 | "Host: www.google.com\r\n" |
| 12661 | "Connection: keep-alive\r\n\r\n"), |
| 12662 | }; |
| 12663 | MockRead http_reads[] = { |
| 12664 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12665 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12666 | MockRead("falafel"), |
| 12667 | MockRead(SYNCHRONOUS, OK), |
| 12668 | }; |
| 12669 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12670 | http_writes, arraysize(http_writes)); |
| 12671 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12672 | |
| 12673 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12674 | |
| 12675 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 12676 | // cancelled when a normal transaction is cancelled. |
| 12677 | net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 12678 | net::SSLConfig ssl_config; |
| 12679 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 12680 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 12681 | ssl_config, ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12682 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12683 | |
| 12684 | // Start the HTTP request. Pool should stall. |
| 12685 | TestCompletionCallback http_callback; |
| 12686 | scoped_ptr<HttpTransaction> http_trans( |
| 12687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12688 | ASSERT_EQ(ERR_IO_PENDING, |
| 12689 | http_trans->Start(&http_request, http_callback.callback(), |
| 12690 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12691 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12692 | |
| 12693 | // The SSL connection will automatically be closed once the connection is |
| 12694 | // established, to let the HTTP request start. |
| 12695 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12696 | std::string response_data; |
| 12697 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12698 | EXPECT_EQ("falafel", response_data); |
| 12699 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12700 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12701 | } |
| 12702 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12703 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 12704 | ScopedVector<UploadElementReader> element_readers; |
| 12705 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12706 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12707 | |
| 12708 | HttpRequestInfo request; |
| 12709 | request.method = "POST"; |
| 12710 | request.url = GURL("http://www.foo.com/"); |
| 12711 | request.upload_data_stream = &upload_data_stream; |
| 12712 | request.load_flags = 0; |
| 12713 | |
| 12714 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12715 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12717 | // Send headers successfully, but get an error while sending the body. |
| 12718 | MockWrite data_writes[] = { |
| 12719 | MockWrite("POST / HTTP/1.1\r\n" |
| 12720 | "Host: www.foo.com\r\n" |
| 12721 | "Connection: keep-alive\r\n" |
| 12722 | "Content-Length: 3\r\n\r\n"), |
| 12723 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12724 | }; |
| 12725 | |
| 12726 | MockRead data_reads[] = { |
| 12727 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12728 | MockRead("hello world"), |
| 12729 | MockRead(SYNCHRONOUS, OK), |
| 12730 | }; |
| 12731 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12732 | arraysize(data_writes)); |
| 12733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12734 | |
| 12735 | TestCompletionCallback callback; |
| 12736 | |
| 12737 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12738 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12739 | |
| 12740 | rv = callback.WaitForResult(); |
| 12741 | EXPECT_EQ(OK, rv); |
| 12742 | |
| 12743 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12744 | ASSERT_TRUE(response != NULL); |
| 12745 | |
| 12746 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12747 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12748 | |
| 12749 | std::string response_data; |
| 12750 | rv = ReadTransaction(trans.get(), &response_data); |
| 12751 | EXPECT_EQ(OK, rv); |
| 12752 | EXPECT_EQ("hello world", response_data); |
| 12753 | } |
| 12754 | |
| 12755 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 12756 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 12757 | TEST_P(HttpNetworkTransactionTest, |
| 12758 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 12759 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12760 | MockWrite data_writes[] = { |
| 12761 | MockWrite("GET / HTTP/1.1\r\n" |
| 12762 | "Host: www.foo.com\r\n" |
| 12763 | "Connection: keep-alive\r\n\r\n"), |
| 12764 | MockWrite("POST / HTTP/1.1\r\n" |
| 12765 | "Host: www.foo.com\r\n" |
| 12766 | "Connection: keep-alive\r\n" |
| 12767 | "Content-Length: 3\r\n\r\n"), |
| 12768 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12769 | }; |
| 12770 | |
| 12771 | MockRead data_reads[] = { |
| 12772 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 12773 | "Content-Length: 14\r\n\r\n"), |
| 12774 | MockRead("first response"), |
| 12775 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 12776 | "Content-Length: 15\r\n\r\n"), |
| 12777 | MockRead("second response"), |
| 12778 | MockRead(SYNCHRONOUS, OK), |
| 12779 | }; |
| 12780 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12781 | arraysize(data_writes)); |
| 12782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12783 | |
| 12784 | TestCompletionCallback callback; |
| 12785 | HttpRequestInfo request1; |
| 12786 | request1.method = "GET"; |
| 12787 | request1.url = GURL("http://www.foo.com/"); |
| 12788 | request1.load_flags = 0; |
| 12789 | |
| 12790 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12792 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 12793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12794 | |
| 12795 | rv = callback.WaitForResult(); |
| 12796 | EXPECT_EQ(OK, rv); |
| 12797 | |
| 12798 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12799 | ASSERT_TRUE(response1 != NULL); |
| 12800 | |
| 12801 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 12802 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 12803 | |
| 12804 | std::string response_data1; |
| 12805 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 12806 | EXPECT_EQ(OK, rv); |
| 12807 | EXPECT_EQ("first response", response_data1); |
| 12808 | // Delete the transaction to release the socket back into the socket pool. |
| 12809 | trans1.reset(); |
| 12810 | |
| 12811 | ScopedVector<UploadElementReader> element_readers; |
| 12812 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12813 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12814 | |
| 12815 | HttpRequestInfo request2; |
| 12816 | request2.method = "POST"; |
| 12817 | request2.url = GURL("http://www.foo.com/"); |
| 12818 | request2.upload_data_stream = &upload_data_stream; |
| 12819 | request2.load_flags = 0; |
| 12820 | |
| 12821 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12822 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12823 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 12824 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12825 | |
| 12826 | rv = callback.WaitForResult(); |
| 12827 | EXPECT_EQ(OK, rv); |
| 12828 | |
| 12829 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 12830 | ASSERT_TRUE(response2 != NULL); |
| 12831 | |
| 12832 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 12833 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 12834 | |
| 12835 | std::string response_data2; |
| 12836 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 12837 | EXPECT_EQ(OK, rv); |
| 12838 | EXPECT_EQ("second response", response_data2); |
| 12839 | } |
| 12840 | |
| 12841 | TEST_P(HttpNetworkTransactionTest, |
| 12842 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 12843 | ScopedVector<UploadElementReader> element_readers; |
| 12844 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12845 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12846 | |
| 12847 | HttpRequestInfo request; |
| 12848 | request.method = "POST"; |
| 12849 | request.url = GURL("http://www.foo.com/"); |
| 12850 | request.upload_data_stream = &upload_data_stream; |
| 12851 | request.load_flags = 0; |
| 12852 | |
| 12853 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12854 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12855 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12856 | // Send headers successfully, but get an error while sending the body. |
| 12857 | MockWrite data_writes[] = { |
| 12858 | MockWrite("POST / HTTP/1.1\r\n" |
| 12859 | "Host: www.foo.com\r\n" |
| 12860 | "Connection: keep-alive\r\n" |
| 12861 | "Content-Length: 3\r\n\r\n" |
| 12862 | "fo"), |
| 12863 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12864 | }; |
| 12865 | |
| 12866 | MockRead data_reads[] = { |
| 12867 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12868 | MockRead("hello world"), |
| 12869 | MockRead(SYNCHRONOUS, OK), |
| 12870 | }; |
| 12871 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12872 | arraysize(data_writes)); |
| 12873 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12874 | |
| 12875 | TestCompletionCallback callback; |
| 12876 | |
| 12877 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12879 | |
| 12880 | rv = callback.WaitForResult(); |
| 12881 | EXPECT_EQ(OK, rv); |
| 12882 | |
| 12883 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12884 | ASSERT_TRUE(response != NULL); |
| 12885 | |
| 12886 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12887 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12888 | |
| 12889 | std::string response_data; |
| 12890 | rv = ReadTransaction(trans.get(), &response_data); |
| 12891 | EXPECT_EQ(OK, rv); |
| 12892 | EXPECT_EQ("hello world", response_data); |
| 12893 | } |
| 12894 | |
| 12895 | // This tests the more common case than the previous test, where headers and |
| 12896 | // body are not merged into a single request. |
| 12897 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 12898 | ScopedVector<UploadElementReader> element_readers; |
| 12899 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12900 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12901 | |
| 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( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12910 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12911 | // 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 | "Transfer-Encoding: chunked\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 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 12934 | // they can't be merged with the body in a single send. Not currently |
| 12935 | // necessary since a chunked body is never merged with headers, but this makes |
| 12936 | // the test more future proof. |
| 12937 | base::RunLoop().RunUntilIdle(); |
| 12938 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12939 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12940 | |
| 12941 | rv = callback.WaitForResult(); |
| 12942 | EXPECT_EQ(OK, rv); |
| 12943 | |
| 12944 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12945 | ASSERT_TRUE(response != NULL); |
| 12946 | |
| 12947 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12948 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12949 | |
| 12950 | std::string response_data; |
| 12951 | rv = ReadTransaction(trans.get(), &response_data); |
| 12952 | EXPECT_EQ(OK, rv); |
| 12953 | EXPECT_EQ("hello world", response_data); |
| 12954 | } |
| 12955 | |
| 12956 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 12957 | ScopedVector<UploadElementReader> element_readers; |
| 12958 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12959 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12960 | |
| 12961 | HttpRequestInfo request; |
| 12962 | request.method = "POST"; |
| 12963 | request.url = GURL("http://www.foo.com/"); |
| 12964 | request.upload_data_stream = &upload_data_stream; |
| 12965 | request.load_flags = 0; |
| 12966 | |
| 12967 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12968 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12969 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12970 | |
| 12971 | MockWrite data_writes[] = { |
| 12972 | MockWrite("POST / HTTP/1.1\r\n" |
| 12973 | "Host: www.foo.com\r\n" |
| 12974 | "Connection: keep-alive\r\n" |
| 12975 | "Content-Length: 3\r\n\r\n"), |
| 12976 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12977 | }; |
| 12978 | |
| 12979 | MockRead data_reads[] = { |
| 12980 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 12981 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12982 | MockRead("hello world"), |
| 12983 | MockRead(SYNCHRONOUS, OK), |
| 12984 | }; |
| 12985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12986 | arraysize(data_writes)); |
| 12987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12988 | |
| 12989 | TestCompletionCallback callback; |
| 12990 | |
| 12991 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12992 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12993 | |
| 12994 | rv = callback.WaitForResult(); |
| 12995 | EXPECT_EQ(OK, rv); |
| 12996 | |
| 12997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12998 | ASSERT_TRUE(response != NULL); |
| 12999 | |
| 13000 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13001 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13002 | |
| 13003 | std::string response_data; |
| 13004 | rv = ReadTransaction(trans.get(), &response_data); |
| 13005 | EXPECT_EQ(OK, rv); |
| 13006 | EXPECT_EQ("hello world", response_data); |
| 13007 | } |
| 13008 | |
| 13009 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 13010 | ScopedVector<UploadElementReader> element_readers; |
| 13011 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13012 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13013 | |
| 13014 | HttpRequestInfo request; |
| 13015 | request.method = "POST"; |
| 13016 | request.url = GURL("http://www.foo.com/"); |
| 13017 | request.upload_data_stream = &upload_data_stream; |
| 13018 | request.load_flags = 0; |
| 13019 | |
| 13020 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13021 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13023 | // Send headers successfully, but get an error while sending the body. |
| 13024 | MockWrite data_writes[] = { |
| 13025 | MockWrite("POST / HTTP/1.1\r\n" |
| 13026 | "Host: www.foo.com\r\n" |
| 13027 | "Connection: keep-alive\r\n" |
| 13028 | "Content-Length: 3\r\n\r\n"), |
| 13029 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13030 | }; |
| 13031 | |
| 13032 | MockRead data_reads[] = { |
| 13033 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 13034 | MockRead("hello world"), |
| 13035 | MockRead(SYNCHRONOUS, OK), |
| 13036 | }; |
| 13037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13038 | arraysize(data_writes)); |
| 13039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13040 | |
| 13041 | TestCompletionCallback callback; |
| 13042 | |
| 13043 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13044 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13045 | |
| 13046 | rv = callback.WaitForResult(); |
| 13047 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13048 | |
| 13049 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13050 | EXPECT_TRUE(response == NULL); |
| 13051 | } |
| 13052 | |
| 13053 | TEST_P(HttpNetworkTransactionTest, |
| 13054 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 13055 | ScopedVector<UploadElementReader> element_readers; |
| 13056 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13057 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13058 | |
| 13059 | HttpRequestInfo request; |
| 13060 | request.method = "POST"; |
| 13061 | request.url = GURL("http://www.foo.com/"); |
| 13062 | request.upload_data_stream = &upload_data_stream; |
| 13063 | request.load_flags = 0; |
| 13064 | |
| 13065 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13066 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13068 | // Send headers successfully, but get an error while sending the body. |
| 13069 | MockWrite data_writes[] = { |
| 13070 | MockWrite("POST / HTTP/1.1\r\n" |
| 13071 | "Host: www.foo.com\r\n" |
| 13072 | "Connection: keep-alive\r\n" |
| 13073 | "Content-Length: 3\r\n\r\n"), |
| 13074 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13075 | }; |
| 13076 | |
| 13077 | MockRead data_reads[] = { |
| 13078 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13079 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 13080 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 13081 | MockRead("Content-Length: 0\r\n\r\n"), |
| 13082 | MockRead(SYNCHRONOUS, OK), |
| 13083 | }; |
| 13084 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13085 | arraysize(data_writes)); |
| 13086 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13087 | |
| 13088 | TestCompletionCallback callback; |
| 13089 | |
| 13090 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13092 | |
| 13093 | rv = callback.WaitForResult(); |
| 13094 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13095 | |
| 13096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13097 | EXPECT_TRUE(response == NULL); |
| 13098 | } |
| 13099 | |
| 13100 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 13101 | ScopedVector<UploadElementReader> element_readers; |
| 13102 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13103 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13104 | |
| 13105 | HttpRequestInfo request; |
| 13106 | request.method = "POST"; |
| 13107 | request.url = GURL("http://www.foo.com/"); |
| 13108 | request.upload_data_stream = &upload_data_stream; |
| 13109 | request.load_flags = 0; |
| 13110 | |
| 13111 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13112 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13114 | // Send headers successfully, but get an error while sending the body. |
| 13115 | MockWrite data_writes[] = { |
| 13116 | MockWrite("POST / HTTP/1.1\r\n" |
| 13117 | "Host: www.foo.com\r\n" |
| 13118 | "Connection: keep-alive\r\n" |
| 13119 | "Content-Length: 3\r\n\r\n"), |
| 13120 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13121 | }; |
| 13122 | |
| 13123 | MockRead data_reads[] = { |
| 13124 | MockRead("HTTP 0.9 rocks!"), |
| 13125 | MockRead(SYNCHRONOUS, OK), |
| 13126 | }; |
| 13127 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13128 | arraysize(data_writes)); |
| 13129 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13130 | |
| 13131 | TestCompletionCallback callback; |
| 13132 | |
| 13133 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13134 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13135 | |
| 13136 | rv = callback.WaitForResult(); |
| 13137 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13138 | |
| 13139 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13140 | EXPECT_TRUE(response == NULL); |
| 13141 | } |
| 13142 | |
| 13143 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 13144 | ScopedVector<UploadElementReader> element_readers; |
| 13145 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13146 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13147 | |
| 13148 | HttpRequestInfo request; |
| 13149 | request.method = "POST"; |
| 13150 | request.url = GURL("http://www.foo.com/"); |
| 13151 | request.upload_data_stream = &upload_data_stream; |
| 13152 | request.load_flags = 0; |
| 13153 | |
| 13154 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13155 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13156 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13157 | // Send headers successfully, but get an error while sending the body. |
| 13158 | MockWrite data_writes[] = { |
| 13159 | MockWrite("POST / HTTP/1.1\r\n" |
| 13160 | "Host: www.foo.com\r\n" |
| 13161 | "Connection: keep-alive\r\n" |
| 13162 | "Content-Length: 3\r\n\r\n"), |
| 13163 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13164 | }; |
| 13165 | |
| 13166 | MockRead data_reads[] = { |
| 13167 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 13168 | MockRead(SYNCHRONOUS, OK), |
| 13169 | }; |
| 13170 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13171 | arraysize(data_writes)); |
| 13172 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13173 | |
| 13174 | TestCompletionCallback callback; |
| 13175 | |
| 13176 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13177 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13178 | |
| 13179 | rv = callback.WaitForResult(); |
| 13180 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13181 | |
| 13182 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13183 | EXPECT_TRUE(response == NULL); |
| 13184 | } |
| 13185 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 13186 | } // namespace net |