[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 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 271 | const char* GetAlternateProtocolFromParam() { |
| 272 | return |
| 273 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 274 | } |
| 275 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 276 | // This is the expected return from a current server advertising SPDY. |
| 277 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 278 | return std::string("Alternate-Protocol: 443:") + |
| 279 | GetAlternateProtocolFromParam() + "\r\n\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 280 | } |
| 281 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 282 | // Either |write_failure| specifies a write failure or |read_failure| |
| 283 | // specifies a read failure when using a reused socket. In either case, the |
| 284 | // failure should cause the network transaction to resend the request, and the |
| 285 | // other argument should be NULL. |
| 286 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 287 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 288 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 289 | // Either |write_failure| specifies a write failure or |read_failure| |
| 290 | // specifies a read failure when using a reused socket. In either case, the |
| 291 | // failure should cause the network transaction to resend the request, and the |
| 292 | // other argument should be NULL. |
| 293 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 294 | const MockRead* read_failure, |
| 295 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 296 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 297 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 298 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 299 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 300 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 301 | HttpRequestInfo request; |
| 302 | request.method = "GET"; |
| 303 | request.url = GURL("http://www.google.com/"); |
| 304 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 305 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 306 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 307 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 308 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 309 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 310 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 311 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 312 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 313 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 314 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 316 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 317 | |
[email protected] | c47c037 | 2014-03-12 23:07:02 | [diff] [blame] | 318 | EXPECT_TRUE(log.bound().IsLogging()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 319 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 320 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 321 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 322 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 323 | |
| 324 | // Even in the failure cases that use this function, connections are always |
| 325 | // successfully established before the error. |
| 326 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 327 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 328 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 329 | if (out.rv != OK) |
| 330 | return out; |
| 331 | |
| 332 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 333 | // Can't use ASSERT_* inside helper functions like this, so |
| 334 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 335 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 336 | out.rv = ERR_UNEXPECTED; |
| 337 | return out; |
| 338 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 339 | out.status_line = response->headers->GetStatusLine(); |
| 340 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 341 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 342 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 343 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 344 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 345 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 346 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 347 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 348 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 349 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 350 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 351 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 352 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 353 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 354 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 355 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 356 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 357 | std::string line; |
| 358 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 359 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 360 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 361 | HttpRequestHeaders request_headers; |
| 362 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 363 | std::string value; |
| 364 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
| 365 | EXPECT_EQ("www.google.com", value); |
| 366 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 367 | EXPECT_EQ("keep-alive", value); |
| 368 | |
| 369 | std::string response_headers; |
| 370 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
| 371 | EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", |
| 372 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 373 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 374 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 375 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 376 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 377 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 378 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 379 | size_t reads_count) { |
| 380 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 381 | StaticSocketDataProvider* data[] = { &reads }; |
| 382 | return SimpleGetHelperForData(data, 1); |
| 383 | } |
| 384 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 385 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 386 | int64 size = 0; |
| 387 | for (size_t i = 0; i < reads_count; ++i) |
| 388 | size += data_reads[i].data_len; |
| 389 | return size; |
| 390 | } |
| 391 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 392 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 393 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 394 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 395 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 396 | |
| 397 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 398 | |
| 399 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 400 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 401 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 402 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 403 | |
| 404 | // Original socket limits. Some tests set these. Safest to always restore |
| 405 | // them once each test has been run. |
| 406 | int old_max_group_sockets_; |
| 407 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 408 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 409 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 410 | INSTANTIATE_TEST_CASE_P( |
| 411 | NextProto, |
| 412 | HttpNetworkTransactionTest, |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 413 | testing::Values(kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 414 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 415 | namespace { |
| 416 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 417 | class BeforeNetworkStartHandler { |
| 418 | public: |
| 419 | explicit BeforeNetworkStartHandler(bool defer) |
| 420 | : defer_on_before_network_start_(defer), |
| 421 | observed_before_network_start_(false) {} |
| 422 | |
| 423 | void OnBeforeNetworkStart(bool* defer) { |
| 424 | *defer = defer_on_before_network_start_; |
| 425 | observed_before_network_start_ = true; |
| 426 | } |
| 427 | |
| 428 | bool observed_before_network_start() const { |
| 429 | return observed_before_network_start_; |
| 430 | } |
| 431 | |
| 432 | private: |
| 433 | const bool defer_on_before_network_start_; |
| 434 | bool observed_before_network_start_; |
| 435 | |
| 436 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 437 | }; |
| 438 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 439 | class BeforeProxyHeadersSentHandler { |
| 440 | public: |
| 441 | BeforeProxyHeadersSentHandler() |
| 442 | : observed_before_proxy_headers_sent_(false) {} |
| 443 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 444 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 445 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 446 | observed_before_proxy_headers_sent_ = true; |
| 447 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 448 | } |
| 449 | |
| 450 | bool observed_before_proxy_headers_sent() const { |
| 451 | return observed_before_proxy_headers_sent_; |
| 452 | } |
| 453 | |
| 454 | std::string observed_proxy_server_uri() const { |
| 455 | return observed_proxy_server_uri_; |
| 456 | } |
| 457 | |
| 458 | private: |
| 459 | bool observed_before_proxy_headers_sent_; |
| 460 | std::string observed_proxy_server_uri_; |
| 461 | |
| 462 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 463 | }; |
| 464 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 465 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 466 | void FillLargeHeadersString(std::string* str, int size) { |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 467 | const char* row = |
| 468 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 469 | const int sizeof_row = strlen(row); |
| 470 | const int num_rows = static_cast<int>( |
| 471 | ceil(static_cast<float>(size) / sizeof_row)); |
| 472 | const int sizeof_data = num_rows * sizeof_row; |
| 473 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 474 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 475 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 476 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 477 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 478 | } |
| 479 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 480 | // Alternative functions that eliminate randomness and dependency on the local |
| 481 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 482 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 483 | static const uint8 bytes[] = { |
| 484 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 485 | }; |
| 486 | static size_t current_byte = 0; |
| 487 | for (size_t i = 0; i < n; ++i) { |
| 488 | output[i] = bytes[current_byte++]; |
| 489 | current_byte %= arraysize(bytes); |
| 490 | } |
| 491 | } |
| 492 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 493 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 494 | static const uint8 bytes[] = { |
| 495 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 496 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 497 | }; |
| 498 | static size_t current_byte = 0; |
| 499 | for (size_t i = 0; i < n; ++i) { |
| 500 | output[i] = bytes[current_byte++]; |
| 501 | current_byte %= arraysize(bytes); |
| 502 | } |
| 503 | } |
| 504 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 505 | std::string MockGetHostName() { |
| 506 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 509 | template<typename ParentPool> |
| 510 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 511 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 512 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 513 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 514 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 515 | const std::string last_group_name_received() const { |
| 516 | return last_group_name_; |
| 517 | } |
| 518 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame^] | 519 | int RequestSocket(const std::string& group_name, |
| 520 | const void* socket_params, |
| 521 | RequestPriority priority, |
| 522 | ClientSocketHandle* handle, |
| 523 | const CompletionCallback& callback, |
| 524 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 525 | last_group_name_ = group_name; |
| 526 | return ERR_IO_PENDING; |
| 527 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame^] | 528 | void CancelRequest(const std::string& group_name, |
| 529 | ClientSocketHandle* handle) override {} |
| 530 | void ReleaseSocket(const std::string& group_name, |
| 531 | scoped_ptr<StreamSocket> socket, |
| 532 | int id) override {} |
| 533 | void CloseIdleSockets() override {} |
| 534 | int IdleSocketCount() const override { return 0; } |
| 535 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 536 | return 0; |
| 537 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame^] | 538 | LoadState GetLoadState(const std::string& group_name, |
| 539 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 540 | return LOAD_STATE_IDLE; |
| 541 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame^] | 542 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 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, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 584 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 585 | std::string(), |
| 586 | NULL, |
| 587 | NULL, |
| 588 | NULL, |
| 589 | NULL, |
| 590 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 591 | false, |
| 592 | NULL) { |
| 593 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 594 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 595 | //----------------------------------------------------------------------------- |
| 596 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 597 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 598 | // configured for common cases. |
| 599 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 600 | if (!auth_challenge) |
| 601 | return false; |
| 602 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 603 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 604 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 605 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 606 | return true; |
| 607 | } |
| 608 | |
| 609 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 610 | if (!auth_challenge) |
| 611 | return false; |
| 612 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 613 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 614 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 615 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 616 | return true; |
| 617 | } |
| 618 | |
| 619 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 620 | if (!auth_challenge) |
| 621 | return false; |
| 622 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 623 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 624 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 625 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 630 | if (!auth_challenge) |
| 631 | return false; |
| 632 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 633 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 634 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 635 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 636 | return true; |
| 637 | } |
| 638 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 639 | } // namespace |
| 640 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 641 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 642 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 643 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 644 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 645 | } |
| 646 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 647 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 648 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 649 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 650 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 651 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 652 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 653 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 654 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 655 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 656 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 657 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 658 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 659 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 663 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 664 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 665 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 667 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 668 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 669 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 670 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 671 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 672 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 673 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 674 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 678 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 679 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 680 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 681 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 682 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 683 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 684 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 685 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 686 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 687 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 688 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 689 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 693 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 694 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 695 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 696 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 697 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 698 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 699 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 700 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 701 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 702 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 703 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 704 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | // 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] | 708 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 709 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 710 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 712 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 713 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 714 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 715 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 716 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 717 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 718 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 719 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 723 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 725 | MockRead("\n"), |
| 726 | MockRead("\n"), |
| 727 | MockRead("Q"), |
| 728 | MockRead("J"), |
| 729 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 730 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 731 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 732 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 733 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 734 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 736 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 737 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 738 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 742 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 743 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 744 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 745 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 747 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 748 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 749 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 750 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 751 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 752 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 753 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 754 | } |
| 755 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 756 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 757 | // persistent connection. The response should still terminate since a 204 |
| 758 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 759 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 760 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 761 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 762 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 763 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 764 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 765 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 766 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 767 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 768 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 769 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 770 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 771 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 772 | int64 response_size = reads_size - strlen(junk); |
| 773 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 774 | } |
| 775 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 776 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 777 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 778 | std::string final_chunk = "0\r\n\r\n"; |
| 779 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 780 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 781 | MockRead data_reads[] = { |
| 782 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 783 | MockRead("5\r\nHello\r\n"), |
| 784 | MockRead("1\r\n"), |
| 785 | MockRead(" \r\n"), |
| 786 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 787 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 789 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 790 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 791 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 792 | EXPECT_EQ(OK, out.rv); |
| 793 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 794 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 795 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 796 | int64 response_size = reads_size - extra_data.size(); |
| 797 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 798 | } |
| 799 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 800 | // Next tests deal with http://crbug.com/56344. |
| 801 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 802 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 803 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 804 | MockRead data_reads[] = { |
| 805 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 806 | MockRead("Content-Length: 10\r\n"), |
| 807 | MockRead("Content-Length: 5\r\n\r\n"), |
| 808 | }; |
| 809 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 810 | arraysize(data_reads)); |
| 811 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 812 | } |
| 813 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 814 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 815 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 816 | MockRead data_reads[] = { |
| 817 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 818 | MockRead("Content-Length: 5\r\n"), |
| 819 | MockRead("Content-Length: 5\r\n\r\n"), |
| 820 | MockRead("Hello"), |
| 821 | }; |
| 822 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 823 | arraysize(data_reads)); |
| 824 | EXPECT_EQ(OK, out.rv); |
| 825 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 826 | EXPECT_EQ("Hello", out.response_data); |
| 827 | } |
| 828 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 829 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 830 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 831 | // More than 2 dupes. |
| 832 | { |
| 833 | MockRead data_reads[] = { |
| 834 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 835 | MockRead("Content-Length: 5\r\n"), |
| 836 | MockRead("Content-Length: 5\r\n"), |
| 837 | MockRead("Content-Length: 5\r\n\r\n"), |
| 838 | MockRead("Hello"), |
| 839 | }; |
| 840 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 841 | arraysize(data_reads)); |
| 842 | EXPECT_EQ(OK, out.rv); |
| 843 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 844 | EXPECT_EQ("Hello", out.response_data); |
| 845 | } |
| 846 | // HTTP/1.0 |
| 847 | { |
| 848 | MockRead data_reads[] = { |
| 849 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 850 | MockRead("Content-Length: 5\r\n"), |
| 851 | MockRead("Content-Length: 5\r\n"), |
| 852 | MockRead("Content-Length: 5\r\n\r\n"), |
| 853 | MockRead("Hello"), |
| 854 | }; |
| 855 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 856 | arraysize(data_reads)); |
| 857 | EXPECT_EQ(OK, out.rv); |
| 858 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 859 | EXPECT_EQ("Hello", out.response_data); |
| 860 | } |
| 861 | // 2 dupes and one mismatched. |
| 862 | { |
| 863 | MockRead data_reads[] = { |
| 864 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 865 | MockRead("Content-Length: 10\r\n"), |
| 866 | MockRead("Content-Length: 10\r\n"), |
| 867 | MockRead("Content-Length: 5\r\n\r\n"), |
| 868 | }; |
| 869 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 870 | arraysize(data_reads)); |
| 871 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 872 | } |
| 873 | } |
| 874 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 875 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 876 | MultipleContentLengthHeadersTransferEncoding) { |
| 877 | MockRead data_reads[] = { |
| 878 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 879 | MockRead("Content-Length: 666\r\n"), |
| 880 | MockRead("Content-Length: 1337\r\n"), |
| 881 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 882 | MockRead("5\r\nHello\r\n"), |
| 883 | MockRead("1\r\n"), |
| 884 | MockRead(" \r\n"), |
| 885 | MockRead("5\r\nworld\r\n"), |
| 886 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 887 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 888 | }; |
| 889 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 890 | arraysize(data_reads)); |
| 891 | EXPECT_EQ(OK, out.rv); |
| 892 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 893 | EXPECT_EQ("Hello world", out.response_data); |
| 894 | } |
| 895 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 896 | // Next tests deal with http://crbug.com/98895. |
| 897 | |
| 898 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 899 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 900 | MockRead data_reads[] = { |
| 901 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 902 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 903 | MockRead("Content-Length: 5\r\n\r\n"), |
| 904 | MockRead("Hello"), |
| 905 | }; |
| 906 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 907 | arraysize(data_reads)); |
| 908 | EXPECT_EQ(OK, out.rv); |
| 909 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 910 | EXPECT_EQ("Hello", out.response_data); |
| 911 | } |
| 912 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 913 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 914 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 915 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 916 | MockRead data_reads[] = { |
| 917 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 918 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 919 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 920 | MockRead("Content-Length: 5\r\n\r\n"), |
| 921 | MockRead("Hello"), |
| 922 | }; |
| 923 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 924 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 925 | EXPECT_EQ(OK, out.rv); |
| 926 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 927 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 931 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 932 | MockRead data_reads[] = { |
| 933 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 934 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 935 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 936 | MockRead("Content-Length: 5\r\n\r\n"), |
| 937 | MockRead("Hello"), |
| 938 | }; |
| 939 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 940 | arraysize(data_reads)); |
| 941 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 942 | } |
| 943 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 944 | // Checks that two identical Location headers result in no error. |
| 945 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 946 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 947 | MockRead data_reads[] = { |
| 948 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 949 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 950 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 951 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 952 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 953 | }; |
| 954 | |
| 955 | HttpRequestInfo request; |
| 956 | request.method = "GET"; |
| 957 | request.url = GURL("http://redirect.com/"); |
| 958 | request.load_flags = 0; |
| 959 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 960 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 961 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 962 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 963 | |
| 964 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 965 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 967 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 968 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 969 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 970 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 971 | |
| 972 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 973 | |
| 974 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 975 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 976 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 977 | std::string url; |
| 978 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 979 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 980 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 981 | } |
| 982 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 983 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 984 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 985 | MockRead data_reads[] = { |
| 986 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 987 | MockRead("Location: http://good.com/\r\n"), |
| 988 | MockRead("Location: http://evil.com/\r\n"), |
| 989 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 990 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 991 | }; |
| 992 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 993 | arraysize(data_reads)); |
| 994 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 995 | } |
| 996 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 997 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 998 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 999 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1000 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1001 | request.method = "HEAD"; |
| 1002 | request.url = GURL("http://www.google.com/"); |
| 1003 | request.load_flags = 0; |
| 1004 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1005 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1006 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1007 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1008 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1009 | trans->SetBeforeProxyHeadersSentCallback( |
| 1010 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1011 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1012 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1013 | MockWrite data_writes1[] = { |
| 1014 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1015 | "Host: www.google.com\r\n" |
| 1016 | "Connection: keep-alive\r\n" |
| 1017 | "Content-Length: 0\r\n\r\n"), |
| 1018 | }; |
| 1019 | MockRead data_reads1[] = { |
| 1020 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1021 | MockRead("Server: Blah\r\n"), |
| 1022 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1023 | |
| 1024 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1025 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1026 | }; |
| 1027 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1028 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1029 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1030 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1032 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1034 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1036 | |
| 1037 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1038 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1039 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1040 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1041 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1042 | |
| 1043 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1044 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1045 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1046 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1047 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1048 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1049 | |
| 1050 | std::string server_header; |
| 1051 | void* iter = NULL; |
| 1052 | bool has_server_header = response->headers->EnumerateHeader( |
| 1053 | &iter, "Server", &server_header); |
| 1054 | EXPECT_TRUE(has_server_header); |
| 1055 | EXPECT_EQ("Blah", server_header); |
| 1056 | |
| 1057 | // Reading should give EOF right away, since there is no message body |
| 1058 | // (despite non-zero content-length). |
| 1059 | std::string response_data; |
| 1060 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1061 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1062 | EXPECT_EQ("", response_data); |
| 1063 | } |
| 1064 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1065 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1066 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1067 | |
| 1068 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1069 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1070 | MockRead("hello"), |
| 1071 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1072 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1073 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1074 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1075 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1077 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1078 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1079 | "hello", "world" |
| 1080 | }; |
| 1081 | |
| 1082 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1083 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1084 | request.method = "GET"; |
| 1085 | request.url = GURL("http://www.google.com/"); |
| 1086 | request.load_flags = 0; |
| 1087 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1088 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1089 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1091 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1093 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1094 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1095 | |
| 1096 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1097 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1098 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1100 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1101 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1102 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1103 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1104 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1105 | |
| 1106 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1107 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1108 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1109 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1113 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1114 | ScopedVector<UploadElementReader> element_readers; |
| 1115 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1116 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1117 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1118 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1119 | request.method = "POST"; |
| 1120 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1121 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1122 | request.load_flags = 0; |
| 1123 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1124 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1125 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1126 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1127 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1128 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1129 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1130 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1131 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1132 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1133 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1134 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1137 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1138 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1139 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1140 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1141 | |
| 1142 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1143 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1145 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1146 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1147 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1148 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1149 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1150 | |
| 1151 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1152 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1153 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1154 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1155 | } |
| 1156 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1157 | // This test is almost the same as Ignores100 above, but the response contains |
| 1158 | // 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] | 1159 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1160 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1161 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1162 | request.method = "GET"; |
| 1163 | request.url = GURL("http://www.foo.com/"); |
| 1164 | request.load_flags = 0; |
| 1165 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1166 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1167 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1169 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1170 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1171 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1172 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1173 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1174 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1175 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1176 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1179 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1183 | |
| 1184 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1185 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1186 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1187 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1188 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1189 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1190 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1191 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1192 | |
| 1193 | std::string response_data; |
| 1194 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1195 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1196 | EXPECT_EQ("hello world", response_data); |
| 1197 | } |
| 1198 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1199 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1200 | HttpRequestInfo request; |
| 1201 | request.method = "POST"; |
| 1202 | request.url = GURL("http://www.foo.com/"); |
| 1203 | request.load_flags = 0; |
| 1204 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1205 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1206 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1208 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1209 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1210 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1211 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1212 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1213 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1216 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1218 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1220 | |
| 1221 | rv = callback.WaitForResult(); |
| 1222 | EXPECT_EQ(OK, rv); |
| 1223 | |
| 1224 | std::string response_data; |
| 1225 | rv = ReadTransaction(trans.get(), &response_data); |
| 1226 | EXPECT_EQ(OK, rv); |
| 1227 | EXPECT_EQ("", response_data); |
| 1228 | } |
| 1229 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1230 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1231 | HttpRequestInfo request; |
| 1232 | request.method = "POST"; |
| 1233 | request.url = GURL("http://www.foo.com/"); |
| 1234 | request.load_flags = 0; |
| 1235 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1236 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1237 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1239 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1240 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1241 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1242 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1243 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1244 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1246 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1248 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1250 | |
| 1251 | rv = callback.WaitForResult(); |
| 1252 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1253 | } |
| 1254 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1255 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1256 | const MockWrite* write_failure, |
| 1257 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1258 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1259 | request.method = "GET"; |
| 1260 | request.url = GURL("http://www.foo.com/"); |
| 1261 | request.load_flags = 0; |
| 1262 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1263 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1264 | session_deps_.net_log = &net_log; |
| 1265 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1266 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1267 | // Written data for successfully sending both requests. |
| 1268 | MockWrite data1_writes[] = { |
| 1269 | MockWrite("GET / HTTP/1.1\r\n" |
| 1270 | "Host: www.foo.com\r\n" |
| 1271 | "Connection: keep-alive\r\n\r\n"), |
| 1272 | MockWrite("GET / HTTP/1.1\r\n" |
| 1273 | "Host: www.foo.com\r\n" |
| 1274 | "Connection: keep-alive\r\n\r\n") |
| 1275 | }; |
| 1276 | |
| 1277 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1278 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1279 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1280 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1281 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1282 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1283 | |
| 1284 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1285 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1286 | data1_writes[1] = *write_failure; |
| 1287 | } else { |
| 1288 | ASSERT_TRUE(read_failure); |
| 1289 | data1_reads[2] = *read_failure; |
| 1290 | } |
| 1291 | |
| 1292 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1293 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1294 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1295 | |
| 1296 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1297 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1298 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1299 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1301 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1302 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | |
| 1304 | const char* kExpectedResponseData[] = { |
| 1305 | "hello", "world" |
| 1306 | }; |
| 1307 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1308 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1310 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1312 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1313 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1315 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1316 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | |
| 1318 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1319 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1321 | LoadTimingInfo load_timing_info; |
| 1322 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1323 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1324 | if (i == 0) { |
| 1325 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1326 | } else { |
| 1327 | // The second request should be using a new socket. |
| 1328 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1329 | } |
| 1330 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1331 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1332 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1334 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1335 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | |
| 1337 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1338 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1339 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1340 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | } |
| 1342 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1343 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1344 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1345 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1346 | const MockRead* read_failure, |
| 1347 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1348 | HttpRequestInfo request; |
| 1349 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1350 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1351 | request.load_flags = 0; |
| 1352 | |
| 1353 | CapturingNetLog net_log; |
| 1354 | session_deps_.net_log = &net_log; |
| 1355 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1356 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1357 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1358 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1359 | if (use_spdy) { |
| 1360 | ssl1.SetNextProto(GetParam()); |
| 1361 | ssl2.SetNextProto(GetParam()); |
| 1362 | } |
| 1363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1365 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1366 | // SPDY versions of the request and response. |
| 1367 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1368 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1369 | scoped_ptr<SpdyFrame> spdy_response( |
| 1370 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1371 | scoped_ptr<SpdyFrame> spdy_data( |
| 1372 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1373 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1374 | // HTTP/1.1 versions of the request and response. |
| 1375 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1376 | "Host: www.foo.com\r\n" |
| 1377 | "Connection: keep-alive\r\n\r\n"; |
| 1378 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1379 | const char kHttpData[] = "hello"; |
| 1380 | |
| 1381 | std::vector<MockRead> data1_reads; |
| 1382 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1383 | if (write_failure) { |
| 1384 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1385 | data1_writes.push_back(*write_failure); |
| 1386 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1387 | } else { |
| 1388 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1389 | if (use_spdy) { |
| 1390 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1391 | } else { |
| 1392 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1393 | } |
| 1394 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1395 | } |
| 1396 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1397 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1398 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1399 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1400 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1401 | std::vector<MockRead> data2_reads; |
| 1402 | std::vector<MockWrite> data2_writes; |
| 1403 | |
| 1404 | if (use_spdy) { |
| 1405 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1406 | |
| 1407 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1408 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1409 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1410 | } else { |
| 1411 | data2_writes.push_back( |
| 1412 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1413 | |
| 1414 | data2_reads.push_back( |
| 1415 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1416 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1417 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1418 | } |
| 1419 | OrderedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1420 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1421 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1422 | |
| 1423 | // Preconnect a socket. |
| 1424 | net::SSLConfig ssl_config; |
| 1425 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1426 | session->GetNextProtos(&ssl_config.next_protos); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1427 | session->http_stream_factory()->PreconnectStreams( |
| 1428 | 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config); |
| 1429 | // Wait for the preconnect to complete. |
| 1430 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1431 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1432 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1433 | |
| 1434 | // Make the request. |
| 1435 | TestCompletionCallback callback; |
| 1436 | |
| 1437 | scoped_ptr<HttpTransaction> trans( |
| 1438 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1439 | |
| 1440 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1442 | |
| 1443 | rv = callback.WaitForResult(); |
| 1444 | EXPECT_EQ(OK, rv); |
| 1445 | |
| 1446 | LoadTimingInfo load_timing_info; |
| 1447 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1448 | TestLoadTimingNotReused( |
| 1449 | load_timing_info, |
| 1450 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1451 | |
| 1452 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1453 | ASSERT_TRUE(response != NULL); |
| 1454 | |
| 1455 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1456 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1457 | |
| 1458 | std::string response_data; |
| 1459 | rv = ReadTransaction(trans.get(), &response_data); |
| 1460 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1461 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1462 | } |
| 1463 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1464 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1465 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1466 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1467 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1468 | } |
| 1469 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1470 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1471 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1472 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1473 | } |
| 1474 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1475 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1476 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1477 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1478 | } |
| 1479 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1480 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1481 | // if the socket was a reused keep alive socket. |
| 1482 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1483 | MockRead read_failure(SYNCHRONOUS, |
| 1484 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1485 | "Connection: Keep-Alive\r\n" |
| 1486 | "Content-Length: 6\r\n\r\n" |
| 1487 | "Pickle"); |
| 1488 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1489 | } |
| 1490 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1491 | TEST_P(HttpNetworkTransactionTest, |
| 1492 | PreconnectErrorNotConnectedOnWrite) { |
| 1493 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1494 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1498 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1499 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1503 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1504 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1505 | } |
| 1506 | |
| 1507 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1508 | MockRead read_failure(ASYNC, OK); // EOF |
| 1509 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1510 | } |
| 1511 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1512 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1513 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1514 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1515 | MockRead read_failure(SYNCHRONOUS, |
| 1516 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1517 | "Connection: Keep-Alive\r\n" |
| 1518 | "Content-Length: 6\r\n\r\n" |
| 1519 | "Pickle"); |
| 1520 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1521 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1522 | } |
| 1523 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1524 | TEST_P(HttpNetworkTransactionTest, |
| 1525 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1526 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1527 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1528 | } |
| 1529 | |
| 1530 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1531 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1532 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1533 | } |
| 1534 | |
| 1535 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1536 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1537 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1538 | } |
| 1539 | |
| 1540 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1541 | MockRead read_failure(ASYNC, OK); // EOF |
| 1542 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1543 | } |
| 1544 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1545 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1546 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1547 | request.method = "GET"; |
| 1548 | request.url = GURL("http://www.google.com/"); |
| 1549 | request.load_flags = 0; |
| 1550 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1551 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1552 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1553 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1554 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1555 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1556 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1557 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1558 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1559 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1560 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1561 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1562 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1564 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1566 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1568 | |
| 1569 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1570 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1571 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1572 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1573 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | // What do various browsers do when the server closes a non-keepalive |
| 1577 | // connection without sending any response header or body? |
| 1578 | // |
| 1579 | // IE7: error page |
| 1580 | // Safari 3.1.2 (Windows): error page |
| 1581 | // Firefox 3.0.1: blank page |
| 1582 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1583 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1584 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1585 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1586 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1587 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1588 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1589 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1590 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1591 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1592 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1593 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1594 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1595 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1596 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1597 | // Test that network access can be deferred and resumed. |
| 1598 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1599 | HttpRequestInfo request; |
| 1600 | request.method = "GET"; |
| 1601 | request.url = GURL("http://www.google.com/"); |
| 1602 | request.load_flags = 0; |
| 1603 | |
| 1604 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1605 | scoped_ptr<HttpTransaction> trans( |
| 1606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1607 | |
| 1608 | // Defer on OnBeforeNetworkStart. |
| 1609 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1610 | trans->SetBeforeNetworkStartCallback( |
| 1611 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1612 | base::Unretained(&net_start_handler))); |
| 1613 | |
| 1614 | MockRead data_reads[] = { |
| 1615 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1616 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1617 | MockRead("hello"), |
| 1618 | MockRead(SYNCHRONOUS, 0), |
| 1619 | }; |
| 1620 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1622 | |
| 1623 | TestCompletionCallback callback; |
| 1624 | |
| 1625 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1626 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1627 | base::MessageLoop::current()->RunUntilIdle(); |
| 1628 | |
| 1629 | // Should have deferred for network start. |
| 1630 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1631 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1632 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1633 | |
| 1634 | trans->ResumeNetworkStart(); |
| 1635 | rv = callback.WaitForResult(); |
| 1636 | EXPECT_EQ(OK, rv); |
| 1637 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1638 | |
| 1639 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1640 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1641 | if (rv == ERR_IO_PENDING) |
| 1642 | rv = callback.WaitForResult(); |
| 1643 | EXPECT_EQ(5, rv); |
| 1644 | trans.reset(); |
| 1645 | } |
| 1646 | |
| 1647 | // Test that network use can be deferred and canceled. |
| 1648 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1649 | HttpRequestInfo request; |
| 1650 | request.method = "GET"; |
| 1651 | request.url = GURL("http://www.google.com/"); |
| 1652 | request.load_flags = 0; |
| 1653 | |
| 1654 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1655 | scoped_ptr<HttpTransaction> trans( |
| 1656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1657 | |
| 1658 | // Defer on OnBeforeNetworkStart. |
| 1659 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1660 | trans->SetBeforeNetworkStartCallback( |
| 1661 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1662 | base::Unretained(&net_start_handler))); |
| 1663 | |
| 1664 | TestCompletionCallback callback; |
| 1665 | |
| 1666 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1667 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1668 | base::MessageLoop::current()->RunUntilIdle(); |
| 1669 | |
| 1670 | // Should have deferred for network start. |
| 1671 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1672 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1673 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1674 | } |
| 1675 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1676 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1677 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1678 | // destructor in such situations. |
| 1679 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1680 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1681 | HttpRequestInfo request; |
| 1682 | request.method = "GET"; |
| 1683 | request.url = GURL("http://www.google.com/"); |
| 1684 | request.load_flags = 0; |
| 1685 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1686 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1687 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1688 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1689 | |
| 1690 | MockRead data_reads[] = { |
| 1691 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1692 | MockRead("Connection: keep-alive\r\n"), |
| 1693 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1694 | MockRead("hello"), |
| 1695 | MockRead(SYNCHRONOUS, 0), |
| 1696 | }; |
| 1697 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1698 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1699 | |
| 1700 | TestCompletionCallback callback; |
| 1701 | |
| 1702 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1704 | |
| 1705 | rv = callback.WaitForResult(); |
| 1706 | EXPECT_EQ(OK, rv); |
| 1707 | |
| 1708 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1709 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1710 | if (rv == ERR_IO_PENDING) |
| 1711 | rv = callback.WaitForResult(); |
| 1712 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1713 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1714 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1715 | |
| 1716 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1717 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1718 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1719 | } |
| 1720 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1721 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1722 | HttpRequestInfo request; |
| 1723 | request.method = "GET"; |
| 1724 | request.url = GURL("http://www.google.com/"); |
| 1725 | request.load_flags = 0; |
| 1726 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1727 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1730 | |
| 1731 | MockRead data_reads[] = { |
| 1732 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1733 | MockRead("Connection: keep-alive\r\n"), |
| 1734 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1735 | MockRead(SYNCHRONOUS, 0), |
| 1736 | }; |
| 1737 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1739 | |
| 1740 | TestCompletionCallback callback; |
| 1741 | |
| 1742 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1744 | |
| 1745 | rv = callback.WaitForResult(); |
| 1746 | EXPECT_EQ(OK, rv); |
| 1747 | |
| 1748 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1749 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1750 | if (rv == ERR_IO_PENDING) |
| 1751 | rv = callback.WaitForResult(); |
| 1752 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1753 | |
| 1754 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1755 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1756 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1757 | } |
| 1758 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1759 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1760 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1761 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1762 | HttpRequestInfo request; |
| 1763 | request.method = "GET"; |
| 1764 | request.url = GURL("http://www.foo.com/"); |
| 1765 | request.load_flags = 0; |
| 1766 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1767 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1768 | session_deps_.net_log = &net_log; |
| 1769 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1770 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1771 | // Note that because all these reads happen in the same |
| 1772 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1773 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1774 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1775 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1776 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1777 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1778 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1779 | "Content-Length: 0\r\n\r\n"), |
| 1780 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1781 | "Content-Length: 5\r\n\r\n" |
| 1782 | "hello"), |
| 1783 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1784 | "Content-Length: 0\r\n\r\n"), |
| 1785 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1786 | "Content-Length: 5\r\n\r\n" |
| 1787 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1788 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1789 | MockRead("hello"), |
| 1790 | }; |
| 1791 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1792 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1793 | |
| 1794 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1795 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1796 | }; |
| 1797 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1798 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1799 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1800 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1801 | std::string response_lines[kNumUnreadBodies]; |
| 1802 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1803 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1804 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1805 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1806 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1807 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1808 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1810 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1811 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1812 | |
| 1813 | rv = callback.WaitForResult(); |
| 1814 | EXPECT_EQ(OK, rv); |
| 1815 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1816 | LoadTimingInfo load_timing_info; |
| 1817 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1818 | if (i == 0) { |
| 1819 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1820 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1821 | } else { |
| 1822 | TestLoadTimingReused(load_timing_info); |
| 1823 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1824 | } |
| 1825 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1826 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1827 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1828 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1829 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1830 | response_lines[i] = response->headers->GetStatusLine(); |
| 1831 | |
| 1832 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1833 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1834 | |
| 1835 | const char* const kStatusLines[] = { |
| 1836 | "HTTP/1.1 204 No Content", |
| 1837 | "HTTP/1.1 205 Reset Content", |
| 1838 | "HTTP/1.1 304 Not Modified", |
| 1839 | "HTTP/1.1 302 Found", |
| 1840 | "HTTP/1.1 302 Found", |
| 1841 | "HTTP/1.1 301 Moved Permanently", |
| 1842 | "HTTP/1.1 301 Moved Permanently", |
| 1843 | }; |
| 1844 | |
| 1845 | COMPILE_ASSERT(kNumUnreadBodies == arraysize(kStatusLines), |
| 1846 | forgot_to_update_kStatusLines); |
| 1847 | |
| 1848 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1849 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1851 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1852 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1853 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1854 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1856 | rv = callback.WaitForResult(); |
| 1857 | EXPECT_EQ(OK, rv); |
| 1858 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1859 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1860 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1861 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1862 | std::string response_data; |
| 1863 | rv = ReadTransaction(trans.get(), &response_data); |
| 1864 | EXPECT_EQ(OK, rv); |
| 1865 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1866 | } |
| 1867 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1868 | // Test the request-challenge-retry sequence for basic auth. |
| 1869 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1870 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1871 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1872 | request.method = "GET"; |
| 1873 | request.url = GURL("http://www.google.com/"); |
| 1874 | request.load_flags = 0; |
| 1875 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1876 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1877 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1878 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1879 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1881 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1882 | MockWrite data_writes1[] = { |
| 1883 | MockWrite("GET / HTTP/1.1\r\n" |
| 1884 | "Host: www.google.com\r\n" |
| 1885 | "Connection: keep-alive\r\n\r\n"), |
| 1886 | }; |
| 1887 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1888 | MockRead data_reads1[] = { |
| 1889 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1890 | // Give a couple authenticate options (only the middle one is actually |
| 1891 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1892 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1893 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1894 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1895 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1896 | // Large content-length -- won't matter, as connection will be reset. |
| 1897 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1898 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1899 | }; |
| 1900 | |
| 1901 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1902 | // be issuing -- the final header line contains the credentials. |
| 1903 | MockWrite data_writes2[] = { |
| 1904 | MockWrite("GET / HTTP/1.1\r\n" |
| 1905 | "Host: www.google.com\r\n" |
| 1906 | "Connection: keep-alive\r\n" |
| 1907 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1908 | }; |
| 1909 | |
| 1910 | // Lastly, the server responds with the actual content. |
| 1911 | MockRead data_reads2[] = { |
| 1912 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1913 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1914 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1916 | }; |
| 1917 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1918 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1919 | data_writes1, arraysize(data_writes1)); |
| 1920 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1921 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1922 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1923 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1925 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1927 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1928 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1929 | |
| 1930 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1931 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1932 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1933 | LoadTimingInfo load_timing_info1; |
| 1934 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1935 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1936 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1937 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1938 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1939 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1941 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1942 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1943 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1944 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1946 | rv = trans->RestartWithAuth( |
| 1947 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1948 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1949 | |
| 1950 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1951 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1952 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1953 | LoadTimingInfo load_timing_info2; |
| 1954 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1955 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1956 | // The load timing after restart should have a new socket ID, and times after |
| 1957 | // those of the first load timing. |
| 1958 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1959 | load_timing_info2.connect_timing.connect_start); |
| 1960 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1961 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1962 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1963 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1964 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1965 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1966 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1967 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1968 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1969 | } |
| 1970 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1971 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1972 | HttpRequestInfo request; |
| 1973 | request.method = "GET"; |
| 1974 | request.url = GURL("http://www.google.com/"); |
| 1975 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1976 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1977 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1978 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1979 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1980 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1981 | MockWrite data_writes[] = { |
| 1982 | MockWrite("GET / HTTP/1.1\r\n" |
| 1983 | "Host: www.google.com\r\n" |
| 1984 | "Connection: keep-alive\r\n\r\n"), |
| 1985 | }; |
| 1986 | |
| 1987 | MockRead data_reads[] = { |
| 1988 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1989 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1990 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1991 | // Large content-length -- won't matter, as connection will be reset. |
| 1992 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1993 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1994 | }; |
| 1995 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1996 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 1997 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1999 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2001 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2002 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2003 | |
| 2004 | rv = callback.WaitForResult(); |
| 2005 | EXPECT_EQ(0, rv); |
| 2006 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2007 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2008 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2009 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2010 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2011 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2012 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2013 | } |
| 2014 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2015 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2016 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2017 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2018 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2019 | request.method = "GET"; |
| 2020 | request.url = GURL("http://www.google.com/"); |
| 2021 | request.load_flags = 0; |
| 2022 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2023 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2024 | session_deps_.net_log = &log; |
| 2025 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2026 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2027 | MockWrite data_writes1[] = { |
| 2028 | MockWrite("GET / HTTP/1.1\r\n" |
| 2029 | "Host: www.google.com\r\n" |
| 2030 | "Connection: keep-alive\r\n\r\n"), |
| 2031 | |
| 2032 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2033 | // be issuing -- the final header line contains the credentials. |
| 2034 | MockWrite("GET / HTTP/1.1\r\n" |
| 2035 | "Host: www.google.com\r\n" |
| 2036 | "Connection: keep-alive\r\n" |
| 2037 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2038 | }; |
| 2039 | |
| 2040 | MockRead data_reads1[] = { |
| 2041 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2042 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2043 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2044 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2045 | MockRead("Unauthorized\r\n"), |
| 2046 | |
| 2047 | // Lastly, the server responds with the actual content. |
| 2048 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2049 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2050 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2051 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2052 | }; |
| 2053 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2054 | // If there is a regression where we disconnect a Keep-Alive |
| 2055 | // connection during an auth roundtrip, we'll end up reading this. |
| 2056 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2057 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2058 | }; |
| 2059 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2060 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2061 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2062 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2063 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2064 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2065 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2067 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2068 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2069 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2070 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2071 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2072 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2073 | |
| 2074 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2075 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2076 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2077 | LoadTimingInfo load_timing_info1; |
| 2078 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2079 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2080 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2081 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2082 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2083 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2085 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2087 | rv = trans->RestartWithAuth( |
| 2088 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2090 | |
| 2091 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2092 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2093 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2094 | LoadTimingInfo load_timing_info2; |
| 2095 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2096 | TestLoadTimingReused(load_timing_info2); |
| 2097 | // The load timing after restart should have the same socket ID, and times |
| 2098 | // those of the first load timing. |
| 2099 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2100 | load_timing_info2.send_start); |
| 2101 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2102 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2103 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2104 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2105 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2106 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2107 | |
| 2108 | std::string response_data; |
| 2109 | rv = ReadTransaction(trans.get(), &response_data); |
| 2110 | EXPECT_EQ(OK, rv); |
| 2111 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2112 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2116 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2117 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2118 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2119 | request.method = "GET"; |
| 2120 | request.url = GURL("http://www.google.com/"); |
| 2121 | request.load_flags = 0; |
| 2122 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2123 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2124 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2125 | MockWrite data_writes1[] = { |
| 2126 | MockWrite("GET / HTTP/1.1\r\n" |
| 2127 | "Host: www.google.com\r\n" |
| 2128 | "Connection: keep-alive\r\n\r\n"), |
| 2129 | |
| 2130 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2131 | // be issuing -- the final header line contains the credentials. |
| 2132 | MockWrite("GET / HTTP/1.1\r\n" |
| 2133 | "Host: www.google.com\r\n" |
| 2134 | "Connection: keep-alive\r\n" |
| 2135 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2136 | }; |
| 2137 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2138 | MockRead data_reads1[] = { |
| 2139 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2140 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2141 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2142 | |
| 2143 | // Lastly, the server responds with the actual content. |
| 2144 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2145 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2146 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2147 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2148 | }; |
| 2149 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2150 | // An incorrect reconnect would cause this to be read. |
| 2151 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2152 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2153 | }; |
| 2154 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2155 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2156 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2157 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2158 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2159 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2160 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2162 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2163 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2164 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2165 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2166 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2167 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2168 | |
| 2169 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2170 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2171 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2172 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2173 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2174 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2176 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2178 | rv = trans->RestartWithAuth( |
| 2179 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2180 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2181 | |
| 2182 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2183 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2184 | |
| 2185 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2186 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2188 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2192 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2193 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2194 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2195 | request.method = "GET"; |
| 2196 | request.url = GURL("http://www.google.com/"); |
| 2197 | request.load_flags = 0; |
| 2198 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2199 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2200 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2201 | MockWrite data_writes1[] = { |
| 2202 | MockWrite("GET / HTTP/1.1\r\n" |
| 2203 | "Host: www.google.com\r\n" |
| 2204 | "Connection: keep-alive\r\n\r\n"), |
| 2205 | |
| 2206 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2207 | // be issuing -- the final header line contains the credentials. |
| 2208 | MockWrite("GET / HTTP/1.1\r\n" |
| 2209 | "Host: www.google.com\r\n" |
| 2210 | "Connection: keep-alive\r\n" |
| 2211 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2212 | }; |
| 2213 | |
| 2214 | // Respond with 5 kb of response body. |
| 2215 | std::string large_body_string("Unauthorized"); |
| 2216 | large_body_string.append(5 * 1024, ' '); |
| 2217 | large_body_string.append("\r\n"); |
| 2218 | |
| 2219 | MockRead data_reads1[] = { |
| 2220 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2221 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2222 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2223 | // 5134 = 12 + 5 * 1024 + 2 |
| 2224 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2225 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2226 | |
| 2227 | // Lastly, the server responds with the actual content. |
| 2228 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2229 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2230 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2231 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2232 | }; |
| 2233 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2234 | // An incorrect reconnect would cause this to be read. |
| 2235 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2236 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2237 | }; |
| 2238 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2239 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2240 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2241 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2242 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2243 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2244 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2246 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2247 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2248 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2250 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2251 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2252 | |
| 2253 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2254 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2255 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2256 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2257 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2258 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2260 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2262 | rv = trans->RestartWithAuth( |
| 2263 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2264 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2265 | |
| 2266 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2267 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2268 | |
| 2269 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2270 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2271 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2272 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2276 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2277 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2278 | HttpRequestInfo request; |
| 2279 | request.method = "GET"; |
| 2280 | request.url = GURL("http://www.google.com/"); |
| 2281 | request.load_flags = 0; |
| 2282 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2283 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2284 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2285 | MockWrite data_writes1[] = { |
| 2286 | MockWrite("GET / HTTP/1.1\r\n" |
| 2287 | "Host: www.google.com\r\n" |
| 2288 | "Connection: keep-alive\r\n\r\n"), |
| 2289 | // This simulates the seemingly successful write to a closed connection |
| 2290 | // if the bug is not fixed. |
| 2291 | MockWrite("GET / HTTP/1.1\r\n" |
| 2292 | "Host: www.google.com\r\n" |
| 2293 | "Connection: keep-alive\r\n" |
| 2294 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2295 | }; |
| 2296 | |
| 2297 | MockRead data_reads1[] = { |
| 2298 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2299 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2300 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2301 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2302 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2303 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2304 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2305 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2306 | }; |
| 2307 | |
| 2308 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2309 | // be issuing -- the final header line contains the credentials. |
| 2310 | MockWrite data_writes2[] = { |
| 2311 | MockWrite("GET / HTTP/1.1\r\n" |
| 2312 | "Host: www.google.com\r\n" |
| 2313 | "Connection: keep-alive\r\n" |
| 2314 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2315 | }; |
| 2316 | |
| 2317 | // Lastly, the server responds with the actual content. |
| 2318 | MockRead data_reads2[] = { |
| 2319 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2320 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2321 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2322 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2323 | }; |
| 2324 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2326 | data_writes1, arraysize(data_writes1)); |
| 2327 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2328 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2330 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2332 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2333 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2334 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2336 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2337 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2338 | |
| 2339 | rv = callback1.WaitForResult(); |
| 2340 | EXPECT_EQ(OK, rv); |
| 2341 | |
| 2342 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2343 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2344 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2346 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2348 | rv = trans->RestartWithAuth( |
| 2349 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2351 | |
| 2352 | rv = callback2.WaitForResult(); |
| 2353 | EXPECT_EQ(OK, rv); |
| 2354 | |
| 2355 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2356 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2357 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2358 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2359 | } |
| 2360 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2361 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2362 | // that requires a restart when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2363 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2364 | HttpRequestInfo request; |
| 2365 | request.method = "GET"; |
| 2366 | request.url = GURL("https://www.google.com/"); |
| 2367 | // when the no authentication data flag is set. |
| 2368 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2369 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2370 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2371 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2372 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2373 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2374 | session_deps_.net_log = log.bound().net_log(); |
| 2375 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2376 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2377 | // Since we have proxy, should try to establish tunnel. |
| 2378 | MockWrite data_writes1[] = { |
| 2379 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2380 | "Host: www.google.com\r\n" |
| 2381 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2382 | |
| 2383 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2384 | // be issuing -- the final header line contains the credentials. |
| 2385 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2386 | "Host: www.google.com\r\n" |
| 2387 | "Proxy-Connection: keep-alive\r\n" |
| 2388 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2389 | |
| 2390 | MockWrite("GET / HTTP/1.1\r\n" |
| 2391 | "Host: www.google.com\r\n" |
| 2392 | "Connection: keep-alive\r\n\r\n"), |
| 2393 | }; |
| 2394 | |
| 2395 | // The proxy responds to the connect with a 407, using a persistent |
| 2396 | // connection. |
| 2397 | MockRead data_reads1[] = { |
| 2398 | // No credentials. |
| 2399 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2400 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2401 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2402 | |
| 2403 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2404 | |
| 2405 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2406 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2407 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2408 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2409 | }; |
| 2410 | |
| 2411 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2412 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2413 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2414 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2417 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2418 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2419 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2422 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2423 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2424 | |
| 2425 | rv = callback1.WaitForResult(); |
| 2426 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2427 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2428 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2429 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2430 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2431 | NetLog::PHASE_NONE); |
| 2432 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2433 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2434 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2435 | NetLog::PHASE_NONE); |
| 2436 | |
| 2437 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2438 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2439 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2440 | EXPECT_EQ(407, response->headers->response_code()); |
| 2441 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2442 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2443 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2444 | LoadTimingInfo load_timing_info; |
| 2445 | // CONNECT requests and responses are handled at the connect job level, so |
| 2446 | // the transaction does not yet have a connection. |
| 2447 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2449 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2451 | rv = trans->RestartWithAuth( |
| 2452 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2453 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2454 | |
| 2455 | rv = callback2.WaitForResult(); |
| 2456 | EXPECT_EQ(OK, rv); |
| 2457 | |
| 2458 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2459 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2460 | |
| 2461 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2462 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2463 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2464 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2465 | |
| 2466 | // The password prompt info should not be set. |
| 2467 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2468 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2469 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2470 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2471 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2472 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2473 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2474 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2475 | } |
| 2476 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2477 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2478 | // proxy connection, when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2479 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2480 | HttpRequestInfo request; |
| 2481 | request.method = "GET"; |
| 2482 | request.url = GURL("https://www.google.com/"); |
| 2483 | // Ensure that proxy authentication is attempted even |
| 2484 | // when the no authentication data flag is set. |
| 2485 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2486 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2487 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2488 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2489 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2490 | session_deps_.net_log = log.bound().net_log(); |
| 2491 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2492 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2493 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2494 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2495 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2496 | // Since we have proxy, should try to establish tunnel. |
| 2497 | MockWrite data_writes1[] = { |
| 2498 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2499 | "Host: www.google.com\r\n" |
| 2500 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2501 | |
| 2502 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2503 | // be issuing -- the final header line contains the credentials. |
| 2504 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2505 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2506 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2507 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2508 | }; |
| 2509 | |
| 2510 | // The proxy responds to the connect with a 407, using a persistent |
| 2511 | // connection. |
| 2512 | MockRead data_reads1[] = { |
| 2513 | // No credentials. |
| 2514 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2515 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2516 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2517 | MockRead("0123456789"), |
| 2518 | |
| 2519 | // Wrong credentials (wrong password). |
| 2520 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2521 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2522 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2523 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2524 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2525 | }; |
| 2526 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2527 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2528 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2529 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2531 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2533 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2534 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2535 | |
| 2536 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2537 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2538 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2539 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2540 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2541 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2542 | NetLog::PHASE_NONE); |
| 2543 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2544 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2545 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2546 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2547 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2548 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2549 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2550 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2551 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2552 | EXPECT_EQ(407, response->headers->response_code()); |
| 2553 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2554 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2555 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2557 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2558 | |
| 2559 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2560 | rv = trans->RestartWithAuth( |
| 2561 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2562 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2563 | |
| 2564 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2565 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2566 | |
| 2567 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2568 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2569 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2570 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2571 | EXPECT_EQ(407, response->headers->response_code()); |
| 2572 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2573 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2574 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2575 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2576 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2577 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2578 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2579 | } |
| 2580 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2581 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2582 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2583 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2584 | HttpRequestInfo request; |
| 2585 | request.method = "GET"; |
| 2586 | request.url = GURL("https://www.google.com/"); |
| 2587 | request.load_flags = 0; |
| 2588 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2589 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2590 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2591 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2592 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2593 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2594 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2596 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2597 | // Since we have proxy, should try to establish tunnel. |
| 2598 | MockWrite data_writes[] = { |
| 2599 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2600 | "Host: www.google.com\r\n" |
| 2601 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2602 | }; |
| 2603 | |
| 2604 | // The proxy responds to the connect with a 407. |
| 2605 | MockRead data_reads[] = { |
| 2606 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2607 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2608 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2609 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2610 | }; |
| 2611 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2612 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2613 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2614 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2616 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2618 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2619 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2620 | |
| 2621 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2622 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2623 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2624 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2625 | ASSERT_TRUE(response != NULL); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2626 | |
| 2627 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2628 | EXPECT_EQ(407, response->headers->response_code()); |
| 2629 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2630 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2631 | |
| 2632 | std::string response_data; |
| 2633 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2634 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2635 | |
| 2636 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2637 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2638 | } |
| 2639 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2640 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2641 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2642 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2643 | HttpRequestInfo request; |
| 2644 | request.method = "GET"; |
| 2645 | request.url = GURL("http://www.google.com/"); |
| 2646 | request.load_flags = 0; |
| 2647 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2648 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2649 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2650 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2651 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2652 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2653 | MockWrite data_writes1[] = { |
| 2654 | MockWrite("GET / HTTP/1.1\r\n" |
| 2655 | "Host: www.google.com\r\n" |
| 2656 | "Connection: keep-alive\r\n\r\n"), |
| 2657 | }; |
| 2658 | |
| 2659 | MockRead data_reads1[] = { |
| 2660 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2661 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2662 | // Large content-length -- won't matter, as connection will be reset. |
| 2663 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2664 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2665 | }; |
| 2666 | |
| 2667 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2668 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2669 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2671 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2673 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2675 | |
| 2676 | rv = callback.WaitForResult(); |
| 2677 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2678 | } |
| 2679 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2680 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2681 | // through a non-authenticating proxy. The request should fail with |
| 2682 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2683 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2684 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2685 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2686 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2687 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2688 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2689 | HttpRequestInfo request; |
| 2690 | request.method = "GET"; |
| 2691 | request.url = GURL("https://www.google.com/"); |
| 2692 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2693 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2694 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2695 | session_deps_.net_log = log.bound().net_log(); |
| 2696 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2697 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2698 | // Since we have proxy, should try to establish tunnel. |
| 2699 | MockWrite data_writes1[] = { |
| 2700 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2701 | "Host: www.google.com\r\n" |
| 2702 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2703 | |
| 2704 | MockWrite("GET / HTTP/1.1\r\n" |
| 2705 | "Host: www.google.com\r\n" |
| 2706 | "Connection: keep-alive\r\n\r\n"), |
| 2707 | }; |
| 2708 | |
| 2709 | MockRead data_reads1[] = { |
| 2710 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2711 | |
| 2712 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 2713 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2714 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2716 | }; |
| 2717 | |
| 2718 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2719 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2720 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2721 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2722 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2724 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2725 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2726 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2727 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2729 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2730 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2731 | |
| 2732 | rv = callback1.WaitForResult(); |
| 2733 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2734 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2735 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2736 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2737 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2738 | NetLog::PHASE_NONE); |
| 2739 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2740 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2741 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2742 | NetLog::PHASE_NONE); |
| 2743 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2744 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2745 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2746 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2747 | HttpRequestInfo request1; |
| 2748 | request1.method = "GET"; |
| 2749 | request1.url = GURL("https://www.google.com/1"); |
| 2750 | |
| 2751 | HttpRequestInfo request2; |
| 2752 | request2.method = "GET"; |
| 2753 | request2.url = GURL("https://www.google.com/2"); |
| 2754 | |
| 2755 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2756 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2757 | ProxyService::CreateFixed("PROXY myproxy:70")); |
| 2758 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2759 | session_deps_.net_log = log.bound().net_log(); |
| 2760 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2761 | |
| 2762 | // Since we have proxy, should try to establish tunnel. |
| 2763 | MockWrite data_writes1[] = { |
| 2764 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2765 | "Host: www.google.com\r\n" |
| 2766 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2767 | |
| 2768 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2769 | "Host: www.google.com\r\n" |
| 2770 | "Connection: keep-alive\r\n\r\n"), |
| 2771 | |
| 2772 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2773 | "Host: www.google.com\r\n" |
| 2774 | "Connection: keep-alive\r\n\r\n"), |
| 2775 | }; |
| 2776 | |
| 2777 | // The proxy responds to the connect with a 407, using a persistent |
| 2778 | // connection. |
| 2779 | MockRead data_reads1[] = { |
| 2780 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2781 | |
| 2782 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2783 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2784 | MockRead(SYNCHRONOUS, "1"), |
| 2785 | |
| 2786 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2787 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2788 | MockRead(SYNCHRONOUS, "22"), |
| 2789 | }; |
| 2790 | |
| 2791 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2792 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2793 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2794 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2795 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2796 | |
| 2797 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2798 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2799 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2800 | |
| 2801 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2803 | |
| 2804 | rv = callback1.WaitForResult(); |
| 2805 | EXPECT_EQ(OK, rv); |
| 2806 | |
| 2807 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2808 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2809 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2810 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2811 | |
| 2812 | LoadTimingInfo load_timing_info1; |
| 2813 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2814 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2815 | |
| 2816 | trans1.reset(); |
| 2817 | |
| 2818 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2819 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2820 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2821 | |
| 2822 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2824 | |
| 2825 | rv = callback2.WaitForResult(); |
| 2826 | EXPECT_EQ(OK, rv); |
| 2827 | |
| 2828 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2829 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2830 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2831 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2832 | |
| 2833 | LoadTimingInfo load_timing_info2; |
| 2834 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2835 | TestLoadTimingReused(load_timing_info2); |
| 2836 | |
| 2837 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2838 | |
| 2839 | trans2.reset(); |
| 2840 | session->CloseAllConnections(); |
| 2841 | } |
| 2842 | |
| 2843 | // 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] | 2844 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2845 | HttpRequestInfo request1; |
| 2846 | request1.method = "GET"; |
| 2847 | request1.url = GURL("https://www.google.com/1"); |
| 2848 | |
| 2849 | HttpRequestInfo request2; |
| 2850 | request2.method = "GET"; |
| 2851 | request2.url = GURL("https://www.google.com/2"); |
| 2852 | |
| 2853 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2854 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2855 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 2856 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2857 | session_deps_.net_log = log.bound().net_log(); |
| 2858 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2859 | |
| 2860 | // Since we have proxy, should try to establish tunnel. |
| 2861 | MockWrite data_writes1[] = { |
| 2862 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2863 | "Host: www.google.com\r\n" |
| 2864 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2865 | |
| 2866 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2867 | "Host: www.google.com\r\n" |
| 2868 | "Connection: keep-alive\r\n\r\n"), |
| 2869 | |
| 2870 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2871 | "Host: www.google.com\r\n" |
| 2872 | "Connection: keep-alive\r\n\r\n"), |
| 2873 | }; |
| 2874 | |
| 2875 | // The proxy responds to the connect with a 407, using a persistent |
| 2876 | // connection. |
| 2877 | MockRead data_reads1[] = { |
| 2878 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2879 | |
| 2880 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2881 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2882 | MockRead(SYNCHRONOUS, "1"), |
| 2883 | |
| 2884 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2885 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2886 | MockRead(SYNCHRONOUS, "22"), |
| 2887 | }; |
| 2888 | |
| 2889 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2890 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2891 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2892 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2894 | |
| 2895 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2896 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2898 | |
| 2899 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2901 | |
| 2902 | rv = callback1.WaitForResult(); |
| 2903 | EXPECT_EQ(OK, rv); |
| 2904 | |
| 2905 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2906 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2907 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2908 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2909 | |
| 2910 | LoadTimingInfo load_timing_info1; |
| 2911 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2912 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 2913 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2914 | |
| 2915 | trans1.reset(); |
| 2916 | |
| 2917 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2918 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2919 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2920 | |
| 2921 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2922 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2923 | |
| 2924 | rv = callback2.WaitForResult(); |
| 2925 | EXPECT_EQ(OK, rv); |
| 2926 | |
| 2927 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2928 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2929 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2930 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2931 | |
| 2932 | LoadTimingInfo load_timing_info2; |
| 2933 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2934 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 2935 | |
| 2936 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2937 | |
| 2938 | trans2.reset(); |
| 2939 | session->CloseAllConnections(); |
| 2940 | } |
| 2941 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2942 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2943 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2944 | HttpRequestInfo request; |
| 2945 | request.method = "GET"; |
| 2946 | request.url = GURL("http://www.google.com/"); |
| 2947 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2948 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2949 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 2950 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2951 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2952 | session_deps_.net_log = log.bound().net_log(); |
| 2953 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2954 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2955 | // Since we have proxy, should use full url |
| 2956 | MockWrite data_writes1[] = { |
| 2957 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 2958 | "Host: www.google.com\r\n" |
| 2959 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2960 | }; |
| 2961 | |
| 2962 | MockRead data_reads1[] = { |
| 2963 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2964 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2965 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2966 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2967 | }; |
| 2968 | |
| 2969 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2970 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2971 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2972 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2973 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2974 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2975 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2976 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2977 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2978 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2980 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2981 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2982 | |
| 2983 | rv = callback1.WaitForResult(); |
| 2984 | EXPECT_EQ(OK, rv); |
| 2985 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2986 | LoadTimingInfo load_timing_info; |
| 2987 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2988 | TestLoadTimingNotReused(load_timing_info, |
| 2989 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2990 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2991 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2992 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2993 | |
| 2994 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2995 | EXPECT_EQ(200, response->headers->response_code()); |
| 2996 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2997 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2998 | |
| 2999 | // The password prompt info should not be set. |
| 3000 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3001 | } |
| 3002 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3003 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3004 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3005 | HttpRequestInfo request; |
| 3006 | request.method = "GET"; |
| 3007 | request.url = GURL("http://www.google.com/"); |
| 3008 | request.load_flags = 0; |
| 3009 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3010 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3011 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3012 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3013 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3014 | session_deps_.net_log = log.bound().net_log(); |
| 3015 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3016 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3017 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3018 | scoped_ptr<SpdyFrame> req( |
| 3019 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3020 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 3021 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3022 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3023 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3024 | MockRead spdy_reads[] = { |
| 3025 | CreateMockRead(*resp), |
| 3026 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3027 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3028 | }; |
| 3029 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3030 | DelayedSocketData spdy_data( |
| 3031 | 1, // wait for one write to finish before reading. |
| 3032 | spdy_reads, arraysize(spdy_reads), |
| 3033 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3034 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3035 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3036 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3037 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3040 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3041 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3042 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3043 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3045 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3046 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3047 | |
| 3048 | rv = callback1.WaitForResult(); |
| 3049 | EXPECT_EQ(OK, rv); |
| 3050 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3051 | LoadTimingInfo load_timing_info; |
| 3052 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3053 | TestLoadTimingNotReused(load_timing_info, |
| 3054 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3055 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3056 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3057 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3058 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3059 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3060 | |
| 3061 | std::string response_data; |
| 3062 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3063 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3064 | } |
| 3065 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3066 | // Verifies that a session which races and wins against the owning transaction |
| 3067 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3068 | // Regression test for crbug.com/334413. |
| 3069 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3070 | HttpRequestInfo request; |
| 3071 | request.method = "GET"; |
| 3072 | request.url = GURL("http://www.google.com/"); |
| 3073 | request.load_flags = 0; |
| 3074 | |
| 3075 | // Configure SPDY proxy server "proxy:70". |
| 3076 | session_deps_.proxy_service.reset( |
| 3077 | ProxyService::CreateFixed("https://proxy:70")); |
| 3078 | CapturingBoundNetLog log; |
| 3079 | session_deps_.net_log = log.bound().net_log(); |
| 3080 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3081 | |
| 3082 | // Fetch http://www.google.com/ through the SPDY proxy. |
| 3083 | scoped_ptr<SpdyFrame> req( |
| 3084 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
| 3085 | MockWrite spdy_writes[] = {CreateMockWrite(*req)}; |
| 3086 | |
| 3087 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3088 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3089 | MockRead spdy_reads[] = { |
| 3090 | CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0), |
| 3091 | }; |
| 3092 | |
| 3093 | DelayedSocketData spdy_data( |
| 3094 | 1, // wait for one write to finish before reading. |
| 3095 | spdy_reads, |
| 3096 | arraysize(spdy_reads), |
| 3097 | spdy_writes, |
| 3098 | arraysize(spdy_writes)); |
| 3099 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3100 | |
| 3101 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3102 | ssl.SetNextProto(GetParam()); |
| 3103 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3104 | |
| 3105 | TestCompletionCallback callback1; |
| 3106 | |
| 3107 | scoped_ptr<HttpTransaction> trans( |
| 3108 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3109 | |
| 3110 | // Stall the hostname resolution begun by the transaction. |
| 3111 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3112 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3113 | |
| 3114 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3115 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3116 | |
| 3117 | // Race a session to the proxy, which completes first. |
| 3118 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3119 | SpdySessionKey key( |
| 3120 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3121 | base::WeakPtr<SpdySession> spdy_session = |
| 3122 | CreateSecureSpdySession(session, key, log.bound()); |
| 3123 | |
| 3124 | // Unstall the resolution begun by the transaction. |
| 3125 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3126 | session_deps_.host_resolver->ResolveAllPending(); |
| 3127 | |
| 3128 | EXPECT_FALSE(callback1.have_result()); |
| 3129 | rv = callback1.WaitForResult(); |
| 3130 | EXPECT_EQ(OK, rv); |
| 3131 | |
| 3132 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3133 | ASSERT_TRUE(response != NULL); |
| 3134 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3135 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3136 | |
| 3137 | std::string response_data; |
| 3138 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3139 | EXPECT_EQ(kUploadData, response_data); |
| 3140 | } |
| 3141 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3142 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3143 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3144 | HttpRequestInfo request; |
| 3145 | request.method = "GET"; |
| 3146 | request.url = GURL("http://www.google.com/"); |
| 3147 | request.load_flags = 0; |
| 3148 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3149 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3150 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3151 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3152 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3153 | session_deps_.net_log = log.bound().net_log(); |
| 3154 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3155 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3156 | // The first request will be a bare GET, the second request will be a |
| 3157 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3158 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3159 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3160 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3161 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3162 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3163 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3164 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3165 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3166 | false, |
| 3167 | 3, |
| 3168 | LOWEST, |
| 3169 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3170 | MockWrite spdy_writes[] = { |
| 3171 | CreateMockWrite(*req_get, 1), |
| 3172 | CreateMockWrite(*req_get_authorization, 4), |
| 3173 | }; |
| 3174 | |
| 3175 | // The first response is a 407 proxy authentication challenge, and the second |
| 3176 | // response will be a 200 response since the second request includes a valid |
| 3177 | // Authorization header. |
| 3178 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3179 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3180 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3181 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3182 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3183 | "407 Proxy Authentication Required", |
| 3184 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3185 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3186 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3187 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3188 | scoped_ptr<SpdyFrame> resp_data( |
| 3189 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3190 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3191 | MockRead spdy_reads[] = { |
| 3192 | CreateMockRead(*resp_authentication, 2), |
| 3193 | CreateMockRead(*body_authentication, 3), |
| 3194 | CreateMockRead(*resp_data, 5), |
| 3195 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3196 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3197 | }; |
| 3198 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3199 | OrderedSocketData data( |
| 3200 | spdy_reads, arraysize(spdy_reads), |
| 3201 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3202 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3203 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3204 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3205 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3208 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3209 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3210 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3211 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3213 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3214 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3215 | |
| 3216 | rv = callback1.WaitForResult(); |
| 3217 | EXPECT_EQ(OK, rv); |
| 3218 | |
| 3219 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3220 | |
| 3221 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3222 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3223 | EXPECT_EQ(407, response->headers->response_code()); |
| 3224 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3225 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3226 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3227 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3228 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3229 | rv = trans->RestartWithAuth( |
| 3230 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3232 | |
| 3233 | rv = callback2.WaitForResult(); |
| 3234 | EXPECT_EQ(OK, rv); |
| 3235 | |
| 3236 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3237 | |
| 3238 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3239 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3240 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3241 | // The password prompt info should not be set. |
| 3242 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3243 | } |
| 3244 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3245 | // 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] | 3246 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3247 | HttpRequestInfo request; |
| 3248 | request.method = "GET"; |
| 3249 | request.url = GURL("https://www.google.com/"); |
| 3250 | request.load_flags = 0; |
| 3251 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3252 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3253 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3254 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3255 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3256 | session_deps_.net_log = log.bound().net_log(); |
| 3257 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3258 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3259 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3261 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3262 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3263 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3264 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3265 | // fetch https://www.google.com/ via HTTP |
| 3266 | |
| 3267 | const char get[] = "GET / HTTP/1.1\r\n" |
| 3268 | "Host: www.google.com\r\n" |
| 3269 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3270 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3271 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3272 | scoped_ptr<SpdyFrame> conn_resp( |
| 3273 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3274 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3275 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3276 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3277 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3278 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3279 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3280 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3281 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3282 | |
| 3283 | MockWrite spdy_writes[] = { |
| 3284 | CreateMockWrite(*connect, 1), |
| 3285 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3286 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3287 | }; |
| 3288 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3289 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3290 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3291 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3292 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3293 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 3294 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3295 | }; |
| 3296 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3297 | OrderedSocketData spdy_data( |
| 3298 | spdy_reads, arraysize(spdy_reads), |
| 3299 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3300 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3301 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3302 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3303 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3304 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3305 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3306 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 3307 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3310 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3312 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3313 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3314 | |
| 3315 | rv = callback1.WaitForResult(); |
| 3316 | EXPECT_EQ(OK, rv); |
| 3317 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3318 | LoadTimingInfo load_timing_info; |
| 3319 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3320 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3321 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3322 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3323 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3324 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3325 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3326 | |
| 3327 | std::string response_data; |
| 3328 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3329 | EXPECT_EQ("1234567890", response_data); |
| 3330 | } |
| 3331 | |
| 3332 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3333 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3334 | HttpRequestInfo request; |
| 3335 | request.method = "GET"; |
| 3336 | request.url = GURL("https://www.google.com/"); |
| 3337 | request.load_flags = 0; |
| 3338 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3339 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3340 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3341 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3342 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3343 | session_deps_.net_log = log.bound().net_log(); |
| 3344 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3345 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3346 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3347 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3348 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3349 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3350 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3351 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3352 | // fetch https://www.google.com/ via SPDY |
| 3353 | const char* const kMyUrl = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3354 | scoped_ptr<SpdyFrame> get( |
| 3355 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3356 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3357 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3358 | scoped_ptr<SpdyFrame> conn_resp( |
| 3359 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3360 | scoped_ptr<SpdyFrame> get_resp( |
| 3361 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3362 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3363 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3364 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3365 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3366 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3367 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3368 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3369 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3370 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3371 | |
| 3372 | MockWrite spdy_writes[] = { |
| 3373 | CreateMockWrite(*connect, 1), |
| 3374 | CreateMockWrite(*wrapped_get, 3), |
| 3375 | CreateMockWrite(*window_update_get_resp, 5), |
| 3376 | CreateMockWrite(*window_update_body, 7), |
| 3377 | }; |
| 3378 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3379 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3380 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3381 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3382 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3383 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3384 | }; |
| 3385 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3386 | OrderedSocketData spdy_data( |
| 3387 | spdy_reads, arraysize(spdy_reads), |
| 3388 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3389 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3390 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3391 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3392 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3394 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3395 | ssl2.SetNextProto(GetParam()); |
| 3396 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3397 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3399 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3401 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3402 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3403 | |
| 3404 | rv = callback1.WaitForResult(); |
| 3405 | EXPECT_EQ(OK, rv); |
| 3406 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3407 | LoadTimingInfo load_timing_info; |
| 3408 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3409 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3410 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3411 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3412 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3413 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3414 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3415 | |
| 3416 | std::string response_data; |
| 3417 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3418 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3422 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3423 | HttpRequestInfo request; |
| 3424 | request.method = "GET"; |
| 3425 | request.url = GURL("https://www.google.com/"); |
| 3426 | request.load_flags = 0; |
| 3427 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3428 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3429 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3430 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3431 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3432 | session_deps_.net_log = log.bound().net_log(); |
| 3433 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3434 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3435 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3436 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3437 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3438 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3439 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3440 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3441 | scoped_ptr<SpdyFrame> get( |
| 3442 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3443 | |
| 3444 | MockWrite spdy_writes[] = { |
| 3445 | CreateMockWrite(*connect, 1), |
| 3446 | CreateMockWrite(*get, 3), |
| 3447 | }; |
| 3448 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3449 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3450 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3451 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3452 | CreateMockRead(*resp, 2, ASYNC), |
| 3453 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3454 | }; |
| 3455 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3456 | OrderedSocketData spdy_data( |
| 3457 | spdy_reads, arraysize(spdy_reads), |
| 3458 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3459 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3460 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3461 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3462 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3464 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3465 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3468 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3470 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3471 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3472 | |
| 3473 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3474 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3475 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3476 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3477 | } |
| 3478 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3479 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3480 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3481 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3482 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3483 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3484 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3485 | "https://proxy:70")); |
| 3486 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3487 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3488 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3489 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3490 | |
| 3491 | HttpRequestInfo request1; |
| 3492 | request1.method = "GET"; |
| 3493 | request1.url = GURL("https://www.google.com/"); |
| 3494 | request1.load_flags = 0; |
| 3495 | |
| 3496 | HttpRequestInfo request2; |
| 3497 | request2.method = "GET"; |
| 3498 | request2.url = GURL("https://news.google.com/"); |
| 3499 | request2.load_flags = 0; |
| 3500 | |
| 3501 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3502 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3503 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3504 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3505 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3506 | |
| 3507 | // Fetch https://www.google.com/ via HTTP. |
| 3508 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3509 | "Host: www.google.com\r\n" |
| 3510 | "Connection: keep-alive\r\n\r\n"; |
| 3511 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3512 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3513 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3514 | "Content-Length: 1\r\n\r\n"; |
| 3515 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3516 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3517 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3518 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3519 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3520 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3521 | |
| 3522 | // CONNECT to news.google.com:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3523 | SpdyHeaderBlock connect2_block; |
| 3524 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 3525 | connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443"; |
| 3526 | connect2_block[spdy_util_.GetHostKey()] = "news.google.com"; |
| 3527 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3528 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3529 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3530 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3531 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3532 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3533 | |
| 3534 | // Fetch https://news.google.com/ via HTTP. |
| 3535 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3536 | "Host: news.google.com\r\n" |
| 3537 | "Connection: keep-alive\r\n\r\n"; |
| 3538 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3539 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3540 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3541 | "Content-Length: 2\r\n\r\n"; |
| 3542 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3543 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3544 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3545 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3546 | |
| 3547 | MockWrite spdy_writes[] = { |
| 3548 | CreateMockWrite(*connect1, 0), |
| 3549 | CreateMockWrite(*wrapped_get1, 2), |
| 3550 | CreateMockWrite(*connect2, 5), |
| 3551 | CreateMockWrite(*wrapped_get2, 7), |
| 3552 | }; |
| 3553 | |
| 3554 | MockRead spdy_reads[] = { |
| 3555 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3556 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3557 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3558 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3559 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3560 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3561 | MockRead(ASYNC, 0, 10), |
| 3562 | }; |
| 3563 | |
| 3564 | DeterministicSocketData spdy_data( |
| 3565 | spdy_reads, arraysize(spdy_reads), |
| 3566 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3567 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3568 | |
| 3569 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3570 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3571 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3572 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3573 | ssl2.was_npn_negotiated = false; |
| 3574 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3575 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3576 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3577 | ssl3.was_npn_negotiated = false; |
| 3578 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3579 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3580 | |
| 3581 | TestCompletionCallback callback; |
| 3582 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3583 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3584 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3585 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3587 | // The first connect and request, each of their responses, and the body. |
| 3588 | spdy_data.RunFor(5); |
| 3589 | |
| 3590 | rv = callback.WaitForResult(); |
| 3591 | EXPECT_EQ(OK, rv); |
| 3592 | |
| 3593 | LoadTimingInfo load_timing_info; |
| 3594 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3595 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3596 | |
| 3597 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3598 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3599 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3600 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3601 | |
| 3602 | std::string response_data; |
| 3603 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3604 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3605 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3606 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3607 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3608 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3610 | |
| 3611 | // The second connect and request, each of their responses, and the body. |
| 3612 | spdy_data.RunFor(5); |
| 3613 | rv = callback.WaitForResult(); |
| 3614 | EXPECT_EQ(OK, rv); |
| 3615 | |
| 3616 | LoadTimingInfo load_timing_info2; |
| 3617 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3618 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3619 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3620 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3621 | |
| 3622 | // The requests should have different IDs, since they each are using their own |
| 3623 | // separate stream. |
| 3624 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3625 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3626 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3630 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3631 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3632 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3633 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3634 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3635 | "https://proxy:70")); |
| 3636 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3637 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3638 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3639 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3640 | |
| 3641 | HttpRequestInfo request1; |
| 3642 | request1.method = "GET"; |
| 3643 | request1.url = GURL("https://www.google.com/"); |
| 3644 | request1.load_flags = 0; |
| 3645 | |
| 3646 | HttpRequestInfo request2; |
| 3647 | request2.method = "GET"; |
| 3648 | request2.url = GURL("https://www.google.com/2"); |
| 3649 | request2.load_flags = 0; |
| 3650 | |
| 3651 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3652 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3653 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3654 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3655 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3656 | |
| 3657 | // Fetch https://www.google.com/ via HTTP. |
| 3658 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3659 | "Host: www.google.com\r\n" |
| 3660 | "Connection: keep-alive\r\n\r\n"; |
| 3661 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3662 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3663 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3664 | "Content-Length: 1\r\n\r\n"; |
| 3665 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3666 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3667 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3668 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3669 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3670 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3671 | |
| 3672 | // Fetch https://www.google.com/2 via HTTP. |
| 3673 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3674 | "Host: www.google.com\r\n" |
| 3675 | "Connection: keep-alive\r\n\r\n"; |
| 3676 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3677 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3678 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3679 | "Content-Length: 2\r\n\r\n"; |
| 3680 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3681 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3682 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3683 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3684 | |
| 3685 | MockWrite spdy_writes[] = { |
| 3686 | CreateMockWrite(*connect1, 0), |
| 3687 | CreateMockWrite(*wrapped_get1, 2), |
| 3688 | CreateMockWrite(*wrapped_get2, 5), |
| 3689 | }; |
| 3690 | |
| 3691 | MockRead spdy_reads[] = { |
| 3692 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3693 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3694 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3695 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3696 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3697 | MockRead(ASYNC, 0, 8), |
| 3698 | }; |
| 3699 | |
| 3700 | DeterministicSocketData spdy_data( |
| 3701 | spdy_reads, arraysize(spdy_reads), |
| 3702 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3703 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3704 | |
| 3705 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3706 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3707 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3708 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3709 | ssl2.was_npn_negotiated = false; |
| 3710 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3711 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3712 | |
| 3713 | TestCompletionCallback callback; |
| 3714 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3715 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3717 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3718 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3719 | // The first connect and request, each of their responses, and the body. |
| 3720 | spdy_data.RunFor(5); |
| 3721 | |
| 3722 | rv = callback.WaitForResult(); |
| 3723 | EXPECT_EQ(OK, rv); |
| 3724 | |
| 3725 | LoadTimingInfo load_timing_info; |
| 3726 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3727 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3728 | |
| 3729 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3730 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3731 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3732 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3733 | |
| 3734 | std::string response_data; |
| 3735 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3736 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3737 | trans.reset(); |
| 3738 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3739 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3740 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3741 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3743 | |
| 3744 | // The second request, response, and body. There should not be a second |
| 3745 | // connect. |
| 3746 | spdy_data.RunFor(3); |
| 3747 | rv = callback.WaitForResult(); |
| 3748 | EXPECT_EQ(OK, rv); |
| 3749 | |
| 3750 | LoadTimingInfo load_timing_info2; |
| 3751 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3752 | TestLoadTimingReused(load_timing_info2); |
| 3753 | |
| 3754 | // The requests should have the same ID. |
| 3755 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3756 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3757 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 3761 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3762 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3763 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 3764 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3765 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3766 | "https://proxy:70")); |
| 3767 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3768 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3769 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3770 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3771 | |
| 3772 | HttpRequestInfo request1; |
| 3773 | request1.method = "GET"; |
| 3774 | request1.url = GURL("http://www.google.com/"); |
| 3775 | request1.load_flags = 0; |
| 3776 | |
| 3777 | HttpRequestInfo request2; |
| 3778 | request2.method = "GET"; |
| 3779 | request2.url = GURL("http://news.google.com/"); |
| 3780 | request2.load_flags = 0; |
| 3781 | |
| 3782 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3783 | scoped_ptr<SpdyHeaderBlock> headers( |
| 3784 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3785 | scoped_ptr<SpdyFrame> get1( |
| 3786 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3787 | scoped_ptr<SpdyFrame> get_resp1( |
| 3788 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3789 | scoped_ptr<SpdyFrame> body1( |
| 3790 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3791 | |
| 3792 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3793 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 3794 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3795 | scoped_ptr<SpdyFrame> get2( |
| 3796 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3797 | scoped_ptr<SpdyFrame> get_resp2( |
| 3798 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3799 | scoped_ptr<SpdyFrame> body2( |
| 3800 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3801 | |
| 3802 | MockWrite spdy_writes[] = { |
| 3803 | CreateMockWrite(*get1, 0), |
| 3804 | CreateMockWrite(*get2, 3), |
| 3805 | }; |
| 3806 | |
| 3807 | MockRead spdy_reads[] = { |
| 3808 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 3809 | CreateMockRead(*body1, 2, ASYNC), |
| 3810 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 3811 | CreateMockRead(*body2, 5, ASYNC), |
| 3812 | MockRead(ASYNC, 0, 6), |
| 3813 | }; |
| 3814 | |
| 3815 | DeterministicSocketData spdy_data( |
| 3816 | spdy_reads, arraysize(spdy_reads), |
| 3817 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3818 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3819 | |
| 3820 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3821 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3822 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3823 | |
| 3824 | TestCompletionCallback callback; |
| 3825 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3826 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3827 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3828 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3829 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3830 | spdy_data.RunFor(2); |
| 3831 | |
| 3832 | rv = callback.WaitForResult(); |
| 3833 | EXPECT_EQ(OK, rv); |
| 3834 | |
| 3835 | LoadTimingInfo load_timing_info; |
| 3836 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3837 | TestLoadTimingNotReused(load_timing_info, |
| 3838 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3839 | |
| 3840 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3841 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3842 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3843 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3844 | |
| 3845 | std::string response_data; |
| 3846 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3847 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3848 | spdy_data.RunFor(1); |
| 3849 | EXPECT_EQ(1, callback.WaitForResult()); |
| 3850 | // Delete the first request, so the second one can reuse the socket. |
| 3851 | trans.reset(); |
| 3852 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3853 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3854 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3855 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3856 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3857 | |
| 3858 | spdy_data.RunFor(2); |
| 3859 | rv = callback.WaitForResult(); |
| 3860 | EXPECT_EQ(OK, rv); |
| 3861 | |
| 3862 | LoadTimingInfo load_timing_info2; |
| 3863 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3864 | TestLoadTimingReused(load_timing_info2); |
| 3865 | |
| 3866 | // The requests should have the same ID. |
| 3867 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3868 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3869 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3870 | spdy_data.RunFor(1); |
| 3871 | EXPECT_EQ(2, callback.WaitForResult()); |
| 3872 | } |
| 3873 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3874 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3875 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3876 | HttpRequestInfo request; |
| 3877 | request.method = "GET"; |
| 3878 | request.url = GURL("http://www.google.com/"); |
| 3879 | // when the no authentication data flag is set. |
| 3880 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3881 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3882 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3883 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3884 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3885 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3886 | session_deps_.net_log = log.bound().net_log(); |
| 3887 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3888 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3889 | // Since we have proxy, should use full url |
| 3890 | MockWrite data_writes1[] = { |
| 3891 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3892 | "Host: www.google.com\r\n" |
| 3893 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3894 | |
| 3895 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3896 | // be issuing -- the final header line contains the credentials. |
| 3897 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3898 | "Host: www.google.com\r\n" |
| 3899 | "Proxy-Connection: keep-alive\r\n" |
| 3900 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3901 | }; |
| 3902 | |
| 3903 | // The proxy responds to the GET with a 407, using a persistent |
| 3904 | // connection. |
| 3905 | MockRead data_reads1[] = { |
| 3906 | // No credentials. |
| 3907 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3908 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3909 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3910 | MockRead("Content-Length: 0\r\n\r\n"), |
| 3911 | |
| 3912 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3913 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3914 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3916 | }; |
| 3917 | |
| 3918 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3919 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3920 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3921 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3922 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3924 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3925 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3926 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3928 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3929 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3930 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3931 | |
| 3932 | rv = callback1.WaitForResult(); |
| 3933 | EXPECT_EQ(OK, rv); |
| 3934 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3935 | LoadTimingInfo load_timing_info; |
| 3936 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3937 | TestLoadTimingNotReused(load_timing_info, |
| 3938 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3939 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3941 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3942 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3943 | EXPECT_EQ(407, response->headers->response_code()); |
| 3944 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3945 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3947 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3948 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3949 | rv = trans->RestartWithAuth( |
| 3950 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3951 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3952 | |
| 3953 | rv = callback2.WaitForResult(); |
| 3954 | EXPECT_EQ(OK, rv); |
| 3955 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3956 | load_timing_info = LoadTimingInfo(); |
| 3957 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3958 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 3959 | TestLoadTimingReused(load_timing_info); |
| 3960 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3961 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3962 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3963 | |
| 3964 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3965 | EXPECT_EQ(200, response->headers->response_code()); |
| 3966 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3967 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3968 | |
| 3969 | // The password prompt info should not be set. |
| 3970 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3971 | } |
| 3972 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3973 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3974 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3975 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3976 | request.method = "GET"; |
| 3977 | request.url = GURL("https://www.google.com/"); |
| 3978 | request.load_flags = 0; |
| 3979 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3980 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3981 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3982 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3983 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3984 | // Since we have proxy, should try to establish tunnel. |
| 3985 | MockWrite data_writes[] = { |
| 3986 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 3987 | "Host: www.google.com\r\n" |
| 3988 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3989 | }; |
| 3990 | |
| 3991 | MockRead data_reads[] = { |
| 3992 | status, |
| 3993 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3994 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3995 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 3996 | }; |
| 3997 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3998 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3999 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4002 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4003 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4004 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4005 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4007 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4008 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4009 | |
| 4010 | rv = callback.WaitForResult(); |
| 4011 | EXPECT_EQ(expected_status, rv); |
| 4012 | } |
| 4013 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4014 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4015 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4016 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4017 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4018 | } |
| 4019 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4020 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4021 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4022 | } |
| 4023 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4024 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4025 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4026 | } |
| 4027 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4028 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4029 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4030 | } |
| 4031 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4032 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4033 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4034 | } |
| 4035 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4036 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4037 | ConnectStatusHelper( |
| 4038 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4039 | } |
| 4040 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4041 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4042 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4043 | } |
| 4044 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4045 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4046 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4047 | } |
| 4048 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4049 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4050 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4051 | } |
| 4052 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4053 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4054 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4055 | } |
| 4056 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4057 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4058 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4059 | } |
| 4060 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4061 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4062 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4063 | } |
| 4064 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4065 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4066 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4067 | } |
| 4068 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4069 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4070 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4071 | } |
| 4072 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4073 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4074 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4075 | } |
| 4076 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4077 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4078 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4079 | } |
| 4080 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4081 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4082 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4083 | } |
| 4084 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4085 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4086 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4087 | } |
| 4088 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4089 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4090 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4091 | } |
| 4092 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4093 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4094 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4095 | } |
| 4096 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4097 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4098 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4099 | } |
| 4100 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4101 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4102 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4103 | } |
| 4104 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4105 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4106 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4107 | } |
| 4108 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4109 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4110 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4111 | } |
| 4112 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4113 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4114 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4115 | } |
| 4116 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4117 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4118 | ConnectStatusHelperWithExpectedStatus( |
| 4119 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4120 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4121 | } |
| 4122 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4123 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4124 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4125 | } |
| 4126 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4127 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4128 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4129 | } |
| 4130 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4131 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4132 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4133 | } |
| 4134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4135 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4136 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4137 | } |
| 4138 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4139 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4140 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4141 | } |
| 4142 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4143 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4144 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4145 | } |
| 4146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4147 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4148 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4149 | } |
| 4150 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4151 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4152 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4153 | } |
| 4154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4155 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4156 | ConnectStatusHelper( |
| 4157 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4158 | } |
| 4159 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4160 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4161 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4162 | } |
| 4163 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4164 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4165 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4166 | } |
| 4167 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4168 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4169 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4170 | } |
| 4171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4172 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4173 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4174 | } |
| 4175 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4176 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4177 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4178 | } |
| 4179 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4180 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4181 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4182 | } |
| 4183 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4184 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4185 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4186 | } |
| 4187 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4188 | // Test the flow when both the proxy server AND origin server require |
| 4189 | // authentication. Again, this uses basic auth for both since that is |
| 4190 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4191 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4192 | HttpRequestInfo request; |
| 4193 | request.method = "GET"; |
| 4194 | request.url = GURL("http://www.google.com/"); |
| 4195 | request.load_flags = 0; |
| 4196 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4197 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4198 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4199 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4200 | |
| 4201 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4203 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4204 | MockWrite data_writes1[] = { |
| 4205 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4206 | "Host: www.google.com\r\n" |
| 4207 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4208 | }; |
| 4209 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4210 | MockRead data_reads1[] = { |
| 4211 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4212 | // Give a couple authenticate options (only the middle one is actually |
| 4213 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4214 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4215 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4216 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4217 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4218 | // Large content-length -- won't matter, as connection will be reset. |
| 4219 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4220 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4221 | }; |
| 4222 | |
| 4223 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4224 | // request we should be issuing -- the final header line contains the |
| 4225 | // proxy's credentials. |
| 4226 | MockWrite data_writes2[] = { |
| 4227 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4228 | "Host: www.google.com\r\n" |
| 4229 | "Proxy-Connection: keep-alive\r\n" |
| 4230 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4231 | }; |
| 4232 | |
| 4233 | // Now the proxy server lets the request pass through to origin server. |
| 4234 | // The origin server responds with a 401. |
| 4235 | MockRead data_reads2[] = { |
| 4236 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4237 | // Note: We are using the same realm-name as the proxy server. This is |
| 4238 | // completely valid, as realms are unique across hosts. |
| 4239 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4240 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4241 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4242 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4243 | }; |
| 4244 | |
| 4245 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4246 | // the credentials for both the proxy and origin server. |
| 4247 | MockWrite data_writes3[] = { |
| 4248 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4249 | "Host: www.google.com\r\n" |
| 4250 | "Proxy-Connection: keep-alive\r\n" |
| 4251 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4252 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4253 | }; |
| 4254 | |
| 4255 | // Lastly we get the desired content. |
| 4256 | MockRead data_reads3[] = { |
| 4257 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4258 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4259 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4260 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4261 | }; |
| 4262 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4263 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4264 | data_writes1, arraysize(data_writes1)); |
| 4265 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4266 | data_writes2, arraysize(data_writes2)); |
| 4267 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4268 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4270 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4271 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4273 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4275 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4276 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4277 | |
| 4278 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4279 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4280 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4281 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4282 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4283 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4285 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4287 | rv = trans->RestartWithAuth( |
| 4288 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4290 | |
| 4291 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4292 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4293 | |
| 4294 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4295 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4296 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4297 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4298 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4300 | rv = trans->RestartWithAuth( |
| 4301 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4302 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4303 | |
| 4304 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4305 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4306 | |
| 4307 | response = trans->GetResponseInfo(); |
| 4308 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4309 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4310 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4311 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4312 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4313 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4314 | // authorization headers. |
| 4315 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4316 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4317 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4318 | // bytes in the debugger. |
| 4319 | |
| 4320 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4321 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4322 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4323 | request.method = "GET"; |
| 4324 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4325 | |
| 4326 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4327 | // to other auth schemes. |
| 4328 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4329 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4330 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4331 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4332 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4333 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4334 | MockWrite data_writes1[] = { |
| 4335 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4336 | "Host: 172.22.68.17\r\n" |
| 4337 | "Connection: keep-alive\r\n\r\n"), |
| 4338 | }; |
| 4339 | |
| 4340 | MockRead data_reads1[] = { |
| 4341 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4342 | // Negotiate and NTLM are often requested together. However, we only want |
| 4343 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4344 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4345 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4346 | MockRead("Connection: close\r\n"), |
| 4347 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4348 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4349 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4350 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4351 | }; |
| 4352 | |
| 4353 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4354 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4355 | // request we should be issuing -- the final header line contains a Type |
| 4356 | // 1 message. |
| 4357 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4358 | "Host: 172.22.68.17\r\n" |
| 4359 | "Connection: keep-alive\r\n" |
| 4360 | "Authorization: NTLM " |
| 4361 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4362 | |
| 4363 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4364 | // (the credentials for the origin server). The second request continues |
| 4365 | // on the same connection. |
| 4366 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4367 | "Host: 172.22.68.17\r\n" |
| 4368 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4369 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4370 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4371 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4372 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4373 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4374 | }; |
| 4375 | |
| 4376 | MockRead data_reads2[] = { |
| 4377 | // The origin server responds with a Type 2 message. |
| 4378 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4379 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4380 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4381 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4382 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4383 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4384 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4385 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4386 | "BtAAAAAAA=\r\n"), |
| 4387 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4388 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4389 | MockRead("You are not authorized to view this page\r\n"), |
| 4390 | |
| 4391 | // Lastly we get the desired content. |
| 4392 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4393 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4394 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4395 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4396 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4397 | }; |
| 4398 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4399 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4400 | data_writes1, arraysize(data_writes1)); |
| 4401 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4402 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4403 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4404 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4405 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4406 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4407 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4408 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4409 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4410 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4411 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4412 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4413 | |
| 4414 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4415 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4416 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4417 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4418 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4419 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4420 | ASSERT_FALSE(response == NULL); |
| 4421 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4422 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4423 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4424 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4425 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4426 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4427 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4428 | |
| 4429 | rv = callback2.WaitForResult(); |
| 4430 | EXPECT_EQ(OK, rv); |
| 4431 | |
| 4432 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4433 | |
| 4434 | response = trans->GetResponseInfo(); |
| 4435 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4436 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4438 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4440 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4442 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4443 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4444 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4445 | |
| 4446 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4447 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4448 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4449 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4450 | } |
| 4451 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4452 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4453 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4454 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4455 | request.method = "GET"; |
| 4456 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4457 | request.load_flags = 0; |
| 4458 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4459 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4460 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4461 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4462 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4463 | MockWrite data_writes1[] = { |
| 4464 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4465 | "Host: 172.22.68.17\r\n" |
| 4466 | "Connection: keep-alive\r\n\r\n"), |
| 4467 | }; |
| 4468 | |
| 4469 | MockRead data_reads1[] = { |
| 4470 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4471 | // Negotiate and NTLM are often requested together. However, we only want |
| 4472 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4473 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4474 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4475 | MockRead("Connection: close\r\n"), |
| 4476 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4477 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4478 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4479 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4480 | }; |
| 4481 | |
| 4482 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4483 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4484 | // request we should be issuing -- the final header line contains a Type |
| 4485 | // 1 message. |
| 4486 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4487 | "Host: 172.22.68.17\r\n" |
| 4488 | "Connection: keep-alive\r\n" |
| 4489 | "Authorization: NTLM " |
| 4490 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4491 | |
| 4492 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4493 | // (the credentials for the origin server). The second request continues |
| 4494 | // on the same connection. |
| 4495 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4496 | "Host: 172.22.68.17\r\n" |
| 4497 | "Connection: keep-alive\r\n" |
| 4498 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4499 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4500 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4501 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4502 | "4Ww7b7E=\r\n\r\n"), |
| 4503 | }; |
| 4504 | |
| 4505 | MockRead data_reads2[] = { |
| 4506 | // The origin server responds with a Type 2 message. |
| 4507 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4508 | MockRead("WWW-Authenticate: NTLM " |
| 4509 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4510 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4511 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4512 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4513 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4514 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4515 | "BtAAAAAAA=\r\n"), |
| 4516 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4517 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4518 | MockRead("You are not authorized to view this page\r\n"), |
| 4519 | |
| 4520 | // Wrong password. |
| 4521 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4522 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4523 | MockRead("Connection: close\r\n"), |
| 4524 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4525 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4526 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4527 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4528 | }; |
| 4529 | |
| 4530 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4531 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4532 | // request we should be issuing -- the final header line contains a Type |
| 4533 | // 1 message. |
| 4534 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4535 | "Host: 172.22.68.17\r\n" |
| 4536 | "Connection: keep-alive\r\n" |
| 4537 | "Authorization: NTLM " |
| 4538 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4539 | |
| 4540 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4541 | // (the credentials for the origin server). The second request continues |
| 4542 | // on the same connection. |
| 4543 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4544 | "Host: 172.22.68.17\r\n" |
| 4545 | "Connection: keep-alive\r\n" |
| 4546 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4547 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4548 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4549 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4550 | "+4MUm7c=\r\n\r\n"), |
| 4551 | }; |
| 4552 | |
| 4553 | MockRead data_reads3[] = { |
| 4554 | // The origin server responds with a Type 2 message. |
| 4555 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4556 | MockRead("WWW-Authenticate: NTLM " |
| 4557 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4558 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4559 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4560 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4561 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4562 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4563 | "BtAAAAAAA=\r\n"), |
| 4564 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4565 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4566 | MockRead("You are not authorized to view this page\r\n"), |
| 4567 | |
| 4568 | // Lastly we get the desired content. |
| 4569 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4570 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4571 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4572 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4573 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4574 | }; |
| 4575 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4576 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4577 | data_writes1, arraysize(data_writes1)); |
| 4578 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4579 | data_writes2, arraysize(data_writes2)); |
| 4580 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4581 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4582 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4583 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4584 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4586 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4587 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4588 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4589 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4591 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4592 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4593 | |
| 4594 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4595 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4596 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4597 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4598 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4599 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4600 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4601 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4603 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4604 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4605 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4606 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4607 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4609 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4610 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4611 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4612 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4613 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4614 | TestCompletionCallback callback3; |
| 4615 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4616 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4617 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4618 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4619 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4620 | |
| 4621 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4622 | ASSERT_FALSE(response == NULL); |
| 4623 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4625 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4626 | |
| 4627 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4628 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4629 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4630 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4631 | |
| 4632 | rv = callback4.WaitForResult(); |
| 4633 | EXPECT_EQ(OK, rv); |
| 4634 | |
| 4635 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4637 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4638 | |
| 4639 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4640 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4641 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4642 | |
| 4643 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4644 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4645 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4646 | response = trans->GetResponseInfo(); |
| 4647 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4648 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4649 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4650 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4651 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4652 | // Test reading a server response which has only headers, and no body. |
| 4653 | // After some maximum number of bytes is consumed, the transaction should |
| 4654 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4655 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4656 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4657 | request.method = "GET"; |
| 4658 | request.url = GURL("http://www.google.com/"); |
| 4659 | request.load_flags = 0; |
| 4660 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4661 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4662 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4663 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4664 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4665 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4666 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4667 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4668 | |
| 4669 | MockRead data_reads[] = { |
| 4670 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4671 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4672 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4673 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4674 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4675 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4676 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4677 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4678 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4680 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4681 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4682 | |
| 4683 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4684 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4685 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4686 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4687 | EXPECT_TRUE(response == NULL); |
| 4688 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4689 | |
| 4690 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4691 | // establish tunnel. |
| 4692 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4693 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4694 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4695 | HttpRequestInfo request; |
| 4696 | request.method = "GET"; |
| 4697 | request.url = GURL("https://www.google.com/"); |
| 4698 | request.load_flags = 0; |
| 4699 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4700 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4701 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 4702 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4703 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4704 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4705 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4706 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4707 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4708 | // Since we have proxy, should try to establish tunnel. |
| 4709 | MockWrite data_writes1[] = { |
| 4710 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4711 | "Host: www.google.com\r\n" |
| 4712 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4713 | }; |
| 4714 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 4715 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4716 | // connection. Usually a proxy would return 501 (not implemented), |
| 4717 | // or 200 (tunnel established). |
| 4718 | MockRead data_reads1[] = { |
| 4719 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 4720 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4721 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4722 | }; |
| 4723 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4724 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4725 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4726 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4728 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4730 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4731 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4732 | |
| 4733 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4734 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4735 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4736 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4737 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4738 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4739 | // Empty the current queue. This is necessary because idle sockets are |
| 4740 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4741 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4742 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4743 | // We now check to make sure the TCPClientSocket was not added back to |
| 4744 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4745 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4746 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4747 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4748 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4749 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4750 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4751 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4752 | // 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] | 4753 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4754 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4755 | request.method = "GET"; |
| 4756 | request.url = GURL("http://www.google.com/"); |
| 4757 | request.load_flags = 0; |
| 4758 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4759 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4760 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4761 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4763 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4764 | MockRead data_reads[] = { |
| 4765 | // A part of the response body is received with the response headers. |
| 4766 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 4767 | // The rest of the response body is received in two parts. |
| 4768 | MockRead("lo"), |
| 4769 | MockRead(" world"), |
| 4770 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4771 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4772 | }; |
| 4773 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4774 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4777 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4778 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4779 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4780 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4781 | |
| 4782 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4783 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4784 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4785 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4786 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4787 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4788 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4789 | std::string status_line = response->headers->GetStatusLine(); |
| 4790 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 4791 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4792 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4793 | |
| 4794 | std::string response_data; |
| 4795 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4796 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4797 | EXPECT_EQ("hello world", response_data); |
| 4798 | |
| 4799 | // Empty the current queue. This is necessary because idle sockets are |
| 4800 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4801 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4802 | |
| 4803 | // 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] | 4804 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4805 | } |
| 4806 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4807 | // Make sure that we recycle a SSL socket after reading all of the response |
| 4808 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4809 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4810 | HttpRequestInfo request; |
| 4811 | request.method = "GET"; |
| 4812 | request.url = GURL("https://www.google.com/"); |
| 4813 | request.load_flags = 0; |
| 4814 | |
| 4815 | MockWrite data_writes[] = { |
| 4816 | MockWrite("GET / HTTP/1.1\r\n" |
| 4817 | "Host: www.google.com\r\n" |
| 4818 | "Connection: keep-alive\r\n\r\n"), |
| 4819 | }; |
| 4820 | |
| 4821 | MockRead data_reads[] = { |
| 4822 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4823 | MockRead("Content-Length: 11\r\n\r\n"), |
| 4824 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4826 | }; |
| 4827 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4828 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4829 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4830 | |
| 4831 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4832 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4833 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4835 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4836 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4837 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4838 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4839 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4841 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4842 | |
| 4843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4844 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4845 | |
| 4846 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4847 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4848 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4849 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4850 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4851 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4852 | |
| 4853 | std::string response_data; |
| 4854 | rv = ReadTransaction(trans.get(), &response_data); |
| 4855 | EXPECT_EQ(OK, rv); |
| 4856 | EXPECT_EQ("hello world", response_data); |
| 4857 | |
| 4858 | // Empty the current queue. This is necessary because idle sockets are |
| 4859 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4860 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4861 | |
| 4862 | // 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] | 4863 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 4867 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4868 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4869 | HttpRequestInfo request; |
| 4870 | request.method = "GET"; |
| 4871 | request.url = GURL("https://www.google.com/"); |
| 4872 | request.load_flags = 0; |
| 4873 | |
| 4874 | MockWrite data_writes[] = { |
| 4875 | MockWrite("GET / HTTP/1.1\r\n" |
| 4876 | "Host: www.google.com\r\n" |
| 4877 | "Connection: keep-alive\r\n\r\n"), |
| 4878 | MockWrite("GET / HTTP/1.1\r\n" |
| 4879 | "Host: www.google.com\r\n" |
| 4880 | "Connection: keep-alive\r\n\r\n"), |
| 4881 | }; |
| 4882 | |
| 4883 | MockRead data_reads[] = { |
| 4884 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4885 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4886 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4887 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4888 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4889 | }; |
| 4890 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4891 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4892 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4895 | |
| 4896 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4897 | data_writes, arraysize(data_writes)); |
| 4898 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 4899 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4901 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4903 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4904 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4905 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4906 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4907 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4909 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4910 | |
| 4911 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4912 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4913 | |
| 4914 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4915 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4916 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4917 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4918 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4919 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4920 | |
| 4921 | std::string response_data; |
| 4922 | rv = ReadTransaction(trans.get(), &response_data); |
| 4923 | EXPECT_EQ(OK, rv); |
| 4924 | EXPECT_EQ("hello world", response_data); |
| 4925 | |
| 4926 | // Empty the current queue. This is necessary because idle sockets are |
| 4927 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4928 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4929 | |
| 4930 | // 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] | 4931 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4932 | |
| 4933 | // Now start the second transaction, which should reuse the previous socket. |
| 4934 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4935 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4937 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4938 | |
| 4939 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4940 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4941 | |
| 4942 | response = trans->GetResponseInfo(); |
| 4943 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4944 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4945 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4946 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4947 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4948 | |
| 4949 | rv = ReadTransaction(trans.get(), &response_data); |
| 4950 | EXPECT_EQ(OK, rv); |
| 4951 | EXPECT_EQ("hello world", response_data); |
| 4952 | |
| 4953 | // Empty the current queue. This is necessary because idle sockets are |
| 4954 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4955 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4956 | |
| 4957 | // 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] | 4958 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4959 | } |
| 4960 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4961 | // Make sure that we recycle a socket after a zero-length response. |
| 4962 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4963 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4964 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4965 | request.method = "GET"; |
| 4966 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 4967 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 4968 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 4969 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 4970 | request.load_flags = 0; |
| 4971 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4972 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4973 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4974 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4975 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4976 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4977 | MockRead data_reads[] = { |
| 4978 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 4979 | "Content-Length: 0\r\n" |
| 4980 | "Content-Type: text/html\r\n\r\n"), |
| 4981 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4982 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4983 | }; |
| 4984 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4986 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4988 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4990 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4991 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4992 | |
| 4993 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4994 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4995 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4996 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4997 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4998 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4999 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5000 | std::string status_line = response->headers->GetStatusLine(); |
| 5001 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5002 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5003 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5004 | |
| 5005 | std::string response_data; |
| 5006 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5007 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5008 | EXPECT_EQ("", response_data); |
| 5009 | |
| 5010 | // Empty the current queue. This is necessary because idle sockets are |
| 5011 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5012 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5013 | |
| 5014 | // 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] | 5015 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5016 | } |
| 5017 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5018 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5019 | ScopedVector<UploadElementReader> element_readers; |
| 5020 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5021 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5022 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5023 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5024 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5025 | // after use. |
| 5026 | request[0].method = "GET"; |
| 5027 | request[0].url = GURL("http://www.google.com/"); |
| 5028 | request[0].load_flags = 0; |
| 5029 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5030 | // transaction 1. The first attempts fails when writing the POST data. |
| 5031 | // This causes the transaction to retry with a new socket. The second |
| 5032 | // attempt succeeds. |
| 5033 | request[1].method = "POST"; |
| 5034 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5035 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5036 | request[1].load_flags = 0; |
| 5037 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5038 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5039 | |
| 5040 | // The first socket is used for transaction 1 and the first attempt of |
| 5041 | // transaction 2. |
| 5042 | |
| 5043 | // The response of transaction 1. |
| 5044 | MockRead data_reads1[] = { |
| 5045 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5046 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5047 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5048 | }; |
| 5049 | // The mock write results of transaction 1 and the first attempt of |
| 5050 | // transaction 2. |
| 5051 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5052 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5053 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5054 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5055 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5056 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5057 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5058 | |
| 5059 | // The second socket is used for the second attempt of transaction 2. |
| 5060 | |
| 5061 | // The response of transaction 2. |
| 5062 | MockRead data_reads2[] = { |
| 5063 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5064 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5065 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5066 | }; |
| 5067 | // The mock write results of the second attempt of transaction 2. |
| 5068 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5069 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5070 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5071 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5072 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5073 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5074 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5075 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5076 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5077 | |
| 5078 | const char* kExpectedResponseData[] = { |
| 5079 | "hello world", "welcome" |
| 5080 | }; |
| 5081 | |
| 5082 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5083 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5084 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5086 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5088 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5090 | |
| 5091 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5092 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5093 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5094 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5095 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5096 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5097 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5098 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5099 | |
| 5100 | std::string response_data; |
| 5101 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5102 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5103 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5104 | } |
| 5105 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5106 | |
| 5107 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5108 | // 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] | 5109 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5110 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5111 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5112 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5113 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5114 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5115 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5116 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5117 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5119 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5120 | // The password contains an escaped character -- for this test to pass it |
| 5121 | // will need to be unescaped by HttpNetworkTransaction. |
| 5122 | EXPECT_EQ("b%40r", request.url.password()); |
| 5123 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5124 | MockWrite data_writes1[] = { |
| 5125 | MockWrite("GET / HTTP/1.1\r\n" |
| 5126 | "Host: www.google.com\r\n" |
| 5127 | "Connection: keep-alive\r\n\r\n"), |
| 5128 | }; |
| 5129 | |
| 5130 | MockRead data_reads1[] = { |
| 5131 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5132 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5133 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5134 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5135 | }; |
| 5136 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5137 | // After the challenge above, the transaction will be restarted using the |
| 5138 | // identity from the url (foo, b@r) to answer the challenge. |
| 5139 | MockWrite data_writes2[] = { |
| 5140 | MockWrite("GET / HTTP/1.1\r\n" |
| 5141 | "Host: www.google.com\r\n" |
| 5142 | "Connection: keep-alive\r\n" |
| 5143 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 5144 | }; |
| 5145 | |
| 5146 | MockRead data_reads2[] = { |
| 5147 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5148 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5149 | MockRead(SYNCHRONOUS, OK), |
| 5150 | }; |
| 5151 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5152 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5153 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5154 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5155 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5156 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5157 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5159 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5160 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5161 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5162 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5163 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5164 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5165 | |
| 5166 | TestCompletionCallback callback2; |
| 5167 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5168 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5169 | rv = callback2.WaitForResult(); |
| 5170 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5171 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5172 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5173 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5174 | ASSERT_TRUE(response != NULL); |
| 5175 | |
| 5176 | // There is no challenge info, since the identity in URL worked. |
| 5177 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5178 | |
| 5179 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5180 | |
| 5181 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5182 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5186 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5187 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5188 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5189 | HttpRequestInfo request; |
| 5190 | request.method = "GET"; |
| 5191 | // Note: the URL has a username:password in it. The password "baz" is |
| 5192 | // wrong (should be "bar"). |
| 5193 | request.url = GURL("http://foo:[email protected]/"); |
| 5194 | |
| 5195 | request.load_flags = LOAD_NORMAL; |
| 5196 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5197 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5198 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5200 | |
| 5201 | MockWrite data_writes1[] = { |
| 5202 | MockWrite("GET / HTTP/1.1\r\n" |
| 5203 | "Host: www.google.com\r\n" |
| 5204 | "Connection: keep-alive\r\n\r\n"), |
| 5205 | }; |
| 5206 | |
| 5207 | MockRead data_reads1[] = { |
| 5208 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5209 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5210 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5211 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5212 | }; |
| 5213 | |
| 5214 | // After the challenge above, the transaction will be restarted using the |
| 5215 | // identity from the url (foo, baz) to answer the challenge. |
| 5216 | MockWrite data_writes2[] = { |
| 5217 | MockWrite("GET / HTTP/1.1\r\n" |
| 5218 | "Host: www.google.com\r\n" |
| 5219 | "Connection: keep-alive\r\n" |
| 5220 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 5221 | }; |
| 5222 | |
| 5223 | MockRead data_reads2[] = { |
| 5224 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5225 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5226 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5227 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5228 | }; |
| 5229 | |
| 5230 | // After the challenge above, the transaction will be restarted using the |
| 5231 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5232 | MockWrite data_writes3[] = { |
| 5233 | MockWrite("GET / HTTP/1.1\r\n" |
| 5234 | "Host: www.google.com\r\n" |
| 5235 | "Connection: keep-alive\r\n" |
| 5236 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5237 | }; |
| 5238 | |
| 5239 | MockRead data_reads3[] = { |
| 5240 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5241 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5242 | MockRead(SYNCHRONOUS, OK), |
| 5243 | }; |
| 5244 | |
| 5245 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5246 | data_writes1, arraysize(data_writes1)); |
| 5247 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5248 | data_writes2, arraysize(data_writes2)); |
| 5249 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5250 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5252 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5253 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5254 | |
| 5255 | TestCompletionCallback callback1; |
| 5256 | |
| 5257 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5258 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5259 | |
| 5260 | rv = callback1.WaitForResult(); |
| 5261 | EXPECT_EQ(OK, rv); |
| 5262 | |
| 5263 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5264 | TestCompletionCallback callback2; |
| 5265 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5266 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5267 | rv = callback2.WaitForResult(); |
| 5268 | EXPECT_EQ(OK, rv); |
| 5269 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5270 | |
| 5271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5272 | ASSERT_TRUE(response != NULL); |
| 5273 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5274 | |
| 5275 | TestCompletionCallback callback3; |
| 5276 | rv = trans->RestartWithAuth( |
| 5277 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5278 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5279 | rv = callback3.WaitForResult(); |
| 5280 | EXPECT_EQ(OK, rv); |
| 5281 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5282 | |
| 5283 | response = trans->GetResponseInfo(); |
| 5284 | ASSERT_TRUE(response != NULL); |
| 5285 | |
| 5286 | // There is no challenge info, since the identity worked. |
| 5287 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5288 | |
| 5289 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5290 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5291 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5292 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5293 | } |
| 5294 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5295 | |
| 5296 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5297 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5298 | // from the URL should never be used. |
| 5299 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5300 | HttpRequestInfo request; |
| 5301 | request.method = "GET"; |
| 5302 | request.url = GURL("http://foo:[email protected]/"); |
| 5303 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5304 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5305 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5306 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5308 | |
| 5309 | MockWrite data_writes1[] = { |
| 5310 | MockWrite("GET / HTTP/1.1\r\n" |
| 5311 | "Host: www.google.com\r\n" |
| 5312 | "Connection: keep-alive\r\n\r\n"), |
| 5313 | }; |
| 5314 | |
| 5315 | MockRead data_reads1[] = { |
| 5316 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5317 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5318 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5319 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5320 | }; |
| 5321 | |
| 5322 | // After the challenge above, the transaction will be restarted using the |
| 5323 | // identity supplied by the user, not the one in the URL, to answer the |
| 5324 | // challenge. |
| 5325 | MockWrite data_writes3[] = { |
| 5326 | MockWrite("GET / HTTP/1.1\r\n" |
| 5327 | "Host: www.google.com\r\n" |
| 5328 | "Connection: keep-alive\r\n" |
| 5329 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5330 | }; |
| 5331 | |
| 5332 | MockRead data_reads3[] = { |
| 5333 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5334 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5335 | MockRead(SYNCHRONOUS, OK), |
| 5336 | }; |
| 5337 | |
| 5338 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5339 | data_writes1, arraysize(data_writes1)); |
| 5340 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5341 | data_writes3, arraysize(data_writes3)); |
| 5342 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5343 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5344 | |
| 5345 | TestCompletionCallback callback1; |
| 5346 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5347 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5348 | rv = callback1.WaitForResult(); |
| 5349 | EXPECT_EQ(OK, rv); |
| 5350 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5351 | |
| 5352 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5353 | ASSERT_TRUE(response != NULL); |
| 5354 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5355 | |
| 5356 | TestCompletionCallback callback3; |
| 5357 | rv = trans->RestartWithAuth( |
| 5358 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5359 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5360 | rv = callback3.WaitForResult(); |
| 5361 | EXPECT_EQ(OK, rv); |
| 5362 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5363 | |
| 5364 | response = trans->GetResponseInfo(); |
| 5365 | ASSERT_TRUE(response != NULL); |
| 5366 | |
| 5367 | // There is no challenge info, since the identity worked. |
| 5368 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5369 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5370 | |
| 5371 | // Empty the current queue. |
| 5372 | base::MessageLoop::current()->RunUntilIdle(); |
| 5373 | } |
| 5374 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5375 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5376 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5377 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5378 | |
| 5379 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5380 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5381 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5382 | request.method = "GET"; |
| 5383 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5384 | request.load_flags = 0; |
| 5385 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5386 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5387 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5388 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5389 | MockWrite data_writes1[] = { |
| 5390 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5391 | "Host: www.google.com\r\n" |
| 5392 | "Connection: keep-alive\r\n\r\n"), |
| 5393 | }; |
| 5394 | |
| 5395 | MockRead data_reads1[] = { |
| 5396 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5397 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5398 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5399 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5400 | }; |
| 5401 | |
| 5402 | // Resend with authorization (username=foo, password=bar) |
| 5403 | MockWrite data_writes2[] = { |
| 5404 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5405 | "Host: www.google.com\r\n" |
| 5406 | "Connection: keep-alive\r\n" |
| 5407 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5408 | }; |
| 5409 | |
| 5410 | // Sever accepts the authorization. |
| 5411 | MockRead data_reads2[] = { |
| 5412 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5413 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5414 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5415 | }; |
| 5416 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5417 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5418 | data_writes1, arraysize(data_writes1)); |
| 5419 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5420 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5421 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5422 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5424 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5426 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5427 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5428 | |
| 5429 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5430 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5431 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5432 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5433 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5434 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5436 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5438 | rv = trans->RestartWithAuth( |
| 5439 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5440 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5441 | |
| 5442 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5443 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5444 | |
| 5445 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5446 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5447 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5448 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5449 | } |
| 5450 | |
| 5451 | // ------------------------------------------------------------------------ |
| 5452 | |
| 5453 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5454 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5455 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5456 | request.method = "GET"; |
| 5457 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5458 | // protection space as MyRealm1. |
| 5459 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5460 | request.load_flags = 0; |
| 5461 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5462 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5463 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5464 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5465 | MockWrite data_writes1[] = { |
| 5466 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5467 | "Host: www.google.com\r\n" |
| 5468 | "Connection: keep-alive\r\n" |
| 5469 | // Send preemptive authorization for MyRealm1 |
| 5470 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5471 | }; |
| 5472 | |
| 5473 | // The server didn't like the preemptive authorization, and |
| 5474 | // challenges us for a different realm (MyRealm2). |
| 5475 | MockRead data_reads1[] = { |
| 5476 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5477 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5478 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5479 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5480 | }; |
| 5481 | |
| 5482 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5483 | MockWrite data_writes2[] = { |
| 5484 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5485 | "Host: www.google.com\r\n" |
| 5486 | "Connection: keep-alive\r\n" |
| 5487 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 5488 | }; |
| 5489 | |
| 5490 | // Sever accepts the authorization. |
| 5491 | MockRead data_reads2[] = { |
| 5492 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5493 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5494 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5495 | }; |
| 5496 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5497 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5498 | data_writes1, arraysize(data_writes1)); |
| 5499 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5500 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5501 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5502 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5503 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5504 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5505 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5506 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5507 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5508 | |
| 5509 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5510 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5511 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5512 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5513 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5514 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5515 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 5516 | EXPECT_EQ("www.google.com:80", |
| 5517 | response->auth_challenge->challenger.ToString()); |
| 5518 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5519 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5521 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5522 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5523 | rv = trans->RestartWithAuth( |
| 5524 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5525 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5526 | |
| 5527 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5528 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5529 | |
| 5530 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5531 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5532 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5533 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5534 | } |
| 5535 | |
| 5536 | // ------------------------------------------------------------------------ |
| 5537 | |
| 5538 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5539 | // succeed with preemptive authorization. |
| 5540 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5541 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5542 | request.method = "GET"; |
| 5543 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 5544 | request.load_flags = 0; |
| 5545 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5546 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5547 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5548 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5549 | MockWrite data_writes1[] = { |
| 5550 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 5551 | "Host: www.google.com\r\n" |
| 5552 | "Connection: keep-alive\r\n" |
| 5553 | // The authorization for MyRealm1 gets sent preemptively |
| 5554 | // (since the url is in the same protection space) |
| 5555 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5556 | }; |
| 5557 | |
| 5558 | // Sever accepts the preemptive authorization |
| 5559 | MockRead data_reads1[] = { |
| 5560 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5561 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5562 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5563 | }; |
| 5564 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5565 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5566 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5567 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5568 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5569 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5571 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5572 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5573 | |
| 5574 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5575 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5576 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5577 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5578 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5579 | |
| 5580 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5581 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5582 | } |
| 5583 | |
| 5584 | // ------------------------------------------------------------------------ |
| 5585 | |
| 5586 | // Transaction 4: request another URL in MyRealm (however the |
| 5587 | // url is not known to belong to the protection space, so no pre-auth). |
| 5588 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5589 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5590 | request.method = "GET"; |
| 5591 | request.url = GURL("http://www.google.com/x/1"); |
| 5592 | request.load_flags = 0; |
| 5593 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5594 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5596 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5597 | MockWrite data_writes1[] = { |
| 5598 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5599 | "Host: www.google.com\r\n" |
| 5600 | "Connection: keep-alive\r\n\r\n"), |
| 5601 | }; |
| 5602 | |
| 5603 | MockRead data_reads1[] = { |
| 5604 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5605 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5606 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5607 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5608 | }; |
| 5609 | |
| 5610 | // Resend with authorization from MyRealm's cache. |
| 5611 | MockWrite data_writes2[] = { |
| 5612 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5613 | "Host: www.google.com\r\n" |
| 5614 | "Connection: keep-alive\r\n" |
| 5615 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5616 | }; |
| 5617 | |
| 5618 | // Sever accepts the authorization. |
| 5619 | MockRead data_reads2[] = { |
| 5620 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5621 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5622 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5623 | }; |
| 5624 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5625 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5626 | data_writes1, arraysize(data_writes1)); |
| 5627 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5628 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5629 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5630 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5631 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5632 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5634 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5635 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5636 | |
| 5637 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5638 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5639 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5640 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5641 | TestCompletionCallback callback2; |
| 5642 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5643 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5644 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5645 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5646 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5647 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5648 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5649 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5650 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5651 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5652 | } |
| 5653 | |
| 5654 | // ------------------------------------------------------------------------ |
| 5655 | |
| 5656 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5657 | // cached identity. Should invalidate and re-prompt. |
| 5658 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5659 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5660 | request.method = "GET"; |
| 5661 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5662 | request.load_flags = 0; |
| 5663 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5664 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5665 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5666 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5667 | MockWrite data_writes1[] = { |
| 5668 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5669 | "Host: www.google.com\r\n" |
| 5670 | "Connection: keep-alive\r\n\r\n"), |
| 5671 | }; |
| 5672 | |
| 5673 | MockRead data_reads1[] = { |
| 5674 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5675 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5676 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5677 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5678 | }; |
| 5679 | |
| 5680 | // Resend with authorization from cache for MyRealm. |
| 5681 | MockWrite data_writes2[] = { |
| 5682 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5683 | "Host: www.google.com\r\n" |
| 5684 | "Connection: keep-alive\r\n" |
| 5685 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5686 | }; |
| 5687 | |
| 5688 | // Sever rejects the authorization. |
| 5689 | MockRead data_reads2[] = { |
| 5690 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5691 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5692 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5693 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5694 | }; |
| 5695 | |
| 5696 | // At this point we should prompt for new credentials for MyRealm. |
| 5697 | // Restart with username=foo3, password=foo4. |
| 5698 | MockWrite data_writes3[] = { |
| 5699 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5700 | "Host: www.google.com\r\n" |
| 5701 | "Connection: keep-alive\r\n" |
| 5702 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 5703 | }; |
| 5704 | |
| 5705 | // Sever accepts the authorization. |
| 5706 | MockRead data_reads3[] = { |
| 5707 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5708 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5710 | }; |
| 5711 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5712 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5713 | data_writes1, arraysize(data_writes1)); |
| 5714 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5715 | data_writes2, arraysize(data_writes2)); |
| 5716 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5717 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5718 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5719 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5720 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5722 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5724 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5725 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5726 | |
| 5727 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5728 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5729 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5730 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5731 | TestCompletionCallback callback2; |
| 5732 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5733 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5734 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5735 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5736 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5737 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5738 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5739 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5740 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5742 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5744 | rv = trans->RestartWithAuth( |
| 5745 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5746 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5747 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5748 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5749 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5750 | |
| 5751 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5752 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5753 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5754 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5755 | } |
| 5756 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5757 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5758 | // Tests that nonce count increments when multiple auth attempts |
| 5759 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5760 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 5761 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 5762 | new HttpAuthHandlerDigest::Factory(); |
| 5763 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 5764 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 5765 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5766 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 5767 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5768 | |
| 5769 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5770 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5771 | HttpRequestInfo request; |
| 5772 | request.method = "GET"; |
| 5773 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5774 | request.load_flags = 0; |
| 5775 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5776 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5777 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5778 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5779 | MockWrite data_writes1[] = { |
| 5780 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5781 | "Host: www.google.com\r\n" |
| 5782 | "Connection: keep-alive\r\n\r\n"), |
| 5783 | }; |
| 5784 | |
| 5785 | MockRead data_reads1[] = { |
| 5786 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5787 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 5788 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5790 | }; |
| 5791 | |
| 5792 | // Resend with authorization (username=foo, password=bar) |
| 5793 | MockWrite data_writes2[] = { |
| 5794 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5795 | "Host: www.google.com\r\n" |
| 5796 | "Connection: keep-alive\r\n" |
| 5797 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5798 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 5799 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 5800 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5801 | }; |
| 5802 | |
| 5803 | // Sever accepts the authorization. |
| 5804 | MockRead data_reads2[] = { |
| 5805 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5806 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5807 | }; |
| 5808 | |
| 5809 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5810 | data_writes1, arraysize(data_writes1)); |
| 5811 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5812 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5814 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5816 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5818 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5819 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5820 | |
| 5821 | rv = callback1.WaitForResult(); |
| 5822 | EXPECT_EQ(OK, rv); |
| 5823 | |
| 5824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5825 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5826 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5827 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5828 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5830 | rv = trans->RestartWithAuth( |
| 5831 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5832 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5833 | |
| 5834 | rv = callback2.WaitForResult(); |
| 5835 | EXPECT_EQ(OK, rv); |
| 5836 | |
| 5837 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5838 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5839 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5840 | } |
| 5841 | |
| 5842 | // ------------------------------------------------------------------------ |
| 5843 | |
| 5844 | // Transaction 2: Request another resource in digestive's protection space. |
| 5845 | // This will preemptively add an Authorization header which should have an |
| 5846 | // "nc" value of 2 (as compared to 1 in the first use. |
| 5847 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5848 | HttpRequestInfo request; |
| 5849 | request.method = "GET"; |
| 5850 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5851 | // protection space as digest. |
| 5852 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5853 | request.load_flags = 0; |
| 5854 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5855 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5856 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5857 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5858 | MockWrite data_writes1[] = { |
| 5859 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5860 | "Host: www.google.com\r\n" |
| 5861 | "Connection: keep-alive\r\n" |
| 5862 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5863 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 5864 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 5865 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5866 | }; |
| 5867 | |
| 5868 | // Sever accepts the authorization. |
| 5869 | MockRead data_reads1[] = { |
| 5870 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5871 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5872 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5873 | }; |
| 5874 | |
| 5875 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5876 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5879 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5881 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5882 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5883 | |
| 5884 | rv = callback1.WaitForResult(); |
| 5885 | EXPECT_EQ(OK, rv); |
| 5886 | |
| 5887 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5888 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5889 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5890 | } |
| 5891 | } |
| 5892 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5893 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5894 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5895 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5896 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5897 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5898 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5899 | |
| 5900 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5901 | trans->read_buf_ = new IOBuffer(15); |
| 5902 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5903 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5904 | |
| 5905 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 5906 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5907 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5908 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5909 | response->response_time = base::Time::Now(); |
| 5910 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5911 | |
| 5912 | { // Setup state for response_.vary_data |
| 5913 | HttpRequestInfo request; |
| 5914 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 5915 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 5916 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 5917 | request.extra_headers.SetHeader("Foo", "1"); |
| 5918 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5919 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5920 | } |
| 5921 | |
| 5922 | // Cause the above state to be reset. |
| 5923 | trans->ResetStateForRestart(); |
| 5924 | |
| 5925 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 5926 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5927 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5928 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5929 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5930 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 5931 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5932 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5933 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5934 | } |
| 5935 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5936 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5937 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5938 | HttpRequestInfo request; |
| 5939 | request.method = "GET"; |
| 5940 | request.url = GURL("https://www.google.com/"); |
| 5941 | request.load_flags = 0; |
| 5942 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5943 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5944 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5945 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5946 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5947 | MockWrite data_writes[] = { |
| 5948 | MockWrite("GET / HTTP/1.1\r\n" |
| 5949 | "Host: www.google.com\r\n" |
| 5950 | "Connection: keep-alive\r\n\r\n"), |
| 5951 | }; |
| 5952 | |
| 5953 | MockRead data_reads[] = { |
| 5954 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5955 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5956 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5957 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5958 | }; |
| 5959 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 5960 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5961 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5962 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5963 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 5964 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5965 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5966 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 5967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 5969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5971 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5973 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5975 | |
| 5976 | rv = callback.WaitForResult(); |
| 5977 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 5978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5979 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5980 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5981 | |
| 5982 | rv = callback.WaitForResult(); |
| 5983 | EXPECT_EQ(OK, rv); |
| 5984 | |
| 5985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5986 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5987 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5988 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5989 | } |
| 5990 | |
| 5991 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 5992 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5993 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5994 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 5995 | |
| 5996 | HttpRequestInfo request; |
| 5997 | request.method = "GET"; |
| 5998 | request.url = GURL("https://www.google.com/"); |
| 5999 | request.load_flags = 0; |
| 6000 | |
| 6001 | MockWrite proxy_writes[] = { |
| 6002 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6003 | "Host: www.google.com\r\n" |
| 6004 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6005 | }; |
| 6006 | |
| 6007 | MockRead proxy_reads[] = { |
| 6008 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6009 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6010 | }; |
| 6011 | |
| 6012 | MockWrite data_writes[] = { |
| 6013 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6014 | "Host: www.google.com\r\n" |
| 6015 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6016 | MockWrite("GET / HTTP/1.1\r\n" |
| 6017 | "Host: www.google.com\r\n" |
| 6018 | "Connection: keep-alive\r\n\r\n"), |
| 6019 | }; |
| 6020 | |
| 6021 | MockRead data_reads[] = { |
| 6022 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6023 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6024 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6025 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6026 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6027 | }; |
| 6028 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6029 | StaticSocketDataProvider ssl_bad_certificate( |
| 6030 | proxy_reads, arraysize(proxy_reads), |
| 6031 | proxy_writes, arraysize(proxy_writes)); |
| 6032 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6033 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6034 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6035 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6036 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6037 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6042 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6043 | |
| 6044 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6045 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6046 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6047 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6048 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6049 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6051 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6053 | |
| 6054 | rv = callback.WaitForResult(); |
| 6055 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6057 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6059 | |
| 6060 | rv = callback.WaitForResult(); |
| 6061 | EXPECT_EQ(OK, rv); |
| 6062 | |
| 6063 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6064 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6065 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6066 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6067 | } |
| 6068 | } |
| 6069 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6070 | |
| 6071 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6072 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6073 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6074 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6075 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6076 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6077 | |
| 6078 | HttpRequestInfo request; |
| 6079 | request.method = "GET"; |
| 6080 | request.url = GURL("https://www.google.com/"); |
| 6081 | request.load_flags = 0; |
| 6082 | |
| 6083 | MockWrite data_writes[] = { |
| 6084 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6085 | "Host: www.google.com\r\n" |
| 6086 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6087 | MockWrite("GET / HTTP/1.1\r\n" |
| 6088 | "Host: www.google.com\r\n" |
| 6089 | "Connection: keep-alive\r\n\r\n"), |
| 6090 | }; |
| 6091 | |
| 6092 | MockRead data_reads[] = { |
| 6093 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6094 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6095 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6096 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6097 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6098 | }; |
| 6099 | |
| 6100 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6101 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6102 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6103 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6104 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6105 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6107 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6109 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6110 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6111 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6112 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6115 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6116 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6117 | |
| 6118 | rv = callback.WaitForResult(); |
| 6119 | EXPECT_EQ(OK, rv); |
| 6120 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6121 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6122 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6123 | |
| 6124 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6125 | EXPECT_EQ(200, response->headers->response_code()); |
| 6126 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6127 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6128 | |
| 6129 | LoadTimingInfo load_timing_info; |
| 6130 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6131 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6132 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6133 | } |
| 6134 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6135 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6136 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6137 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6138 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6139 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6140 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6141 | |
| 6142 | HttpRequestInfo request; |
| 6143 | request.method = "GET"; |
| 6144 | request.url = GURL("https://www.google.com/"); |
| 6145 | request.load_flags = 0; |
| 6146 | |
| 6147 | MockWrite data_writes[] = { |
| 6148 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6149 | "Host: www.google.com\r\n" |
| 6150 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6151 | }; |
| 6152 | |
| 6153 | MockRead data_reads[] = { |
| 6154 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6155 | MockRead("Location: http://login.example.com/\r\n"), |
| 6156 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6157 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6158 | }; |
| 6159 | |
| 6160 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6161 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6162 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6163 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6164 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6167 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6168 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6169 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6170 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6171 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6173 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6174 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6175 | |
| 6176 | rv = callback.WaitForResult(); |
| 6177 | EXPECT_EQ(OK, rv); |
| 6178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6179 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6180 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6181 | |
| 6182 | EXPECT_EQ(302, response->headers->response_code()); |
| 6183 | std::string url; |
| 6184 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6185 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6186 | |
| 6187 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6188 | // timing for the proxy connection instead of the connection to the host, |
| 6189 | // and no send / receive times. |
| 6190 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6191 | LoadTimingInfo load_timing_info; |
| 6192 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6193 | |
| 6194 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 6195 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 6196 | |
| 6197 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6198 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6199 | load_timing_info.proxy_resolve_end); |
| 6200 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6201 | load_timing_info.connect_timing.connect_start); |
| 6202 | ExpectConnectTimingHasTimes( |
| 6203 | load_timing_info.connect_timing, |
| 6204 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6205 | |
| 6206 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6207 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6208 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6212 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6213 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6214 | ProxyService::CreateFixed("https://proxy:70")); |
| 6215 | |
| 6216 | HttpRequestInfo request; |
| 6217 | request.method = "GET"; |
| 6218 | request.url = GURL("https://www.google.com/"); |
| 6219 | request.load_flags = 0; |
| 6220 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6221 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6222 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6223 | scoped_ptr<SpdyFrame> goaway( |
| 6224 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6225 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6226 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 6227 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6228 | }; |
| 6229 | |
| 6230 | static const char* const kExtraHeaders[] = { |
| 6231 | "location", |
| 6232 | "http://login.example.com/", |
| 6233 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6234 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6235 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6236 | arraysize(kExtraHeaders)/2, 1)); |
| 6237 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6238 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6239 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6240 | }; |
| 6241 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6242 | DelayedSocketData data( |
| 6243 | 1, // wait for one write to finish before reading. |
| 6244 | data_reads, arraysize(data_reads), |
| 6245 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6246 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6247 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6248 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6252 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6253 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6254 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6255 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6256 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6258 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6259 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6260 | |
| 6261 | rv = callback.WaitForResult(); |
| 6262 | EXPECT_EQ(OK, rv); |
| 6263 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6264 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6265 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6266 | |
| 6267 | EXPECT_EQ(302, response->headers->response_code()); |
| 6268 | std::string url; |
| 6269 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6270 | EXPECT_EQ("http://login.example.com/", url); |
| 6271 | } |
| 6272 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6273 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6274 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6275 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6276 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6277 | ProxyService::CreateFixed("https://proxy:70")); |
| 6278 | |
| 6279 | HttpRequestInfo request; |
| 6280 | request.method = "GET"; |
| 6281 | request.url = GURL("https://www.google.com/"); |
| 6282 | request.load_flags = 0; |
| 6283 | |
| 6284 | MockWrite data_writes[] = { |
| 6285 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6286 | "Host: www.google.com\r\n" |
| 6287 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6288 | }; |
| 6289 | |
| 6290 | MockRead data_reads[] = { |
| 6291 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6292 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6293 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6294 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6295 | }; |
| 6296 | |
| 6297 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6298 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6299 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6300 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6301 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6304 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6305 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6306 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6307 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6308 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6310 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6311 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6312 | |
| 6313 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6314 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6315 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6316 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6317 | } |
| 6318 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6319 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6320 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6321 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6322 | session_deps_.proxy_service.reset( |
| 6323 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6324 | |
| 6325 | HttpRequestInfo request; |
| 6326 | request.method = "GET"; |
| 6327 | request.url = GURL("https://www.google.com/"); |
| 6328 | request.load_flags = 0; |
| 6329 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6330 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6331 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6332 | scoped_ptr<SpdyFrame> rst( |
| 6333 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6334 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6335 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6336 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6337 | }; |
| 6338 | |
| 6339 | static const char* const kExtraHeaders[] = { |
| 6340 | "location", |
| 6341 | "http://login.example.com/", |
| 6342 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6343 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6344 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6345 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6346 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6347 | spdy_util_.ConstructSpdyBodyFrame( |
| 6348 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6349 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6350 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6351 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6352 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6353 | }; |
| 6354 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6355 | DelayedSocketData data( |
| 6356 | 1, // wait for one write to finish before reading. |
| 6357 | data_reads, arraysize(data_reads), |
| 6358 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6359 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6360 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6361 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6365 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6366 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6367 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6368 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6369 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6371 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6372 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6373 | |
| 6374 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6375 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6376 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6377 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6378 | } |
| 6379 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6380 | // Test the request-challenge-retry sequence for basic auth, through |
| 6381 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6382 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6383 | HttpRequestInfo request; |
| 6384 | request.method = "GET"; |
| 6385 | request.url = GURL("https://www.google.com/"); |
| 6386 | // when the no authentication data flag is set. |
| 6387 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 6388 | |
| 6389 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6390 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6391 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6392 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6393 | session_deps_.net_log = log.bound().net_log(); |
| 6394 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6395 | |
| 6396 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6397 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
| 6398 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6399 | scoped_ptr<SpdyFrame> rst( |
| 6400 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6401 | |
| 6402 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6403 | // be issuing -- the final header line contains the credentials. |
| 6404 | const char* const kAuthCredentials[] = { |
| 6405 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6406 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6407 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6408 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
| 6409 | HostPortPair("www.google.com", 443))); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6410 | // fetch https://www.google.com/ via HTTP |
| 6411 | const char get[] = "GET / HTTP/1.1\r\n" |
| 6412 | "Host: www.google.com\r\n" |
| 6413 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6414 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6415 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6416 | |
| 6417 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6418 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 6419 | CreateMockWrite(*rst, 4, ASYNC), |
| 6420 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6421 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6422 | }; |
| 6423 | |
| 6424 | // The proxy responds to the connect with a 407, using a persistent |
| 6425 | // connection. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6426 | const char* const kAuthStatus = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6427 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6428 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6429 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6430 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6431 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6432 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6433 | scoped_ptr<SpdyFrame> conn_resp( |
| 6434 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6435 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6436 | "Content-Length: 5\r\n\r\n"; |
| 6437 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6438 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6439 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6440 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6441 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6442 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6443 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 6444 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 6445 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 6446 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 6447 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6448 | }; |
| 6449 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6450 | OrderedSocketData spdy_data( |
| 6451 | spdy_reads, arraysize(spdy_reads), |
| 6452 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6453 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6454 | // Negotiate SPDY to the proxy |
| 6455 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6456 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6458 | // Vanilla SSL to the server |
| 6459 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6461 | |
| 6462 | TestCompletionCallback callback1; |
| 6463 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6464 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6465 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6466 | |
| 6467 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6468 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6469 | |
| 6470 | rv = callback1.WaitForResult(); |
| 6471 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 6472 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6473 | log.GetEntries(&entries); |
| 6474 | size_t pos = ExpectLogContainsSomewhere( |
| 6475 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6476 | NetLog::PHASE_NONE); |
| 6477 | ExpectLogContainsSomewhere( |
| 6478 | entries, pos, |
| 6479 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6480 | NetLog::PHASE_NONE); |
| 6481 | |
| 6482 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6483 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6484 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6485 | EXPECT_EQ(407, response->headers->response_code()); |
| 6486 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6487 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6488 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6489 | |
| 6490 | TestCompletionCallback callback2; |
| 6491 | |
| 6492 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6493 | callback2.callback()); |
| 6494 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6495 | |
| 6496 | rv = callback2.WaitForResult(); |
| 6497 | EXPECT_EQ(OK, rv); |
| 6498 | |
| 6499 | response = trans->GetResponseInfo(); |
| 6500 | ASSERT_TRUE(response != NULL); |
| 6501 | |
| 6502 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6503 | EXPECT_EQ(200, response->headers->response_code()); |
| 6504 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6505 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6506 | |
| 6507 | // The password prompt info should not be set. |
| 6508 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6509 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6510 | LoadTimingInfo load_timing_info; |
| 6511 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6512 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6513 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6514 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6515 | trans.reset(); |
| 6516 | session->CloseAllConnections(); |
| 6517 | } |
| 6518 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6519 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6520 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6521 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6522 | HttpRequestInfo request; |
| 6523 | HttpRequestInfo push_request; |
| 6524 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6525 | request.method = "GET"; |
| 6526 | request.url = GURL("http://www.google.com/"); |
| 6527 | push_request.method = "GET"; |
| 6528 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6529 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6530 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6531 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6532 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6533 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6534 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6535 | |
| 6536 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6537 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6538 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6539 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6540 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6541 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6542 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6543 | |
| 6544 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6545 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6546 | }; |
| 6547 | |
| 6548 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6549 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6550 | |
| 6551 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6552 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6553 | |
| 6554 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6555 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6556 | 0, |
| 6557 | 2, |
| 6558 | 1, |
| 6559 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6560 | const char kPushedData[] = "pushed"; |
| 6561 | scoped_ptr<SpdyFrame> stream2_body( |
| 6562 | spdy_util_.ConstructSpdyBodyFrame( |
| 6563 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6564 | |
| 6565 | MockRead spdy_reads[] = { |
| 6566 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6567 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6568 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6569 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6570 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6571 | }; |
| 6572 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6573 | OrderedSocketData spdy_data( |
| 6574 | spdy_reads, arraysize(spdy_reads), |
| 6575 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6576 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6577 | // Negotiate SPDY to the proxy |
| 6578 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6579 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6581 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6582 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6584 | TestCompletionCallback callback; |
| 6585 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6587 | |
| 6588 | rv = callback.WaitForResult(); |
| 6589 | EXPECT_EQ(OK, rv); |
| 6590 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6591 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6592 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6593 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6594 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6595 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6596 | |
| 6597 | rv = callback.WaitForResult(); |
| 6598 | EXPECT_EQ(OK, rv); |
| 6599 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6600 | |
| 6601 | ASSERT_TRUE(response != NULL); |
| 6602 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6603 | |
| 6604 | EXPECT_EQ(200, response->headers->response_code()); |
| 6605 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6606 | |
| 6607 | std::string response_data; |
| 6608 | rv = ReadTransaction(trans.get(), &response_data); |
| 6609 | EXPECT_EQ(OK, rv); |
| 6610 | EXPECT_EQ("hello!", response_data); |
| 6611 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6612 | LoadTimingInfo load_timing_info; |
| 6613 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6614 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6615 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6616 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6617 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6618 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6619 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6620 | |
| 6621 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6622 | EXPECT_EQ(OK, rv); |
| 6623 | EXPECT_EQ("pushed", response_data); |
| 6624 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6625 | LoadTimingInfo push_load_timing_info; |
| 6626 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6627 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6628 | // The transactions should share a socket ID, despite being for different |
| 6629 | // origins. |
| 6630 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6631 | push_load_timing_info.socket_log_id); |
| 6632 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6633 | trans.reset(); |
| 6634 | push_trans.reset(); |
| 6635 | session->CloseAllConnections(); |
| 6636 | } |
| 6637 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6638 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6639 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6640 | HttpRequestInfo request; |
| 6641 | |
| 6642 | request.method = "GET"; |
| 6643 | request.url = GURL("http://www.google.com/"); |
| 6644 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6645 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6646 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6647 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6648 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6649 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6650 | |
| 6651 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6652 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6653 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6654 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6655 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6656 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6657 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6658 | |
| 6659 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6660 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6661 | |
| 6662 | MockWrite spdy_writes[] = { |
| 6663 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6664 | CreateMockWrite(*push_rst, 4), |
| 6665 | }; |
| 6666 | |
| 6667 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6668 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6669 | |
| 6670 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6671 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6672 | |
| 6673 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6674 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6675 | 0, |
| 6676 | 2, |
| 6677 | 1, |
| 6678 | "https://www.another-origin.com/foo.dat")); |
| 6679 | |
| 6680 | MockRead spdy_reads[] = { |
| 6681 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6682 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6683 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6684 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6685 | }; |
| 6686 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6687 | OrderedSocketData spdy_data( |
| 6688 | spdy_reads, arraysize(spdy_reads), |
| 6689 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6690 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6691 | // Negotiate SPDY to the proxy |
| 6692 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6693 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6694 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6695 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6696 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6697 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6698 | TestCompletionCallback callback; |
| 6699 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6700 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6701 | |
| 6702 | rv = callback.WaitForResult(); |
| 6703 | EXPECT_EQ(OK, rv); |
| 6704 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6705 | |
| 6706 | ASSERT_TRUE(response != NULL); |
| 6707 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6708 | |
| 6709 | EXPECT_EQ(200, response->headers->response_code()); |
| 6710 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6711 | |
| 6712 | std::string response_data; |
| 6713 | rv = ReadTransaction(trans.get(), &response_data); |
| 6714 | EXPECT_EQ(OK, rv); |
| 6715 | EXPECT_EQ("hello!", response_data); |
| 6716 | |
| 6717 | trans.reset(); |
| 6718 | session->CloseAllConnections(); |
| 6719 | } |
| 6720 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6721 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 6722 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6723 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6724 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 6725 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6726 | |
| 6727 | HttpRequestInfo request; |
| 6728 | request.method = "GET"; |
| 6729 | request.url = GURL("https://www.google.com/"); |
| 6730 | request.load_flags = 0; |
| 6731 | |
| 6732 | // Attempt to fetch the URL from a server with a bad cert |
| 6733 | MockWrite bad_cert_writes[] = { |
| 6734 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6735 | "Host: www.google.com\r\n" |
| 6736 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6737 | }; |
| 6738 | |
| 6739 | MockRead bad_cert_reads[] = { |
| 6740 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6741 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6742 | }; |
| 6743 | |
| 6744 | // Attempt to fetch the URL with a good cert |
| 6745 | MockWrite good_data_writes[] = { |
| 6746 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6747 | "Host: www.google.com\r\n" |
| 6748 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6749 | MockWrite("GET / HTTP/1.1\r\n" |
| 6750 | "Host: www.google.com\r\n" |
| 6751 | "Connection: keep-alive\r\n\r\n"), |
| 6752 | }; |
| 6753 | |
| 6754 | MockRead good_cert_reads[] = { |
| 6755 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6756 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6757 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6758 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6759 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6760 | }; |
| 6761 | |
| 6762 | StaticSocketDataProvider ssl_bad_certificate( |
| 6763 | bad_cert_reads, arraysize(bad_cert_reads), |
| 6764 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 6765 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 6766 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6767 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6768 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6769 | |
| 6770 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6771 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6772 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6774 | |
| 6775 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6777 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6780 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6781 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6782 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6783 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6784 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6786 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6787 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6788 | |
| 6789 | rv = callback.WaitForResult(); |
| 6790 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6792 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6794 | |
| 6795 | rv = callback.WaitForResult(); |
| 6796 | EXPECT_EQ(OK, rv); |
| 6797 | |
| 6798 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6799 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6800 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6801 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6802 | } |
| 6803 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6804 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6805 | HttpRequestInfo request; |
| 6806 | request.method = "GET"; |
| 6807 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6808 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6809 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6810 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6811 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6812 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6813 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6814 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6815 | MockWrite data_writes[] = { |
| 6816 | MockWrite("GET / HTTP/1.1\r\n" |
| 6817 | "Host: www.google.com\r\n" |
| 6818 | "Connection: keep-alive\r\n" |
| 6819 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6820 | }; |
| 6821 | |
| 6822 | // Lastly, the server responds with the actual content. |
| 6823 | MockRead data_reads[] = { |
| 6824 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6825 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6826 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6827 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6828 | }; |
| 6829 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6830 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6831 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6834 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6836 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6837 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6838 | |
| 6839 | rv = callback.WaitForResult(); |
| 6840 | EXPECT_EQ(OK, rv); |
| 6841 | } |
| 6842 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6843 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6844 | HttpRequestInfo request; |
| 6845 | request.method = "GET"; |
| 6846 | request.url = GURL("https://www.google.com/"); |
| 6847 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6848 | "Chromium Ultra Awesome X Edition"); |
| 6849 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6850 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6851 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6852 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6853 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6854 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6855 | MockWrite data_writes[] = { |
| 6856 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6857 | "Host: www.google.com\r\n" |
| 6858 | "Proxy-Connection: keep-alive\r\n" |
| 6859 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6860 | }; |
| 6861 | MockRead data_reads[] = { |
| 6862 | // Return an error, so the transaction stops here (this test isn't |
| 6863 | // interested in the rest). |
| 6864 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6865 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6866 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 6867 | }; |
| 6868 | |
| 6869 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6870 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6873 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6875 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6876 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6877 | |
| 6878 | rv = callback.WaitForResult(); |
| 6879 | EXPECT_EQ(OK, rv); |
| 6880 | } |
| 6881 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6882 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6883 | HttpRequestInfo request; |
| 6884 | request.method = "GET"; |
| 6885 | request.url = GURL("http://www.google.com/"); |
| 6886 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6887 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 6888 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6889 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6890 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6891 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6893 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6894 | MockWrite data_writes[] = { |
| 6895 | MockWrite("GET / HTTP/1.1\r\n" |
| 6896 | "Host: www.google.com\r\n" |
| 6897 | "Connection: keep-alive\r\n" |
| 6898 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 6899 | }; |
| 6900 | |
| 6901 | // Lastly, the server responds with the actual content. |
| 6902 | MockRead data_reads[] = { |
| 6903 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6904 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6905 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6906 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6907 | }; |
| 6908 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6909 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6910 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6911 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6913 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6915 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6916 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6917 | |
| 6918 | rv = callback.WaitForResult(); |
| 6919 | EXPECT_EQ(OK, rv); |
| 6920 | } |
| 6921 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6922 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6923 | HttpRequestInfo request; |
| 6924 | request.method = "POST"; |
| 6925 | request.url = GURL("http://www.google.com/"); |
| 6926 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6927 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6928 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6929 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6930 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6931 | MockWrite data_writes[] = { |
| 6932 | MockWrite("POST / HTTP/1.1\r\n" |
| 6933 | "Host: www.google.com\r\n" |
| 6934 | "Connection: keep-alive\r\n" |
| 6935 | "Content-Length: 0\r\n\r\n"), |
| 6936 | }; |
| 6937 | |
| 6938 | // Lastly, the server responds with the actual content. |
| 6939 | MockRead data_reads[] = { |
| 6940 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6941 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6942 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6943 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6944 | }; |
| 6945 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6946 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6947 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6948 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6950 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6952 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6953 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6954 | |
| 6955 | rv = callback.WaitForResult(); |
| 6956 | EXPECT_EQ(OK, rv); |
| 6957 | } |
| 6958 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6959 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6960 | HttpRequestInfo request; |
| 6961 | request.method = "PUT"; |
| 6962 | request.url = GURL("http://www.google.com/"); |
| 6963 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6964 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6965 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6966 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6967 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6968 | MockWrite data_writes[] = { |
| 6969 | MockWrite("PUT / HTTP/1.1\r\n" |
| 6970 | "Host: www.google.com\r\n" |
| 6971 | "Connection: keep-alive\r\n" |
| 6972 | "Content-Length: 0\r\n\r\n"), |
| 6973 | }; |
| 6974 | |
| 6975 | // Lastly, the server responds with the actual content. |
| 6976 | MockRead data_reads[] = { |
| 6977 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6978 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6979 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6980 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6981 | }; |
| 6982 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6983 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6984 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6987 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6989 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6990 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6991 | |
| 6992 | rv = callback.WaitForResult(); |
| 6993 | EXPECT_EQ(OK, rv); |
| 6994 | } |
| 6995 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6996 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6997 | HttpRequestInfo request; |
| 6998 | request.method = "HEAD"; |
| 6999 | request.url = GURL("http://www.google.com/"); |
| 7000 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7001 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7002 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7003 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7004 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7005 | MockWrite data_writes[] = { |
| 7006 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7007 | "Host: www.google.com\r\n" |
| 7008 | "Connection: keep-alive\r\n" |
| 7009 | "Content-Length: 0\r\n\r\n"), |
| 7010 | }; |
| 7011 | |
| 7012 | // Lastly, the server responds with the actual content. |
| 7013 | MockRead data_reads[] = { |
| 7014 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7015 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7016 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7017 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7018 | }; |
| 7019 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7020 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7021 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7022 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7024 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7026 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7027 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7028 | |
| 7029 | rv = callback.WaitForResult(); |
| 7030 | EXPECT_EQ(OK, rv); |
| 7031 | } |
| 7032 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7033 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7034 | HttpRequestInfo request; |
| 7035 | request.method = "GET"; |
| 7036 | request.url = GURL("http://www.google.com/"); |
| 7037 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7038 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7039 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7040 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7041 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7042 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7043 | MockWrite data_writes[] = { |
| 7044 | MockWrite("GET / HTTP/1.1\r\n" |
| 7045 | "Host: www.google.com\r\n" |
| 7046 | "Connection: keep-alive\r\n" |
| 7047 | "Pragma: no-cache\r\n" |
| 7048 | "Cache-Control: no-cache\r\n\r\n"), |
| 7049 | }; |
| 7050 | |
| 7051 | // Lastly, the server responds with the actual content. |
| 7052 | MockRead data_reads[] = { |
| 7053 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7054 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7055 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7056 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7057 | }; |
| 7058 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7059 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7060 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7063 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7065 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7067 | |
| 7068 | rv = callback.WaitForResult(); |
| 7069 | EXPECT_EQ(OK, rv); |
| 7070 | } |
| 7071 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7072 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7073 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7074 | HttpRequestInfo request; |
| 7075 | request.method = "GET"; |
| 7076 | request.url = GURL("http://www.google.com/"); |
| 7077 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7078 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7079 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7080 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7081 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7082 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7083 | MockWrite data_writes[] = { |
| 7084 | MockWrite("GET / HTTP/1.1\r\n" |
| 7085 | "Host: www.google.com\r\n" |
| 7086 | "Connection: keep-alive\r\n" |
| 7087 | "Cache-Control: max-age=0\r\n\r\n"), |
| 7088 | }; |
| 7089 | |
| 7090 | // Lastly, the server responds with the actual content. |
| 7091 | MockRead data_reads[] = { |
| 7092 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7093 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7094 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7095 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7096 | }; |
| 7097 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7098 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7099 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7102 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7104 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7106 | |
| 7107 | rv = callback.WaitForResult(); |
| 7108 | EXPECT_EQ(OK, rv); |
| 7109 | } |
| 7110 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7111 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7112 | HttpRequestInfo request; |
| 7113 | request.method = "GET"; |
| 7114 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7115 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7116 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7117 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7118 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7120 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7121 | MockWrite data_writes[] = { |
| 7122 | MockWrite("GET / HTTP/1.1\r\n" |
| 7123 | "Host: www.google.com\r\n" |
| 7124 | "Connection: keep-alive\r\n" |
| 7125 | "FooHeader: Bar\r\n\r\n"), |
| 7126 | }; |
| 7127 | |
| 7128 | // Lastly, the server responds with the actual content. |
| 7129 | MockRead data_reads[] = { |
| 7130 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7131 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7132 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7133 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7134 | }; |
| 7135 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7136 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7137 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7138 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7140 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7142 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7144 | |
| 7145 | rv = callback.WaitForResult(); |
| 7146 | EXPECT_EQ(OK, rv); |
| 7147 | } |
| 7148 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7149 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7150 | HttpRequestInfo request; |
| 7151 | request.method = "GET"; |
| 7152 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7153 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7154 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7155 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7156 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7157 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7158 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7159 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7160 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7161 | MockWrite data_writes[] = { |
| 7162 | MockWrite("GET / HTTP/1.1\r\n" |
| 7163 | "Host: www.google.com\r\n" |
| 7164 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7165 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7166 | "hEllo: Kitty\r\n" |
| 7167 | "FoO: bar\r\n\r\n"), |
| 7168 | }; |
| 7169 | |
| 7170 | // Lastly, the server responds with the actual content. |
| 7171 | MockRead data_reads[] = { |
| 7172 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7173 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7174 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7175 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7176 | }; |
| 7177 | |
| 7178 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7179 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7182 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7184 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7185 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7186 | |
| 7187 | rv = callback.WaitForResult(); |
| 7188 | EXPECT_EQ(OK, rv); |
| 7189 | } |
| 7190 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7191 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7192 | HttpRequestInfo request; |
| 7193 | request.method = "GET"; |
| 7194 | request.url = GURL("http://www.google.com/"); |
| 7195 | request.load_flags = 0; |
| 7196 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7197 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7198 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7199 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7200 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7201 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7202 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7203 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7205 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7206 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7207 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7208 | |
| 7209 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7210 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7211 | MockWrite("GET / HTTP/1.1\r\n" |
| 7212 | "Host: www.google.com\r\n" |
| 7213 | "Connection: keep-alive\r\n\r\n") |
| 7214 | }; |
| 7215 | |
| 7216 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7217 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7218 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7219 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7220 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7221 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7222 | }; |
| 7223 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7224 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7225 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7226 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7228 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7230 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7232 | |
| 7233 | rv = callback.WaitForResult(); |
| 7234 | EXPECT_EQ(OK, rv); |
| 7235 | |
| 7236 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7237 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7238 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7239 | LoadTimingInfo load_timing_info; |
| 7240 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7241 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7242 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7243 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7244 | std::string response_text; |
| 7245 | rv = ReadTransaction(trans.get(), &response_text); |
| 7246 | EXPECT_EQ(OK, rv); |
| 7247 | EXPECT_EQ("Payload", response_text); |
| 7248 | } |
| 7249 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7250 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7251 | HttpRequestInfo request; |
| 7252 | request.method = "GET"; |
| 7253 | request.url = GURL("https://www.google.com/"); |
| 7254 | request.load_flags = 0; |
| 7255 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7256 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7257 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7258 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7259 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7260 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7261 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7262 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7263 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7264 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7265 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7266 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7267 | |
| 7268 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7269 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7270 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7271 | MockWrite("GET / HTTP/1.1\r\n" |
| 7272 | "Host: www.google.com\r\n" |
| 7273 | "Connection: keep-alive\r\n\r\n") |
| 7274 | }; |
| 7275 | |
| 7276 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7277 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7278 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7279 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7281 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7282 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7283 | }; |
| 7284 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7286 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7288 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7289 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7292 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7294 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7295 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7296 | |
| 7297 | rv = callback.WaitForResult(); |
| 7298 | EXPECT_EQ(OK, rv); |
| 7299 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7300 | LoadTimingInfo load_timing_info; |
| 7301 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7302 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7303 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7304 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7305 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7306 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7307 | |
| 7308 | std::string response_text; |
| 7309 | rv = ReadTransaction(trans.get(), &response_text); |
| 7310 | EXPECT_EQ(OK, rv); |
| 7311 | EXPECT_EQ("Payload", response_text); |
| 7312 | } |
| 7313 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7314 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7315 | HttpRequestInfo request; |
| 7316 | request.method = "GET"; |
| 7317 | request.url = GURL("http://www.google.com/"); |
| 7318 | request.load_flags = 0; |
| 7319 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7320 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7321 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
| 7322 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7323 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7324 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7325 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7326 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7328 | |
| 7329 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7330 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7331 | |
| 7332 | MockWrite data_writes[] = { |
| 7333 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7334 | MockWrite("GET / HTTP/1.1\r\n" |
| 7335 | "Host: www.google.com\r\n" |
| 7336 | "Connection: keep-alive\r\n\r\n") |
| 7337 | }; |
| 7338 | |
| 7339 | MockRead data_reads[] = { |
| 7340 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7341 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7342 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7343 | MockRead("Payload"), |
| 7344 | MockRead(SYNCHRONOUS, OK) |
| 7345 | }; |
| 7346 | |
| 7347 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7348 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7349 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7350 | |
| 7351 | TestCompletionCallback callback; |
| 7352 | |
| 7353 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7354 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7355 | |
| 7356 | rv = callback.WaitForResult(); |
| 7357 | EXPECT_EQ(OK, rv); |
| 7358 | |
| 7359 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7360 | ASSERT_TRUE(response != NULL); |
| 7361 | |
| 7362 | LoadTimingInfo load_timing_info; |
| 7363 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7364 | TestLoadTimingNotReused(load_timing_info, |
| 7365 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7366 | |
| 7367 | std::string response_text; |
| 7368 | rv = ReadTransaction(trans.get(), &response_text); |
| 7369 | EXPECT_EQ(OK, rv); |
| 7370 | EXPECT_EQ("Payload", response_text); |
| 7371 | } |
| 7372 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7373 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7374 | HttpRequestInfo request; |
| 7375 | request.method = "GET"; |
| 7376 | request.url = GURL("http://www.google.com/"); |
| 7377 | request.load_flags = 0; |
| 7378 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7379 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7380 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7381 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7382 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7383 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7384 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7385 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7386 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7387 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7388 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7389 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7390 | const char kSOCKS5OkRequest[] = { |
| 7391 | 0x05, // Version |
| 7392 | 0x01, // Command (CONNECT) |
| 7393 | 0x00, // Reserved. |
| 7394 | 0x03, // Address type (DOMAINNAME). |
| 7395 | 0x0E, // Length of domain (14) |
| 7396 | // Domain string: |
| 7397 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7398 | 0x00, 0x50, // 16-bit port (80) |
| 7399 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7400 | const char kSOCKS5OkResponse[] = |
| 7401 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7402 | |
| 7403 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7404 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7405 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7406 | MockWrite("GET / HTTP/1.1\r\n" |
| 7407 | "Host: www.google.com\r\n" |
| 7408 | "Connection: keep-alive\r\n\r\n") |
| 7409 | }; |
| 7410 | |
| 7411 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7412 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7413 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7414 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7415 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7416 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7417 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7418 | }; |
| 7419 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7420 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7421 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7424 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7426 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7427 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7428 | |
| 7429 | rv = callback.WaitForResult(); |
| 7430 | EXPECT_EQ(OK, rv); |
| 7431 | |
| 7432 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7433 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7434 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7435 | LoadTimingInfo load_timing_info; |
| 7436 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7437 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7438 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7439 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7440 | std::string response_text; |
| 7441 | rv = ReadTransaction(trans.get(), &response_text); |
| 7442 | EXPECT_EQ(OK, rv); |
| 7443 | EXPECT_EQ("Payload", response_text); |
| 7444 | } |
| 7445 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7446 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7447 | HttpRequestInfo request; |
| 7448 | request.method = "GET"; |
| 7449 | request.url = GURL("https://www.google.com/"); |
| 7450 | request.load_flags = 0; |
| 7451 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7452 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7453 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7454 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7455 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7456 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7457 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7458 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7460 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7461 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7462 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7463 | const unsigned char kSOCKS5OkRequest[] = { |
| 7464 | 0x05, // Version |
| 7465 | 0x01, // Command (CONNECT) |
| 7466 | 0x00, // Reserved. |
| 7467 | 0x03, // Address type (DOMAINNAME). |
| 7468 | 0x0E, // Length of domain (14) |
| 7469 | // Domain string: |
| 7470 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7471 | 0x01, 0xBB, // 16-bit port (443) |
| 7472 | }; |
| 7473 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7474 | const char kSOCKS5OkResponse[] = |
| 7475 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7476 | |
| 7477 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7478 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7479 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7480 | arraysize(kSOCKS5OkRequest)), |
| 7481 | MockWrite("GET / HTTP/1.1\r\n" |
| 7482 | "Host: www.google.com\r\n" |
| 7483 | "Connection: keep-alive\r\n\r\n") |
| 7484 | }; |
| 7485 | |
| 7486 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7487 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7488 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7489 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7490 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7491 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7492 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7493 | }; |
| 7494 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7495 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7496 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7498 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7499 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7502 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7503 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7504 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7505 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7506 | |
| 7507 | rv = callback.WaitForResult(); |
| 7508 | EXPECT_EQ(OK, rv); |
| 7509 | |
| 7510 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7511 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7512 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7513 | LoadTimingInfo load_timing_info; |
| 7514 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7515 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7516 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7517 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7518 | std::string response_text; |
| 7519 | rv = ReadTransaction(trans.get(), &response_text); |
| 7520 | EXPECT_EQ(OK, rv); |
| 7521 | EXPECT_EQ("Payload", response_text); |
| 7522 | } |
| 7523 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7524 | namespace { |
| 7525 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7526 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7527 | |
| 7528 | struct GroupNameTest { |
| 7529 | std::string proxy_server; |
| 7530 | std::string url; |
| 7531 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7532 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7533 | }; |
| 7534 | |
| 7535 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7536 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7537 | SpdySessionDependencies* session_deps_) { |
| 7538 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7539 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7540 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7541 | session->http_server_properties(); |
| 7542 | http_server_properties->SetAlternateProtocol( |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7543 | HostPortPair("host.with.alternate", 80), 443, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 7544 | AlternateProtocolFromNextProto(next_proto), 1); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7545 | |
| 7546 | return session; |
| 7547 | } |
| 7548 | |
| 7549 | int GroupNameTransactionHelper( |
| 7550 | const std::string& url, |
| 7551 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7552 | HttpRequestInfo request; |
| 7553 | request.method = "GET"; |
| 7554 | request.url = GURL(url); |
| 7555 | request.load_flags = 0; |
| 7556 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7557 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7558 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7560 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7561 | |
| 7562 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7563 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7564 | } |
| 7565 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7566 | } // namespace |
| 7567 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7568 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7569 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7570 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7571 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7572 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7573 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7574 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7575 | }, |
| 7576 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7577 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7578 | "http://[2001:1418:13:1::25]/direct", |
| 7579 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7580 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7581 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7582 | |
| 7583 | // SSL Tests |
| 7584 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7585 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7586 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7587 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7588 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7589 | }, |
| 7590 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7591 | "", // unused |
| 7592 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7593 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7594 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7595 | }, |
| 7596 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7597 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7598 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7599 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7600 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7601 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7602 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7603 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7604 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7605 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7606 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7607 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7608 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7609 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7610 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7611 | |
| 7612 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7613 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7614 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7615 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7616 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7617 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7618 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7619 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7620 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7621 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7622 | |
| 7623 | EXPECT_EQ(ERR_IO_PENDING, |
| 7624 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7625 | if (tests[i].ssl) |
| 7626 | EXPECT_EQ(tests[i].expected_group_name, |
| 7627 | ssl_conn_pool->last_group_name_received()); |
| 7628 | else |
| 7629 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7630 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7631 | } |
| 7632 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7633 | } |
| 7634 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7635 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7636 | const GroupNameTest tests[] = { |
| 7637 | { |
| 7638 | "http_proxy", |
| 7639 | "http://www.google.com/http_proxy_normal", |
| 7640 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7641 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7642 | }, |
| 7643 | |
| 7644 | // SSL Tests |
| 7645 | { |
| 7646 | "http_proxy", |
| 7647 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7648 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7649 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7650 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7651 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7652 | { |
| 7653 | "http_proxy", |
| 7654 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7655 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7656 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7657 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7658 | |
| 7659 | { |
| 7660 | "http_proxy", |
| 7661 | "ftp://ftp.google.com/http_proxy_normal", |
| 7662 | "ftp/ftp.google.com:21", |
| 7663 | false, |
| 7664 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7665 | }; |
| 7666 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7667 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7668 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7669 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7670 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7671 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7672 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7673 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7674 | |
| 7675 | HttpNetworkSessionPeer peer(session); |
| 7676 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7677 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7678 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7679 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7680 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7681 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7682 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7683 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7684 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7685 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7686 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7687 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7688 | |
| 7689 | EXPECT_EQ(ERR_IO_PENDING, |
| 7690 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7691 | if (tests[i].ssl) |
| 7692 | EXPECT_EQ(tests[i].expected_group_name, |
| 7693 | ssl_conn_pool->last_group_name_received()); |
| 7694 | else |
| 7695 | EXPECT_EQ(tests[i].expected_group_name, |
| 7696 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7697 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7698 | } |
| 7699 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7700 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7701 | const GroupNameTest tests[] = { |
| 7702 | { |
| 7703 | "socks4://socks_proxy:1080", |
| 7704 | "http://www.google.com/socks4_direct", |
| 7705 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7706 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7707 | }, |
| 7708 | { |
| 7709 | "socks5://socks_proxy:1080", |
| 7710 | "http://www.google.com/socks5_direct", |
| 7711 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7712 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7713 | }, |
| 7714 | |
| 7715 | // SSL Tests |
| 7716 | { |
| 7717 | "socks4://socks_proxy:1080", |
| 7718 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7719 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7720 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7721 | }, |
| 7722 | { |
| 7723 | "socks5://socks_proxy:1080", |
| 7724 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7725 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7726 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7727 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7728 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7729 | { |
| 7730 | "socks4://socks_proxy:1080", |
| 7731 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7732 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7733 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7734 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7735 | }; |
| 7736 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7737 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7738 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7739 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7740 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7741 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7742 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7743 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7744 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7745 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7746 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7747 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7748 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7749 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7750 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7751 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7752 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7753 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7754 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7755 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 7756 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7757 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7758 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7759 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7761 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7762 | EXPECT_EQ(ERR_IO_PENDING, |
| 7763 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7764 | if (tests[i].ssl) |
| 7765 | EXPECT_EQ(tests[i].expected_group_name, |
| 7766 | ssl_conn_pool->last_group_name_received()); |
| 7767 | else |
| 7768 | EXPECT_EQ(tests[i].expected_group_name, |
| 7769 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7770 | } |
| 7771 | } |
| 7772 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7773 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7774 | HttpRequestInfo request; |
| 7775 | request.method = "GET"; |
| 7776 | request.url = GURL("http://www.google.com/"); |
| 7777 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7778 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 7779 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7780 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 7781 | // This simulates failure resolving all hostnames; that means we will fail |
| 7782 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7783 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7784 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7785 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7786 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7787 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7788 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7789 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7791 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7792 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7793 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7794 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 7795 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7796 | } |
| 7797 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7798 | // Base test to make sure that when the load flags for a request specify to |
| 7799 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7800 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7801 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7802 | // Issue a request, asking to bypass the cache(s). |
| 7803 | HttpRequestInfo request; |
| 7804 | request.method = "GET"; |
| 7805 | request.load_flags = load_flags; |
| 7806 | request.url = GURL("http://www.google.com/"); |
| 7807 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 7808 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7809 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7810 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7811 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7812 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7813 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7814 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7815 | // 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] | 7816 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7817 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7818 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7819 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7820 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7821 | &addrlist, |
| 7822 | callback.callback(), |
| 7823 | NULL, |
| 7824 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7826 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7827 | EXPECT_EQ(OK, rv); |
| 7828 | |
| 7829 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 7830 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7831 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7832 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7833 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7834 | &addrlist, |
| 7835 | callback.callback(), |
| 7836 | NULL, |
| 7837 | BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7838 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7839 | |
| 7840 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 7841 | // we can tell if the next lookup hit the cache, or the "network". |
| 7842 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7843 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7844 | |
| 7845 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 7846 | // 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] | 7847 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7848 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7850 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7851 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7852 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7853 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7854 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7855 | |
| 7856 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 7857 | // "www.google.com". |
| 7858 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 7859 | } |
| 7860 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7861 | // There are multiple load flags that should trigger the host cache bypass. |
| 7862 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7863 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7864 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 7865 | } |
| 7866 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7867 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7868 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 7869 | } |
| 7870 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7871 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7872 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 7873 | } |
| 7874 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7875 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7876 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7877 | HttpRequestInfo request; |
| 7878 | request.method = "GET"; |
| 7879 | request.url = GURL("http://www.foo.com/"); |
| 7880 | request.load_flags = 0; |
| 7881 | |
| 7882 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7883 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7884 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7885 | StaticSocketDataProvider data(NULL, 0, |
| 7886 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7887 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7888 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7890 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7891 | |
| 7892 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7893 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7894 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7895 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7897 | |
| 7898 | rv = callback.WaitForResult(); |
| 7899 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 7900 | } |
| 7901 | |
| 7902 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7903 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7904 | HttpRequestInfo request; |
| 7905 | request.method = "GET"; |
| 7906 | request.url = GURL("http://www.foo.com/"); |
| 7907 | request.load_flags = 0; |
| 7908 | |
| 7909 | MockRead data_reads[] = { |
| 7910 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7911 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7912 | }; |
| 7913 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7914 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7916 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7917 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7918 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7919 | |
| 7920 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7921 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7923 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7924 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7925 | |
| 7926 | rv = callback.WaitForResult(); |
| 7927 | EXPECT_EQ(OK, rv); |
| 7928 | |
| 7929 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7930 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7931 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7932 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7933 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 7934 | |
| 7935 | std::string response_data; |
| 7936 | rv = ReadTransaction(trans.get(), &response_data); |
| 7937 | EXPECT_EQ(OK, rv); |
| 7938 | EXPECT_EQ("", response_data); |
| 7939 | } |
| 7940 | |
| 7941 | // Make sure that a dropped connection while draining the body for auth |
| 7942 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7943 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7944 | HttpRequestInfo request; |
| 7945 | request.method = "GET"; |
| 7946 | request.url = GURL("http://www.google.com/"); |
| 7947 | request.load_flags = 0; |
| 7948 | |
| 7949 | MockWrite data_writes1[] = { |
| 7950 | MockWrite("GET / HTTP/1.1\r\n" |
| 7951 | "Host: www.google.com\r\n" |
| 7952 | "Connection: keep-alive\r\n\r\n"), |
| 7953 | }; |
| 7954 | |
| 7955 | MockRead data_reads1[] = { |
| 7956 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 7957 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7958 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7959 | MockRead("Content-Length: 14\r\n\r\n"), |
| 7960 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7961 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7962 | }; |
| 7963 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7964 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7965 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7966 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7967 | |
| 7968 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7969 | // be issuing -- the final header line contains the credentials. |
| 7970 | MockWrite data_writes2[] = { |
| 7971 | MockWrite("GET / HTTP/1.1\r\n" |
| 7972 | "Host: www.google.com\r\n" |
| 7973 | "Connection: keep-alive\r\n" |
| 7974 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 7975 | }; |
| 7976 | |
| 7977 | // Lastly, the server responds with the actual content. |
| 7978 | MockRead data_reads2[] = { |
| 7979 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7980 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7981 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7982 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7983 | }; |
| 7984 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7985 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7986 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7987 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7988 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7990 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7991 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7992 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7995 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7996 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7997 | |
| 7998 | rv = callback1.WaitForResult(); |
| 7999 | EXPECT_EQ(OK, rv); |
| 8000 | |
| 8001 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8002 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8003 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8005 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8007 | rv = trans->RestartWithAuth( |
| 8008 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8009 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8010 | |
| 8011 | rv = callback2.WaitForResult(); |
| 8012 | EXPECT_EQ(OK, rv); |
| 8013 | |
| 8014 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8015 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8016 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8017 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8018 | } |
| 8019 | |
| 8020 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8021 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8022 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8023 | |
| 8024 | HttpRequestInfo request; |
| 8025 | request.method = "GET"; |
| 8026 | request.url = GURL("https://www.google.com/"); |
| 8027 | request.load_flags = 0; |
| 8028 | |
| 8029 | MockRead proxy_reads[] = { |
| 8030 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8031 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8032 | }; |
| 8033 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8034 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8035 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8036 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8037 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8040 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8041 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8042 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8043 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8044 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8045 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8046 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8048 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8050 | |
| 8051 | rv = callback.WaitForResult(); |
| 8052 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8053 | } |
| 8054 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8055 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8056 | HttpRequestInfo request; |
| 8057 | request.method = "GET"; |
| 8058 | request.url = GURL("http://www.google.com/"); |
| 8059 | request.load_flags = 0; |
| 8060 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8061 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8062 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8064 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8065 | MockRead data_reads[] = { |
| 8066 | 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] | 8067 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8068 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8069 | |
| 8070 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8073 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8075 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8076 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8077 | |
| 8078 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8079 | |
| 8080 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8081 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8082 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8083 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8084 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8085 | |
| 8086 | std::string response_data; |
| 8087 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8088 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8089 | } |
| 8090 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8091 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8092 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8093 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8094 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8095 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8096 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8097 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8098 | ScopedVector<UploadElementReader> element_readers; |
| 8099 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8100 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8101 | temp_file_path, |
| 8102 | 0, |
| 8103 | kuint64max, |
| 8104 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8105 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8106 | |
| 8107 | HttpRequestInfo request; |
| 8108 | request.method = "POST"; |
| 8109 | request.url = GURL("http://www.google.com/upload"); |
| 8110 | request.upload_data_stream = &upload_data_stream; |
| 8111 | request.load_flags = 0; |
| 8112 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8113 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8114 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8115 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8116 | |
| 8117 | MockRead data_reads[] = { |
| 8118 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8119 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8120 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8121 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8122 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8123 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8124 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8125 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8127 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8129 | |
| 8130 | rv = callback.WaitForResult(); |
| 8131 | EXPECT_EQ(OK, rv); |
| 8132 | |
| 8133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8134 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8135 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8136 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8137 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8138 | |
| 8139 | std::string response_data; |
| 8140 | rv = ReadTransaction(trans.get(), &response_data); |
| 8141 | EXPECT_EQ(OK, rv); |
| 8142 | EXPECT_EQ("hello world", response_data); |
| 8143 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8144 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8145 | } |
| 8146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8147 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8148 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8149 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8150 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8151 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8152 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8153 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8154 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8155 | ScopedVector<UploadElementReader> element_readers; |
| 8156 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8157 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8158 | temp_file, |
| 8159 | 0, |
| 8160 | kuint64max, |
| 8161 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8162 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8163 | |
| 8164 | HttpRequestInfo request; |
| 8165 | request.method = "POST"; |
| 8166 | request.url = GURL("http://www.google.com/upload"); |
| 8167 | request.upload_data_stream = &upload_data_stream; |
| 8168 | request.load_flags = 0; |
| 8169 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8170 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8171 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8172 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8173 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8174 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8175 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8178 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8180 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8182 | |
| 8183 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8184 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8185 | |
| 8186 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8187 | EXPECT_FALSE(response); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8188 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8189 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8190 | } |
| 8191 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8192 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8193 | class FakeUploadElementReader : public UploadElementReader { |
| 8194 | public: |
| 8195 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8196 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8197 | |
| 8198 | const CompletionCallback& callback() const { return callback_; } |
| 8199 | |
| 8200 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8201 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8202 | callback_ = callback; |
| 8203 | return ERR_IO_PENDING; |
| 8204 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8205 | uint64 GetContentLength() const override { return 0; } |
| 8206 | uint64 BytesRemaining() const override { return 0; } |
| 8207 | int Read(IOBuffer* buf, |
| 8208 | int buf_length, |
| 8209 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8210 | return ERR_FAILED; |
| 8211 | } |
| 8212 | |
| 8213 | private: |
| 8214 | CompletionCallback callback_; |
| 8215 | }; |
| 8216 | |
| 8217 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8218 | ScopedVector<UploadElementReader> element_readers; |
| 8219 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8220 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8221 | |
| 8222 | HttpRequestInfo request; |
| 8223 | request.method = "POST"; |
| 8224 | request.url = GURL("http://www.google.com/upload"); |
| 8225 | request.upload_data_stream = &upload_data_stream; |
| 8226 | request.load_flags = 0; |
| 8227 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8229 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8231 | |
| 8232 | StaticSocketDataProvider data; |
| 8233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8234 | |
| 8235 | TestCompletionCallback callback; |
| 8236 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8237 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8238 | base::MessageLoop::current()->RunUntilIdle(); |
| 8239 | |
| 8240 | // Transaction is pending on request body initialization. |
| 8241 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8242 | |
| 8243 | // Return Init()'s result after the transaction gets destroyed. |
| 8244 | trans.reset(); |
| 8245 | fake_reader->callback().Run(OK); // Should not crash. |
| 8246 | } |
| 8247 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8248 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8249 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8250 | |
| 8251 | HttpRequestInfo request; |
| 8252 | request.method = "GET"; |
| 8253 | request.url = GURL("http://www.google.com/"); |
| 8254 | request.load_flags = 0; |
| 8255 | |
| 8256 | // First transaction will request a resource and receive a Basic challenge |
| 8257 | // with realm="first_realm". |
| 8258 | MockWrite data_writes1[] = { |
| 8259 | MockWrite("GET / HTTP/1.1\r\n" |
| 8260 | "Host: www.google.com\r\n" |
| 8261 | "Connection: keep-alive\r\n" |
| 8262 | "\r\n"), |
| 8263 | }; |
| 8264 | MockRead data_reads1[] = { |
| 8265 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8266 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8267 | "\r\n"), |
| 8268 | }; |
| 8269 | |
| 8270 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8271 | // for first_realm. The server will reject and provide a challenge with |
| 8272 | // second_realm. |
| 8273 | MockWrite data_writes2[] = { |
| 8274 | MockWrite("GET / HTTP/1.1\r\n" |
| 8275 | "Host: www.google.com\r\n" |
| 8276 | "Connection: keep-alive\r\n" |
| 8277 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8278 | "\r\n"), |
| 8279 | }; |
| 8280 | MockRead data_reads2[] = { |
| 8281 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8282 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8283 | "\r\n"), |
| 8284 | }; |
| 8285 | |
| 8286 | // This again fails, and goes back to first_realm. Make sure that the |
| 8287 | // entry is removed from cache. |
| 8288 | MockWrite data_writes3[] = { |
| 8289 | MockWrite("GET / HTTP/1.1\r\n" |
| 8290 | "Host: www.google.com\r\n" |
| 8291 | "Connection: keep-alive\r\n" |
| 8292 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8293 | "\r\n"), |
| 8294 | }; |
| 8295 | MockRead data_reads3[] = { |
| 8296 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8297 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8298 | "\r\n"), |
| 8299 | }; |
| 8300 | |
| 8301 | // Try one last time (with the correct password) and get the resource. |
| 8302 | MockWrite data_writes4[] = { |
| 8303 | MockWrite("GET / HTTP/1.1\r\n" |
| 8304 | "Host: www.google.com\r\n" |
| 8305 | "Connection: keep-alive\r\n" |
| 8306 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8307 | "\r\n"), |
| 8308 | }; |
| 8309 | MockRead data_reads4[] = { |
| 8310 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8311 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8312 | "Content-Length: 5\r\n" |
| 8313 | "\r\n" |
| 8314 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8315 | }; |
| 8316 | |
| 8317 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8318 | data_writes1, arraysize(data_writes1)); |
| 8319 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8320 | data_writes2, arraysize(data_writes2)); |
| 8321 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8322 | data_writes3, arraysize(data_writes3)); |
| 8323 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8324 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8326 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8327 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8328 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8330 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8331 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8332 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8333 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8334 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8335 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8336 | // Issue the first request with Authorize headers. There should be a |
| 8337 | // password prompt for first_realm waiting to be filled in after the |
| 8338 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8339 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8341 | rv = callback1.WaitForResult(); |
| 8342 | EXPECT_EQ(OK, rv); |
| 8343 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8344 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8345 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8346 | ASSERT_FALSE(challenge == NULL); |
| 8347 | EXPECT_FALSE(challenge->is_proxy); |
| 8348 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8349 | EXPECT_EQ("first_realm", challenge->realm); |
| 8350 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8351 | |
| 8352 | // Issue the second request with an incorrect password. There should be a |
| 8353 | // password prompt for second_realm waiting to be filled in after the |
| 8354 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8355 | TestCompletionCallback callback2; |
| 8356 | rv = trans->RestartWithAuth( |
| 8357 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8359 | rv = callback2.WaitForResult(); |
| 8360 | EXPECT_EQ(OK, rv); |
| 8361 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8362 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8363 | challenge = response->auth_challenge.get(); |
| 8364 | ASSERT_FALSE(challenge == NULL); |
| 8365 | EXPECT_FALSE(challenge->is_proxy); |
| 8366 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8367 | EXPECT_EQ("second_realm", challenge->realm); |
| 8368 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8369 | |
| 8370 | // Issue the third request with another incorrect password. There should be |
| 8371 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8372 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8373 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8374 | TestCompletionCallback callback3; |
| 8375 | rv = trans->RestartWithAuth( |
| 8376 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8378 | rv = callback3.WaitForResult(); |
| 8379 | EXPECT_EQ(OK, rv); |
| 8380 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8381 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8382 | challenge = response->auth_challenge.get(); |
| 8383 | ASSERT_FALSE(challenge == NULL); |
| 8384 | EXPECT_FALSE(challenge->is_proxy); |
| 8385 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8386 | EXPECT_EQ("first_realm", challenge->realm); |
| 8387 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8388 | |
| 8389 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8390 | TestCompletionCallback callback4; |
| 8391 | rv = trans->RestartWithAuth( |
| 8392 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8393 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8394 | rv = callback4.WaitForResult(); |
| 8395 | EXPECT_EQ(OK, rv); |
| 8396 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8397 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8398 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8399 | } |
| 8400 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8401 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8402 | session_deps_.next_protos = SpdyNextProtos(); |
| 8403 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8404 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8405 | std::string alternate_protocol_http_header = |
| 8406 | GetAlternateProtocolHttpHeader(); |
| 8407 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8408 | MockRead data_reads[] = { |
| 8409 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8410 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8411 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8412 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8413 | }; |
| 8414 | |
| 8415 | HttpRequestInfo request; |
| 8416 | request.method = "GET"; |
| 8417 | request.url = GURL("http://www.google.com/"); |
| 8418 | request.load_flags = 0; |
| 8419 | |
| 8420 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8421 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8424 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8425 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8426 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8427 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8428 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8430 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8431 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8432 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 8433 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8434 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8435 | *session->http_server_properties(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8436 | EXPECT_FALSE( |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8437 | http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8438 | |
| 8439 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8440 | |
| 8441 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8442 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8443 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8444 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8445 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8446 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8447 | |
| 8448 | std::string response_data; |
| 8449 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8450 | EXPECT_EQ("hello world", response_data); |
| 8451 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8452 | ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8453 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8454 | http_server_properties.GetAlternateProtocol(http_host_port_pair); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8455 | AlternateProtocolInfo expected_alternate( |
| 8456 | 443, AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8457 | EXPECT_TRUE(expected_alternate.Equals(alternate)); |
| 8458 | } |
| 8459 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8460 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8461 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8462 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8463 | |
| 8464 | HttpRequestInfo request; |
| 8465 | request.method = "GET"; |
| 8466 | request.url = GURL("http://www.google.com/"); |
| 8467 | request.load_flags = 0; |
| 8468 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8469 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8470 | StaticSocketDataProvider first_data; |
| 8471 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8472 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8473 | |
| 8474 | MockRead data_reads[] = { |
| 8475 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8476 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8477 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8478 | }; |
| 8479 | StaticSocketDataProvider second_data( |
| 8480 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8481 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8482 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8483 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8484 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8485 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8486 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8487 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8488 | // port 80 (another restricted port). |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8489 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8490 | HostPortPair::FromURL(request.url), |
| 8491 | 666 /* port is ignored by MockConnect anyway */, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8492 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8493 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8494 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8495 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8496 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8498 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8499 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8500 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8501 | |
| 8502 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8503 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8504 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8505 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8506 | |
| 8507 | std::string response_data; |
| 8508 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8509 | EXPECT_EQ("hello world", response_data); |
| 8510 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8511 | ASSERT_TRUE(http_server_properties->HasAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8512 | HostPortPair::FromURL(request.url))); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8513 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8514 | http_server_properties->GetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8515 | HostPortPair::FromURL(request.url)); |
bnc | cbd55d5f | 2014-11-06 19:50:40 | [diff] [blame] | 8516 | EXPECT_TRUE(alternate.is_broken); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8517 | } |
| 8518 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8519 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8520 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8521 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8522 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8523 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8524 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8525 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8526 | |
| 8527 | HttpRequestInfo restricted_port_request; |
| 8528 | restricted_port_request.method = "GET"; |
| 8529 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8530 | restricted_port_request.load_flags = 0; |
| 8531 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8532 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8533 | StaticSocketDataProvider first_data; |
| 8534 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8535 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8536 | |
| 8537 | MockRead data_reads[] = { |
| 8538 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8539 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8540 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8541 | }; |
| 8542 | StaticSocketDataProvider second_data( |
| 8543 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8544 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8545 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8546 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8547 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8548 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8549 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8550 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8551 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8552 | HostPortPair::FromURL(restricted_port_request.url), |
| 8553 | kUnrestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8554 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8555 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8556 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8557 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8558 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8560 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8561 | &restricted_port_request, |
| 8562 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8563 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8564 | // Invalid change to unrestricted port should fail. |
| 8565 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8566 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8567 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8568 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8569 | AlternateProtocolPortRestrictedPermitted) { |
| 8570 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8571 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8572 | // on a restricted port (port < 1024) if we set |
| 8573 | // enable_user_alternate_protocol_ports. |
| 8574 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8575 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8576 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8577 | |
| 8578 | HttpRequestInfo restricted_port_request; |
| 8579 | restricted_port_request.method = "GET"; |
| 8580 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8581 | restricted_port_request.load_flags = 0; |
| 8582 | |
| 8583 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8584 | StaticSocketDataProvider first_data; |
| 8585 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8586 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8587 | |
| 8588 | MockRead data_reads[] = { |
| 8589 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8590 | MockRead("hello world"), |
| 8591 | MockRead(ASYNC, OK), |
| 8592 | }; |
| 8593 | StaticSocketDataProvider second_data( |
| 8594 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8595 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8596 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8597 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8598 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8599 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8600 | session->http_server_properties(); |
| 8601 | const int kUnrestrictedAlternatePort = 1024; |
| 8602 | http_server_properties->SetAlternateProtocol( |
| 8603 | HostPortPair::FromURL(restricted_port_request.url), |
| 8604 | kUnrestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8605 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8606 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8607 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8609 | TestCompletionCallback callback; |
| 8610 | |
| 8611 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8612 | &restricted_port_request, |
| 8613 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8614 | // Change to unrestricted port should succeed. |
| 8615 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8616 | } |
| 8617 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8618 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8619 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8620 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8621 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8622 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8623 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8624 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8625 | |
| 8626 | HttpRequestInfo restricted_port_request; |
| 8627 | restricted_port_request.method = "GET"; |
| 8628 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8629 | restricted_port_request.load_flags = 0; |
| 8630 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8631 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8632 | StaticSocketDataProvider first_data; |
| 8633 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8634 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8635 | |
| 8636 | MockRead data_reads[] = { |
| 8637 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8638 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8639 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8640 | }; |
| 8641 | StaticSocketDataProvider second_data( |
| 8642 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8643 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8644 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8645 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8646 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8647 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8648 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8649 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8650 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8651 | HostPortPair::FromURL(restricted_port_request.url), |
| 8652 | kRestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8653 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8654 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8655 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8657 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8659 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8660 | &restricted_port_request, |
| 8661 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8662 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8663 | // Valid change to restricted port should pass. |
| 8664 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8665 | } |
| 8666 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8667 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8668 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8669 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8670 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8671 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8672 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8673 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8674 | |
| 8675 | HttpRequestInfo unrestricted_port_request; |
| 8676 | unrestricted_port_request.method = "GET"; |
| 8677 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8678 | unrestricted_port_request.load_flags = 0; |
| 8679 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8680 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8681 | StaticSocketDataProvider first_data; |
| 8682 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8683 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8684 | |
| 8685 | MockRead data_reads[] = { |
| 8686 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8687 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8688 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8689 | }; |
| 8690 | StaticSocketDataProvider second_data( |
| 8691 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8692 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8693 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8694 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8695 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8696 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8697 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8698 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8699 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8700 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8701 | kRestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8702 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8703 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8704 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8705 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8706 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8708 | int rv = trans->Start( |
| 8709 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8711 | // Valid change to restricted port should pass. |
| 8712 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8713 | } |
| 8714 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8715 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8716 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8717 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8718 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8719 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8720 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8721 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8722 | |
| 8723 | HttpRequestInfo unrestricted_port_request; |
| 8724 | unrestricted_port_request.method = "GET"; |
| 8725 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8726 | unrestricted_port_request.load_flags = 0; |
| 8727 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8728 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8729 | StaticSocketDataProvider first_data; |
| 8730 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8731 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8732 | |
| 8733 | MockRead data_reads[] = { |
| 8734 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8735 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8736 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8737 | }; |
| 8738 | StaticSocketDataProvider second_data( |
| 8739 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8740 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8741 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8742 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8743 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8744 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8745 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8746 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8747 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8748 | HostPortPair::FromURL(unrestricted_port_request.url), |
| 8749 | kUnrestrictedAlternatePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8750 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8751 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8752 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8753 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8754 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8756 | int rv = trans->Start( |
| 8757 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8758 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8759 | // Valid change to an unrestricted port should pass. |
| 8760 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8761 | } |
| 8762 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8763 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8764 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8765 | // protocol to an unsafe port, and that we resume the second |
| 8766 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8767 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8768 | |
| 8769 | HttpRequestInfo request; |
| 8770 | request.method = "GET"; |
| 8771 | request.url = GURL("http://www.google.com/"); |
| 8772 | request.load_flags = 0; |
| 8773 | |
| 8774 | // The alternate protocol request will error out before we attempt to connect, |
| 8775 | // so only the standard HTTP request will try to connect. |
| 8776 | MockRead data_reads[] = { |
| 8777 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8778 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8779 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8780 | }; |
| 8781 | StaticSocketDataProvider data( |
| 8782 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8783 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8784 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8785 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8786 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8787 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8788 | session->http_server_properties(); |
| 8789 | const int kUnsafePort = 7; |
| 8790 | http_server_properties->SetAlternateProtocol( |
| 8791 | HostPortPair::FromURL(request.url), |
| 8792 | kUnsafePort, |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8793 | AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8794 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8795 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8796 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8797 | TestCompletionCallback callback; |
| 8798 | |
| 8799 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8801 | // The HTTP request should succeed. |
| 8802 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8803 | |
| 8804 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8805 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8806 | |
| 8807 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8808 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8809 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8810 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8811 | |
| 8812 | std::string response_data; |
| 8813 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8814 | EXPECT_EQ("hello world", response_data); |
| 8815 | } |
| 8816 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8817 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8818 | session_deps_.use_alternate_protocols = true; |
| 8819 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8820 | |
| 8821 | HttpRequestInfo request; |
| 8822 | request.method = "GET"; |
| 8823 | request.url = GURL("http://www.google.com/"); |
| 8824 | request.load_flags = 0; |
| 8825 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8826 | std::string alternate_protocol_http_header = |
| 8827 | GetAlternateProtocolHttpHeader(); |
| 8828 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8829 | MockRead data_reads[] = { |
| 8830 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8831 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8832 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8833 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 8834 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8835 | }; |
| 8836 | |
| 8837 | StaticSocketDataProvider first_transaction( |
| 8838 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8839 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8840 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8841 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8842 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8844 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8845 | scoped_ptr<SpdyFrame> req( |
| 8846 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8847 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8848 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8849 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8850 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8851 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8852 | CreateMockRead(*resp), |
| 8853 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8854 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8855 | }; |
| 8856 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8857 | DelayedSocketData spdy_data( |
| 8858 | 1, // wait for one write to finish before reading. |
| 8859 | spdy_reads, arraysize(spdy_reads), |
| 8860 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8861 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8862 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8863 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8864 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8865 | NULL, 0, NULL, 0); |
| 8866 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8867 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8868 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8869 | &hanging_non_alternate_protocol_socket); |
| 8870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8871 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8872 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8873 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8874 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8875 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8877 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8879 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8880 | |
| 8881 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8882 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8883 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8884 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8885 | |
| 8886 | std::string response_data; |
| 8887 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8888 | EXPECT_EQ("hello world", response_data); |
| 8889 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8890 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8892 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8893 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8894 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8895 | |
| 8896 | response = trans->GetResponseInfo(); |
| 8897 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8898 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8899 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8900 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8901 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8902 | |
| 8903 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8904 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8905 | } |
| 8906 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8907 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8908 | session_deps_.use_alternate_protocols = true; |
| 8909 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8910 | |
| 8911 | HttpRequestInfo request; |
| 8912 | request.method = "GET"; |
| 8913 | request.url = GURL("http://www.google.com/"); |
| 8914 | request.load_flags = 0; |
| 8915 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8916 | std::string alternate_protocol_http_header = |
| 8917 | GetAlternateProtocolHttpHeader(); |
| 8918 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8919 | MockRead data_reads[] = { |
| 8920 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8921 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8922 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8923 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8924 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8925 | }; |
| 8926 | |
| 8927 | StaticSocketDataProvider first_transaction( |
| 8928 | data_reads, arraysize(data_reads), NULL, 0); |
| 8929 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8930 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8931 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8932 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8933 | StaticSocketDataProvider hanging_socket( |
| 8934 | NULL, 0, NULL, 0); |
| 8935 | hanging_socket.set_connect_data(never_finishing_connect); |
| 8936 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 8937 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8938 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 8939 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8940 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8941 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8942 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8943 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8944 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8945 | scoped_ptr<SpdyFrame> req1( |
| 8946 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 8947 | scoped_ptr<SpdyFrame> req2( |
| 8948 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8949 | MockWrite spdy_writes[] = { |
| 8950 | CreateMockWrite(*req1), |
| 8951 | CreateMockWrite(*req2), |
| 8952 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8953 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8954 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 8955 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 8956 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8957 | MockRead spdy_reads[] = { |
| 8958 | CreateMockRead(*resp1), |
| 8959 | CreateMockRead(*data1), |
| 8960 | CreateMockRead(*resp2), |
| 8961 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8962 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8963 | }; |
| 8964 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8965 | DelayedSocketData spdy_data( |
| 8966 | 2, // wait for writes to finish before reading. |
| 8967 | spdy_reads, arraysize(spdy_reads), |
| 8968 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8969 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8970 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8971 | |
| 8972 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8973 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8974 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8975 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8976 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8977 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8979 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8980 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8981 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 8982 | |
| 8983 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 8984 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8985 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8986 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8987 | |
| 8988 | std::string response_data; |
| 8989 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 8990 | EXPECT_EQ("hello world", response_data); |
| 8991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8992 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8993 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8994 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8995 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8997 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8998 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8999 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9000 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9001 | |
| 9002 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9003 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9004 | |
| 9005 | response = trans2.GetResponseInfo(); |
| 9006 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9007 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9008 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9009 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9010 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9011 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9012 | EXPECT_EQ("hello!", response_data); |
| 9013 | |
| 9014 | response = trans3.GetResponseInfo(); |
| 9015 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9016 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9017 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9018 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9019 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9020 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9021 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9022 | } |
| 9023 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9024 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9025 | session_deps_.use_alternate_protocols = true; |
| 9026 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9027 | |
| 9028 | HttpRequestInfo request; |
| 9029 | request.method = "GET"; |
| 9030 | request.url = GURL("http://www.google.com/"); |
| 9031 | request.load_flags = 0; |
| 9032 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9033 | std::string alternate_protocol_http_header = |
| 9034 | GetAlternateProtocolHttpHeader(); |
| 9035 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9036 | MockRead data_reads[] = { |
| 9037 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9038 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9039 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9040 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9041 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9042 | }; |
| 9043 | |
| 9044 | StaticSocketDataProvider first_transaction( |
| 9045 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9046 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9047 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9048 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9049 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9051 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9052 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9053 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9054 | NULL, 0, NULL, 0); |
| 9055 | hanging_alternate_protocol_socket.set_connect_data( |
| 9056 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9057 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9058 | &hanging_alternate_protocol_socket); |
| 9059 | |
| 9060 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9061 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9063 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9064 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9065 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9066 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9069 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9071 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9072 | |
| 9073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9074 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9075 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9077 | |
| 9078 | std::string response_data; |
| 9079 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9080 | EXPECT_EQ("hello world", response_data); |
| 9081 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9082 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9084 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9085 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9086 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9087 | |
| 9088 | response = trans->GetResponseInfo(); |
| 9089 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9090 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9091 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9092 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9093 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9094 | |
| 9095 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9096 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9097 | } |
| 9098 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9099 | class CapturingProxyResolver : public ProxyResolver { |
| 9100 | public: |
| 9101 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9102 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9103 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9104 | int GetProxyForURL(const GURL& url, |
| 9105 | ProxyInfo* results, |
| 9106 | const CompletionCallback& callback, |
| 9107 | RequestHandle* request, |
| 9108 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9109 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9110 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9111 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9112 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9113 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9114 | } |
| 9115 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9116 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9117 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9118 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9119 | NOTREACHED(); |
| 9120 | return LOAD_STATE_IDLE; |
| 9121 | } |
| 9122 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9123 | void CancelSetPacScript() override { NOTREACHED(); } |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 9124 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9125 | int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
| 9126 | const CompletionCallback& /*callback*/) override { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9127 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9128 | } |
| 9129 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9130 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9131 | |
| 9132 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9133 | std::vector<GURL> resolved_; |
| 9134 | |
| 9135 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9136 | }; |
| 9137 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9138 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9139 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9140 | session_deps_.use_alternate_protocols = true; |
| 9141 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9142 | |
| 9143 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9144 | proxy_config.set_auto_detect(true); |
| 9145 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9146 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9147 | CapturingProxyResolver* capturing_proxy_resolver = |
| 9148 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9149 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9150 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 9151 | NULL)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9152 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9153 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9154 | |
| 9155 | HttpRequestInfo request; |
| 9156 | request.method = "GET"; |
| 9157 | request.url = GURL("http://www.google.com/"); |
| 9158 | request.load_flags = 0; |
| 9159 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9160 | std::string alternate_protocol_http_header = |
| 9161 | GetAlternateProtocolHttpHeader(); |
| 9162 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9163 | MockRead data_reads[] = { |
| 9164 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9165 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9166 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9167 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9168 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9169 | }; |
| 9170 | |
| 9171 | StaticSocketDataProvider first_transaction( |
| 9172 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9173 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9174 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9175 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9176 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9178 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9179 | scoped_ptr<SpdyFrame> req( |
| 9180 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9181 | MockWrite spdy_writes[] = { |
| 9182 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9183 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9184 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9185 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9186 | }; |
| 9187 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9188 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9189 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9190 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9191 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9192 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9193 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9194 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 9195 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9196 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9197 | }; |
| 9198 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9199 | OrderedSocketData spdy_data( |
| 9200 | spdy_reads, arraysize(spdy_reads), |
| 9201 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9202 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9203 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9204 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9205 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9206 | NULL, 0, NULL, 0); |
| 9207 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9208 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9209 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9210 | &hanging_non_alternate_protocol_socket); |
| 9211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9212 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9213 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9214 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9215 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9216 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9218 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9220 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9221 | |
| 9222 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9223 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9224 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9225 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9226 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9227 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9228 | |
| 9229 | std::string response_data; |
| 9230 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9231 | EXPECT_EQ("hello world", response_data); |
| 9232 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9233 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9235 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9236 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9237 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9238 | |
| 9239 | response = trans->GetResponseInfo(); |
| 9240 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9241 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9242 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9243 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9244 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9245 | |
| 9246 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9247 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9248 | ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9249 | EXPECT_EQ("http://www.google.com/", |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9250 | capturing_proxy_resolver->resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9251 | EXPECT_EQ("https://www.google.com/", |
| 9252 | capturing_proxy_resolver->resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9253 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9254 | LoadTimingInfo load_timing_info; |
| 9255 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9256 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9257 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9258 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9259 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9260 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9261 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9262 | session_deps_.use_alternate_protocols = true; |
| 9263 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9264 | |
| 9265 | HttpRequestInfo request; |
| 9266 | request.method = "GET"; |
| 9267 | request.url = GURL("http://www.google.com/"); |
| 9268 | request.load_flags = 0; |
| 9269 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9270 | std::string alternate_protocol_http_header = |
| 9271 | GetAlternateProtocolHttpHeader(); |
| 9272 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9273 | MockRead data_reads[] = { |
| 9274 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9275 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9276 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9277 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9278 | }; |
| 9279 | |
| 9280 | StaticSocketDataProvider first_transaction( |
| 9281 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9282 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9283 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9284 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9285 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9287 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9288 | scoped_ptr<SpdyFrame> req( |
| 9289 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9290 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9291 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9292 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9293 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9294 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9295 | CreateMockRead(*resp), |
| 9296 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9297 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9298 | }; |
| 9299 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9300 | DelayedSocketData spdy_data( |
| 9301 | 1, // wait for one write to finish before reading. |
| 9302 | spdy_reads, arraysize(spdy_reads), |
| 9303 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9304 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9305 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9306 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9307 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9308 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9309 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9310 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9313 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9314 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9315 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9316 | |
| 9317 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9318 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9319 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9320 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9321 | |
| 9322 | std::string response_data; |
| 9323 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9324 | EXPECT_EQ("hello world", response_data); |
| 9325 | |
| 9326 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9327 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9328 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9329 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9330 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9331 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9332 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9333 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9335 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9337 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9338 | |
| 9339 | response = trans->GetResponseInfo(); |
| 9340 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9341 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9342 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9343 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9344 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9345 | |
| 9346 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9347 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9348 | } |
| 9349 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9350 | // GenerateAuthToken is a mighty big test. |
| 9351 | // It tests all permutation of GenerateAuthToken behavior: |
| 9352 | // - Synchronous and Asynchronous completion. |
| 9353 | // - OK or error on completion. |
| 9354 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9355 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9356 | // - Non-authenticating and authenticating backend. |
| 9357 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9358 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9359 | // problems generating an auth token for an authenticating proxy, we don't |
| 9360 | // need to test all permutations of the backend server). |
| 9361 | // |
| 9362 | // The test proceeds by going over each of the configuration cases, and |
| 9363 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9364 | // specifies both the configuration for the test as well as the expectations |
| 9365 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9366 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9367 | static const char kServer[] = "http://www.example.com"; |
| 9368 | static const char kSecureServer[] = "https://www.example.com"; |
| 9369 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9370 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9371 | |
| 9372 | enum AuthTiming { |
| 9373 | AUTH_NONE, |
| 9374 | AUTH_SYNC, |
| 9375 | AUTH_ASYNC, |
| 9376 | }; |
| 9377 | |
| 9378 | const MockWrite kGet( |
| 9379 | "GET / HTTP/1.1\r\n" |
| 9380 | "Host: www.example.com\r\n" |
| 9381 | "Connection: keep-alive\r\n\r\n"); |
| 9382 | const MockWrite kGetProxy( |
| 9383 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9384 | "Host: www.example.com\r\n" |
| 9385 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9386 | const MockWrite kGetAuth( |
| 9387 | "GET / HTTP/1.1\r\n" |
| 9388 | "Host: www.example.com\r\n" |
| 9389 | "Connection: keep-alive\r\n" |
| 9390 | "Authorization: auth_token\r\n\r\n"); |
| 9391 | const MockWrite kGetProxyAuth( |
| 9392 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9393 | "Host: www.example.com\r\n" |
| 9394 | "Proxy-Connection: keep-alive\r\n" |
| 9395 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9396 | const MockWrite kGetAuthThroughProxy( |
| 9397 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9398 | "Host: www.example.com\r\n" |
| 9399 | "Proxy-Connection: keep-alive\r\n" |
| 9400 | "Authorization: auth_token\r\n\r\n"); |
| 9401 | const MockWrite kGetAuthWithProxyAuth( |
| 9402 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9403 | "Host: www.example.com\r\n" |
| 9404 | "Proxy-Connection: keep-alive\r\n" |
| 9405 | "Proxy-Authorization: auth_token\r\n" |
| 9406 | "Authorization: auth_token\r\n\r\n"); |
| 9407 | const MockWrite kConnect( |
| 9408 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9409 | "Host: www.example.com\r\n" |
| 9410 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9411 | const MockWrite kConnectProxyAuth( |
| 9412 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9413 | "Host: www.example.com\r\n" |
| 9414 | "Proxy-Connection: keep-alive\r\n" |
| 9415 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9416 | |
| 9417 | const MockRead kSuccess( |
| 9418 | "HTTP/1.1 200 OK\r\n" |
| 9419 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9420 | "Content-Length: 3\r\n\r\n" |
| 9421 | "Yes"); |
| 9422 | const MockRead kFailure( |
| 9423 | "Should not be called."); |
| 9424 | const MockRead kServerChallenge( |
| 9425 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9426 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9427 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9428 | "Content-Length: 14\r\n\r\n" |
| 9429 | "Unauthorized\r\n"); |
| 9430 | const MockRead kProxyChallenge( |
| 9431 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9432 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9433 | "Proxy-Connection: close\r\n" |
| 9434 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9435 | "Content-Length: 14\r\n\r\n" |
| 9436 | "Unauthorized\r\n"); |
| 9437 | const MockRead kProxyConnected( |
| 9438 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9439 | |
| 9440 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9441 | // no constructors, but the C++ compiler on Windows warns about |
| 9442 | // unspecified data in compound literals. So, moved to using constructors, |
| 9443 | // and TestRound's created with the default constructor should not be used. |
| 9444 | struct TestRound { |
| 9445 | TestRound() |
| 9446 | : expected_rv(ERR_UNEXPECTED), |
| 9447 | extra_write(NULL), |
| 9448 | extra_read(NULL) { |
| 9449 | } |
| 9450 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9451 | int expected_rv_arg) |
| 9452 | : write(write_arg), |
| 9453 | read(read_arg), |
| 9454 | expected_rv(expected_rv_arg), |
| 9455 | extra_write(NULL), |
| 9456 | extra_read(NULL) { |
| 9457 | } |
| 9458 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9459 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9460 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9461 | : write(write_arg), |
| 9462 | read(read_arg), |
| 9463 | expected_rv(expected_rv_arg), |
| 9464 | extra_write(extra_write_arg), |
| 9465 | extra_read(extra_read_arg) { |
| 9466 | } |
| 9467 | MockWrite write; |
| 9468 | MockRead read; |
| 9469 | int expected_rv; |
| 9470 | const MockWrite* extra_write; |
| 9471 | const MockRead* extra_read; |
| 9472 | }; |
| 9473 | |
| 9474 | static const int kNoSSL = 500; |
| 9475 | |
| 9476 | struct TestConfig { |
| 9477 | const char* proxy_url; |
| 9478 | AuthTiming proxy_auth_timing; |
| 9479 | int proxy_auth_rv; |
| 9480 | const char* server_url; |
| 9481 | AuthTiming server_auth_timing; |
| 9482 | int server_auth_rv; |
| 9483 | int num_auth_rounds; |
| 9484 | int first_ssl_round; |
| 9485 | TestRound rounds[3]; |
| 9486 | } test_configs[] = { |
| 9487 | // Non-authenticating HTTP server with a direct connection. |
| 9488 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9489 | { TestRound(kGet, kSuccess, OK)}}, |
| 9490 | // Authenticating HTTP server with a direct connection. |
| 9491 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9492 | { TestRound(kGet, kServerChallenge, OK), |
| 9493 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9494 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9495 | { TestRound(kGet, kServerChallenge, OK), |
| 9496 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9497 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9498 | { TestRound(kGet, kServerChallenge, OK), |
| 9499 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9500 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9501 | { TestRound(kGet, kServerChallenge, OK), |
| 9502 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9503 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9504 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9505 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9506 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9507 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9508 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9509 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9510 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9511 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9512 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9513 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9514 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9515 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9516 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9517 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9518 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9519 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9520 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9521 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9522 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9523 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9524 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9525 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9526 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9527 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9528 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9529 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9530 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9531 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9532 | // Authenticating HTTP server through an authenticating proxy. |
| 9533 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9534 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9535 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9536 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9537 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9538 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9539 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9540 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9541 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9542 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9543 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9544 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9545 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9546 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9547 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9548 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9549 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9550 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9551 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9552 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9553 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9554 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9555 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9556 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9557 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9558 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9559 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9560 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9561 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9562 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9563 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9564 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9565 | // Non-authenticating HTTPS server with a direct connection. |
| 9566 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9567 | { TestRound(kGet, kSuccess, OK)}}, |
| 9568 | // Authenticating HTTPS server with a direct connection. |
| 9569 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9570 | { TestRound(kGet, kServerChallenge, OK), |
| 9571 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9572 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9573 | { TestRound(kGet, kServerChallenge, OK), |
| 9574 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9575 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9576 | { TestRound(kGet, kServerChallenge, OK), |
| 9577 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9578 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9579 | { TestRound(kGet, kServerChallenge, OK), |
| 9580 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9581 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9582 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9583 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9584 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9585 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9586 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9587 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9588 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9589 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9590 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9591 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9592 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9593 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9594 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9595 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9596 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9597 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9598 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9599 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9600 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9601 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9602 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9603 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9604 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9605 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9606 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9607 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9608 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9609 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9610 | // Authenticating HTTPS server through an authenticating proxy. |
| 9611 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9612 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9613 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9614 | &kGet, &kServerChallenge), |
| 9615 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9616 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9617 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9618 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9619 | &kGet, &kServerChallenge), |
| 9620 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9621 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9622 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9623 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9624 | &kGet, &kServerChallenge), |
| 9625 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9626 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9627 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9628 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9629 | &kGet, &kServerChallenge), |
| 9630 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9631 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9632 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9633 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9634 | &kGet, &kServerChallenge), |
| 9635 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9636 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9637 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9638 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9639 | &kGet, &kServerChallenge), |
| 9640 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9641 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9642 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9643 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9644 | &kGet, &kServerChallenge), |
| 9645 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9646 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9647 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9648 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9649 | &kGet, &kServerChallenge), |
| 9650 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9651 | }; |
| 9652 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9653 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9654 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9655 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9656 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9657 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9658 | |
| 9659 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9660 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9661 | for (int n = 0; n < 2; n++) { |
| 9662 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9663 | std::string auth_challenge = "Mock realm=proxy"; |
| 9664 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9665 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9666 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9667 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 9668 | origin, BoundNetLog()); |
| 9669 | auth_handler->SetGenerateExpectation( |
| 9670 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 9671 | test_config.proxy_auth_rv); |
| 9672 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9673 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9674 | } |
| 9675 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 9676 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9677 | std::string auth_challenge = "Mock realm=server"; |
| 9678 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9679 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9680 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9681 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9682 | origin, BoundNetLog()); |
| 9683 | auth_handler->SetGenerateExpectation( |
| 9684 | test_config.server_auth_timing == AUTH_ASYNC, |
| 9685 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9686 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9687 | } |
| 9688 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9689 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 9690 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9691 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9692 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9693 | } |
| 9694 | |
| 9695 | HttpRequestInfo request; |
| 9696 | request.method = "GET"; |
| 9697 | request.url = GURL(test_config.server_url); |
| 9698 | request.load_flags = 0; |
| 9699 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9700 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9702 | |
| 9703 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 9704 | const TestRound& read_write_round = test_config.rounds[round]; |
| 9705 | |
| 9706 | // Set up expected reads and writes. |
| 9707 | MockRead reads[2]; |
| 9708 | reads[0] = read_write_round.read; |
| 9709 | size_t length_reads = 1; |
| 9710 | if (read_write_round.extra_read) { |
| 9711 | reads[1] = *read_write_round.extra_read; |
| 9712 | length_reads = 2; |
| 9713 | } |
| 9714 | |
| 9715 | MockWrite writes[2]; |
| 9716 | writes[0] = read_write_round.write; |
| 9717 | size_t length_writes = 1; |
| 9718 | if (read_write_round.extra_write) { |
| 9719 | writes[1] = *read_write_round.extra_write; |
| 9720 | length_writes = 2; |
| 9721 | } |
| 9722 | StaticSocketDataProvider data_provider( |
| 9723 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9724 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9725 | |
| 9726 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9727 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9728 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9729 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9730 | &ssl_socket_data_provider); |
| 9731 | |
| 9732 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9733 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9734 | int rv; |
| 9735 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9736 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9737 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9738 | rv = trans.RestartWithAuth( |
| 9739 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9740 | } |
| 9741 | if (rv == ERR_IO_PENDING) |
| 9742 | rv = callback.WaitForResult(); |
| 9743 | |
| 9744 | // Compare results with expected data. |
| 9745 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9746 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9747 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9748 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9749 | } else { |
| 9750 | EXPECT_TRUE(response == NULL); |
| 9751 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 9752 | continue; |
| 9753 | } |
| 9754 | if (round + 1 < test_config.num_auth_rounds) { |
| 9755 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 9756 | } else { |
| 9757 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9758 | } |
| 9759 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 9760 | } |
| 9761 | } |
| 9762 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9763 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9764 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9765 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9766 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9767 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9768 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 9769 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 9770 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9771 | |
| 9772 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9773 | auth_handler->set_connection_based(true); |
| 9774 | std::string auth_challenge = "Mock realm=server"; |
| 9775 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9776 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9777 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9778 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9779 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9780 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9781 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9782 | int rv = OK; |
| 9783 | const HttpResponseInfo* response = NULL; |
| 9784 | HttpRequestInfo request; |
| 9785 | request.method = "GET"; |
| 9786 | request.url = origin; |
| 9787 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9788 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9789 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9790 | |
| 9791 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 9792 | // to validate that the TCP socket is not released to the pool between |
| 9793 | // each round of multi-round authentication. |
| 9794 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9795 | ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); |
| 9796 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9797 | 50, // Max sockets for pool |
| 9798 | 1, // Max sockets per group |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9799 | &transport_pool_histograms, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9800 | session_deps_.host_resolver.get(), |
| 9801 | session_deps_.socket_factory.get(), |
| 9802 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9803 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 9804 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9805 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 9806 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9807 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9808 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9809 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9810 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9811 | |
| 9812 | const MockWrite kGet( |
| 9813 | "GET / HTTP/1.1\r\n" |
| 9814 | "Host: www.example.com\r\n" |
| 9815 | "Connection: keep-alive\r\n\r\n"); |
| 9816 | const MockWrite kGetAuth( |
| 9817 | "GET / HTTP/1.1\r\n" |
| 9818 | "Host: www.example.com\r\n" |
| 9819 | "Connection: keep-alive\r\n" |
| 9820 | "Authorization: auth_token\r\n\r\n"); |
| 9821 | |
| 9822 | const MockRead kServerChallenge( |
| 9823 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9824 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9825 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9826 | "Content-Length: 14\r\n\r\n" |
| 9827 | "Unauthorized\r\n"); |
| 9828 | const MockRead kSuccess( |
| 9829 | "HTTP/1.1 200 OK\r\n" |
| 9830 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9831 | "Content-Length: 3\r\n\r\n" |
| 9832 | "Yes"); |
| 9833 | |
| 9834 | MockWrite writes[] = { |
| 9835 | // First round |
| 9836 | kGet, |
| 9837 | // Second round |
| 9838 | kGetAuth, |
| 9839 | // Third round |
| 9840 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9841 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9842 | kGetAuth, |
| 9843 | // Competing request |
| 9844 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9845 | }; |
| 9846 | MockRead reads[] = { |
| 9847 | // First round |
| 9848 | kServerChallenge, |
| 9849 | // Second round |
| 9850 | kServerChallenge, |
| 9851 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9852 | kServerChallenge, |
| 9853 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9854 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9855 | // Competing response |
| 9856 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9857 | }; |
| 9858 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 9859 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9860 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9861 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9862 | const char* const kSocketGroup = "www.example.com:80"; |
| 9863 | |
| 9864 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9865 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9866 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9867 | if (rv == ERR_IO_PENDING) |
| 9868 | rv = callback.WaitForResult(); |
| 9869 | EXPECT_EQ(OK, rv); |
| 9870 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9871 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9872 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9873 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9874 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9875 | // In between rounds, another request comes in for the same domain. |
| 9876 | // It should not be able to grab the TCP socket that trans has already |
| 9877 | // claimed. |
| 9878 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9879 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9880 | TestCompletionCallback callback_compete; |
| 9881 | rv = trans_compete->Start( |
| 9882 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9883 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9884 | // callback_compete.WaitForResult at this point would stall forever, |
| 9885 | // since the HttpNetworkTransaction does not release the request back to |
| 9886 | // the pool until after authentication completes. |
| 9887 | |
| 9888 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9889 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9890 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9891 | if (rv == ERR_IO_PENDING) |
| 9892 | rv = callback.WaitForResult(); |
| 9893 | EXPECT_EQ(OK, rv); |
| 9894 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9895 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9896 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9897 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9898 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9899 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9900 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9901 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9902 | if (rv == ERR_IO_PENDING) |
| 9903 | rv = callback.WaitForResult(); |
| 9904 | EXPECT_EQ(OK, rv); |
| 9905 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9906 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9907 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9908 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9909 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9910 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9911 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9912 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9913 | if (rv == ERR_IO_PENDING) |
| 9914 | rv = callback.WaitForResult(); |
| 9915 | EXPECT_EQ(OK, rv); |
| 9916 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9917 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9918 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9919 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9920 | |
| 9921 | // Read the body since the fourth round was successful. This will also |
| 9922 | // release the socket back to the pool. |
| 9923 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9924 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9925 | if (rv == ERR_IO_PENDING) |
| 9926 | rv = callback.WaitForResult(); |
| 9927 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9928 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9929 | EXPECT_EQ(0, rv); |
| 9930 | // There are still 0 idle sockets, since the trans_compete transaction |
| 9931 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9932 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9933 | |
| 9934 | // The competing request can now finish. Wait for the headers and then |
| 9935 | // read the body. |
| 9936 | rv = callback_compete.WaitForResult(); |
| 9937 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9938 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9939 | if (rv == ERR_IO_PENDING) |
| 9940 | rv = callback.WaitForResult(); |
| 9941 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9942 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9943 | EXPECT_EQ(0, rv); |
| 9944 | |
| 9945 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9946 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9947 | } |
| 9948 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9949 | // This tests the case that a request is issued via http instead of spdy after |
| 9950 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9951 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9952 | session_deps_.use_alternate_protocols = true; |
| 9953 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 9954 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9955 | session_deps_.next_protos = next_protos; |
| 9956 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9957 | HttpRequestInfo request; |
| 9958 | request.method = "GET"; |
| 9959 | request.url = GURL("https://www.google.com/"); |
| 9960 | request.load_flags = 0; |
| 9961 | |
| 9962 | MockWrite data_writes[] = { |
| 9963 | MockWrite("GET / HTTP/1.1\r\n" |
| 9964 | "Host: www.google.com\r\n" |
| 9965 | "Connection: keep-alive\r\n\r\n"), |
| 9966 | }; |
| 9967 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9968 | std::string alternate_protocol_http_header = |
| 9969 | GetAlternateProtocolHttpHeader(); |
| 9970 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9971 | MockRead data_reads[] = { |
| 9972 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9973 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9974 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9975 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9976 | }; |
| 9977 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9978 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9979 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 9980 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 9981 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9982 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9984 | |
| 9985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9986 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9989 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9990 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9991 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9992 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9995 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9996 | |
| 9997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9998 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9999 | |
| 10000 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10001 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10002 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10003 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10004 | |
| 10005 | std::string response_data; |
| 10006 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10007 | EXPECT_EQ("hello world", response_data); |
| 10008 | |
| 10009 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10010 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10011 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10012 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10013 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10014 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10015 | // followed by an immediate server closing of the socket. |
| 10016 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10017 | session_deps_.use_alternate_protocols = true; |
| 10018 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10019 | |
| 10020 | HttpRequestInfo request; |
| 10021 | request.method = "GET"; |
| 10022 | request.url = GURL("https://www.google.com/"); |
| 10023 | request.load_flags = 0; |
| 10024 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10025 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10026 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10027 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10028 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10029 | scoped_ptr<SpdyFrame> req( |
| 10030 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 10031 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10032 | |
| 10033 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10034 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10035 | }; |
| 10036 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10037 | DelayedSocketData spdy_data( |
| 10038 | 0, // don't wait in this case, immediate hangup. |
| 10039 | spdy_reads, arraysize(spdy_reads), |
| 10040 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10041 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10043 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10044 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10045 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10046 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10047 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10049 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10050 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10051 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10052 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10053 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10054 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10055 | // it gets it. This is needed since the auth handler may get destroyed |
| 10056 | // before we get a chance to query it. |
| 10057 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10058 | public: |
| 10059 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10060 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10061 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10062 | |
| 10063 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10064 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10065 | const HttpRequestInfo* request, |
| 10066 | const CompletionCallback& callback, |
| 10067 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10068 | *url_ = request->url; |
| 10069 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10070 | credentials, request, callback, auth_token); |
| 10071 | } |
| 10072 | |
| 10073 | private: |
| 10074 | GURL* url_; |
| 10075 | }; |
| 10076 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10077 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10078 | // This test ensures that the URL passed into the proxy is upgraded |
| 10079 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10080 | session_deps_.use_alternate_protocols = true; |
| 10081 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10082 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10083 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10084 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 10085 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10086 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10087 | GURL request_url; |
| 10088 | { |
| 10089 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10090 | new HttpAuthHandlerMock::Factory(); |
| 10091 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10092 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10093 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10094 | auth_factory->set_do_init_from_challenge(true); |
| 10095 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10096 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10097 | |
| 10098 | HttpRequestInfo request; |
| 10099 | request.method = "GET"; |
| 10100 | request.url = GURL("http://www.google.com"); |
| 10101 | request.load_flags = 0; |
| 10102 | |
| 10103 | // First round goes unauthenticated through the proxy. |
| 10104 | MockWrite data_writes_1[] = { |
| 10105 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10106 | "Host: www.google.com\r\n" |
| 10107 | "Proxy-Connection: keep-alive\r\n" |
| 10108 | "\r\n"), |
| 10109 | }; |
| 10110 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10111 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10112 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10113 | MockRead("Alternate-Protocol: 443:"), |
| 10114 | MockRead(GetAlternateProtocolFromParam()), |
| 10115 | MockRead("\r\n"), |
| 10116 | MockRead("Proxy-Connection: close\r\n"), |
| 10117 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10118 | }; |
| 10119 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10120 | data_writes_1, arraysize(data_writes_1)); |
| 10121 | |
| 10122 | // Second round tries to tunnel to www.google.com due to the |
| 10123 | // Alternate-Protocol announcement in the first round. It fails due |
| 10124 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10125 | // After the failure, a tunnel is established to www.google.com using |
| 10126 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10127 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10128 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10129 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10130 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10131 | // to obtain a new one. |
| 10132 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10133 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10134 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10135 | // establishment and SPDY framing issues. Alas, the |
| 10136 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10137 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10138 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10139 | scoped_ptr<SpdyFrame> req( |
| 10140 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10141 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10142 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10143 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10144 | MockWrite data_writes_2[] = { |
| 10145 | // First connection attempt without Proxy-Authorization. |
| 10146 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10147 | "Host: www.google.com\r\n" |
| 10148 | "Proxy-Connection: keep-alive\r\n" |
| 10149 | "\r\n"), |
| 10150 | |
| 10151 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10152 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10153 | "Host: www.google.com\r\n" |
| 10154 | "Proxy-Connection: keep-alive\r\n" |
| 10155 | "Proxy-Authorization: auth_token\r\n" |
| 10156 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10157 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10158 | // SPDY request |
| 10159 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10160 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10161 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10162 | "Proxy-Authenticate: Mock\r\n" |
| 10163 | "Proxy-Connection: close\r\n" |
| 10164 | "\r\n"); |
| 10165 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10166 | MockRead data_reads_2[] = { |
| 10167 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10168 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 10169 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10170 | arraysize(kRejectConnectResponse) - 1, 1), |
| 10171 | |
| 10172 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10173 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10174 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10175 | |
| 10176 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10177 | CreateMockRead(*resp.get(), 6), |
| 10178 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10179 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10180 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10181 | OrderedSocketData data_2( |
| 10182 | data_reads_2, arraysize(data_reads_2), |
| 10183 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10184 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10185 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10186 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10187 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10188 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10189 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10190 | NULL, 0, NULL, 0); |
| 10191 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10192 | never_finishing_connect); |
| 10193 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10194 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10195 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10197 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10198 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10199 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10200 | |
| 10201 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10202 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10203 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10205 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10206 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10207 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10208 | |
| 10209 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10210 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10211 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10212 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10213 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10214 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10215 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10216 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10217 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10218 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10219 | |
| 10220 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10221 | TestCompletionCallback callback_3; |
| 10222 | rv = trans_2->RestartWithAuth( |
| 10223 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10224 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10225 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10226 | |
| 10227 | // After all that work, these two lines (or actually, just the scheme) are |
| 10228 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10229 | EXPECT_EQ("https", request_url.scheme()); |
| 10230 | EXPECT_EQ("www.google.com", request_url.host()); |
| 10231 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10232 | LoadTimingInfo load_timing_info; |
| 10233 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10234 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10235 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10236 | } |
| 10237 | |
| 10238 | // Test that if we cancel the transaction as the connection is completing, that |
| 10239 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10240 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10241 | // Setup everything about the connection to complete synchronously, so that |
| 10242 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10243 | // for is the callback from the HttpStreamRequest. |
| 10244 | // Then cancel the transaction. |
| 10245 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10246 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10247 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10248 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10249 | MockRead(SYNCHRONOUS, "hello world"), |
| 10250 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10251 | }; |
| 10252 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10253 | HttpRequestInfo request; |
| 10254 | request.method = "GET"; |
| 10255 | request.url = GURL("http://www.google.com/"); |
| 10256 | request.load_flags = 0; |
| 10257 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10258 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10259 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10260 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10262 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10264 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10266 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10267 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10268 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10269 | CapturingBoundNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10270 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10271 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10272 | trans.reset(); // Cancel the transaction here. |
| 10273 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10274 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10275 | } |
| 10276 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10277 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10278 | // stream is drained properly and added back to the socket pool. The main |
| 10279 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10280 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10281 | // deleted. |
| 10282 | // See http://crbug.com/368418 |
| 10283 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10284 | MockRead data_reads[] = { |
| 10285 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10286 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10287 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10288 | MockRead(ASYNC, "1"), |
| 10289 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10290 | // HttpNetworkTransaction has been deleted. |
| 10291 | MockRead(ASYNC, "2"), |
| 10292 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10293 | }; |
| 10294 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10296 | |
| 10297 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10298 | |
| 10299 | { |
| 10300 | HttpRequestInfo request; |
| 10301 | request.method = "GET"; |
| 10302 | request.url = GURL("http://www.google.com/"); |
| 10303 | request.load_flags = 0; |
| 10304 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10306 | TestCompletionCallback callback; |
| 10307 | |
| 10308 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10309 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10310 | callback.WaitForResult(); |
| 10311 | |
| 10312 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10313 | ASSERT_TRUE(response != NULL); |
| 10314 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10315 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10316 | |
| 10317 | // The transaction and HttpRequestInfo are deleted. |
| 10318 | } |
| 10319 | |
| 10320 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10321 | base::MessageLoop::current()->RunUntilIdle(); |
| 10322 | |
| 10323 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10324 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10325 | } |
| 10326 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10327 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10328 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10329 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10330 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10331 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10332 | session_deps_.net_log = log.bound().net_log(); |
| 10333 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10334 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10335 | HttpRequestInfo request; |
| 10336 | request.method = "GET"; |
| 10337 | request.url = GURL("http://www.google.com/"); |
| 10338 | |
| 10339 | MockWrite data_writes1[] = { |
| 10340 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10341 | "Host: www.google.com\r\n" |
| 10342 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10343 | }; |
| 10344 | |
| 10345 | MockRead data_reads1[] = { |
| 10346 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10347 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10348 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10349 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10350 | }; |
| 10351 | |
| 10352 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10353 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10354 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10356 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10357 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10358 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10359 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10360 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10361 | trans->SetBeforeProxyHeadersSentCallback( |
| 10362 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10363 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10365 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10366 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10367 | |
| 10368 | rv = callback1.WaitForResult(); |
| 10369 | EXPECT_EQ(OK, rv); |
| 10370 | |
| 10371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10372 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10373 | |
| 10374 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10375 | EXPECT_EQ(200, response->headers->response_code()); |
| 10376 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10377 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10378 | EXPECT_TRUE( |
| 10379 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10380 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10381 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10382 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10383 | |
| 10384 | LoadTimingInfo load_timing_info; |
| 10385 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10386 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10387 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10388 | } |
| 10389 | |
| 10390 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10391 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10392 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10393 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10394 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10395 | session_deps_.net_log = log.bound().net_log(); |
| 10396 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10397 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10398 | HttpRequestInfo request; |
| 10399 | request.method = "GET"; |
| 10400 | request.url = GURL("https://www.google.com/"); |
| 10401 | |
| 10402 | // Since we have proxy, should try to establish tunnel. |
| 10403 | MockWrite data_writes1[] = { |
| 10404 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10405 | "Host: www.google.com\r\n" |
| 10406 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10407 | |
| 10408 | MockWrite("GET / HTTP/1.1\r\n" |
| 10409 | "Host: www.google.com\r\n" |
| 10410 | "Connection: keep-alive\r\n\r\n"), |
| 10411 | }; |
| 10412 | |
| 10413 | MockRead data_reads1[] = { |
| 10414 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 10415 | |
| 10416 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10417 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10418 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10419 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10420 | }; |
| 10421 | |
| 10422 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10423 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10424 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10425 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10428 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10429 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10430 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10431 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10433 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10434 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10435 | |
| 10436 | rv = callback1.WaitForResult(); |
| 10437 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10438 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10439 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10440 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10441 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10442 | NetLog::PHASE_NONE); |
| 10443 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10444 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10445 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10446 | NetLog::PHASE_NONE); |
| 10447 | |
| 10448 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10449 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10450 | |
| 10451 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10452 | EXPECT_EQ(200, response->headers->response_code()); |
| 10453 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10454 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10455 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10456 | EXPECT_TRUE( |
| 10457 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10458 | |
| 10459 | LoadTimingInfo load_timing_info; |
| 10460 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10461 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10462 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10463 | } |
| 10464 | |
| 10465 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 10466 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10467 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10468 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10469 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10470 | session_deps_.net_log = log.bound().net_log(); |
| 10471 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10472 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10473 | HttpRequestInfo request; |
| 10474 | request.method = "GET"; |
| 10475 | request.url = GURL("https://www.google.com/"); |
| 10476 | |
| 10477 | // Since we have proxy, should try to establish tunnel. |
| 10478 | MockWrite data_writes1[] = { |
| 10479 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10480 | "Host: www.google.com\r\n" |
| 10481 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10482 | |
| 10483 | MockWrite("GET / HTTP/1.1\r\n" |
| 10484 | "Host: www.google.com\r\n" |
| 10485 | "Connection: keep-alive\r\n\r\n"), |
| 10486 | }; |
| 10487 | |
| 10488 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10489 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10490 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10491 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10492 | }; |
| 10493 | |
| 10494 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10495 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10497 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10500 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10501 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10502 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10503 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10505 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10506 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10507 | |
| 10508 | rv = callback1.WaitForResult(); |
| 10509 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10510 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10511 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10512 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10513 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10514 | NetLog::PHASE_NONE); |
| 10515 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10516 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10517 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10518 | NetLog::PHASE_NONE); |
| 10519 | } |
| 10520 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10521 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10522 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10523 | scoped_ptr<SpdyFrame> req( |
| 10524 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10525 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 10526 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10527 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10528 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10529 | MockRead spdy_reads[] = { |
| 10530 | CreateMockRead(*resp), |
| 10531 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10532 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10533 | }; |
| 10534 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10535 | DelayedSocketData spdy_data( |
| 10536 | 1, // wait for one write to finish before reading. |
| 10537 | spdy_reads, arraysize(spdy_reads), |
| 10538 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10539 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10540 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10541 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10542 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10543 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10544 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10545 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10546 | |
| 10547 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10548 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10549 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10550 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10551 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10552 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10553 | |
| 10554 | HttpRequestInfo request; |
| 10555 | request.method = "GET"; |
| 10556 | request.url = GURL("https://www.google.com/"); |
| 10557 | request.load_flags = 0; |
| 10558 | |
| 10559 | // This is the important line that marks this as a preconnect. |
| 10560 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10561 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10562 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10563 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10564 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10565 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10566 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10568 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10569 | } |
| 10570 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10571 | // Given a net error, cause that error to be returned from the first Write() |
| 10572 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10573 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10574 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10575 | net::HttpRequestInfo request_info; |
| 10576 | request_info.url = GURL("https://www.example.com/"); |
| 10577 | request_info.method = "GET"; |
| 10578 | request_info.load_flags = net::LOAD_NORMAL; |
| 10579 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10580 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10581 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10582 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10583 | }; |
| 10584 | net::StaticSocketDataProvider data(NULL, 0, |
| 10585 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10588 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10589 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10590 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10593 | TestCompletionCallback callback; |
| 10594 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10595 | if (rv == net::ERR_IO_PENDING) |
| 10596 | rv = callback.WaitForResult(); |
| 10597 | ASSERT_EQ(error, rv); |
| 10598 | } |
| 10599 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10600 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10601 | // Just check a grab bag of cert errors. |
| 10602 | static const int kErrors[] = { |
| 10603 | ERR_CERT_COMMON_NAME_INVALID, |
| 10604 | ERR_CERT_AUTHORITY_INVALID, |
| 10605 | ERR_CERT_DATE_INVALID, |
| 10606 | }; |
| 10607 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10608 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10609 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10610 | } |
| 10611 | } |
| 10612 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10613 | // Ensure that a client certificate is removed from the SSL client auth |
| 10614 | // cache when: |
| 10615 | // 1) No proxy is involved. |
| 10616 | // 2) TLS False Start is disabled. |
| 10617 | // 3) The initial TLS handshake requests a client certificate. |
| 10618 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10619 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10620 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10621 | net::HttpRequestInfo request_info; |
| 10622 | request_info.url = GURL("https://www.example.com/"); |
| 10623 | request_info.method = "GET"; |
| 10624 | request_info.load_flags = net::LOAD_NORMAL; |
| 10625 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10626 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10627 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10628 | |
| 10629 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 10630 | // CertificateRequest is received for the first time, the handshake will |
| 10631 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10632 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10633 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10635 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10637 | |
| 10638 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 10639 | // False Start is not being used, the result of the SSL handshake will be |
| 10640 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 10641 | // matches the result of a server sending a handshake_failure alert, |
| 10642 | // rather than a Finished message, because it requires a client |
| 10643 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10644 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10645 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10647 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10648 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10649 | |
| 10650 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 10651 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10652 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 10653 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10654 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10655 | // requiring a client certificate, this fallback handshake should also |
| 10656 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10657 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10658 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10660 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10661 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10662 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10663 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 10664 | // connection to a server fails during an SSL handshake, |
| 10665 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 10666 | // connection was attempted with TLSv1. This is transparent to the caller |
| 10667 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10668 | // requiring a client certificate, this fallback handshake should also |
| 10669 | // fail. |
| 10670 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10671 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10672 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10673 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10674 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10675 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10676 | // Need one more if TLSv1.2 is enabled. |
| 10677 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10678 | ssl_data5.cert_request_info = cert_request.get(); |
| 10679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10680 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 10681 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10682 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10683 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10684 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10686 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10687 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10688 | TestCompletionCallback callback; |
| 10689 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10690 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10691 | |
| 10692 | // Complete the SSL handshake, which should abort due to requiring a |
| 10693 | // client certificate. |
| 10694 | rv = callback.WaitForResult(); |
| 10695 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10696 | |
| 10697 | // Indicate that no certificate should be supplied. From the perspective |
| 10698 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10699 | // certificate, so this is the same as supply a |
| 10700 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10701 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10702 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10703 | |
| 10704 | // Ensure the certificate was added to the client auth cache before |
| 10705 | // allowing the connection to continue restarting. |
| 10706 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10707 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10708 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10709 | ASSERT_EQ(NULL, client_cert.get()); |
| 10710 | |
| 10711 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10712 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10713 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10714 | rv = callback.WaitForResult(); |
| 10715 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10716 | |
| 10717 | // Ensure that the client certificate is removed from the cache on a |
| 10718 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10719 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10720 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10721 | } |
| 10722 | |
| 10723 | // Ensure that a client certificate is removed from the SSL client auth |
| 10724 | // cache when: |
| 10725 | // 1) No proxy is involved. |
| 10726 | // 2) TLS False Start is enabled. |
| 10727 | // 3) The initial TLS handshake requests a client certificate. |
| 10728 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10729 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10730 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10731 | net::HttpRequestInfo request_info; |
| 10732 | request_info.url = GURL("https://www.example.com/"); |
| 10733 | request_info.method = "GET"; |
| 10734 | request_info.load_flags = net::LOAD_NORMAL; |
| 10735 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10736 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10737 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10738 | |
| 10739 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 10740 | // return successfully after reading up to the peer's Certificate message. |
| 10741 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 10742 | // enqueue application data to be sent in the same packet as the |
| 10743 | // ChangeCipherSpec and Finished messages. |
| 10744 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 10745 | // called, which expects to process the peer's ChangeCipherSpec and |
| 10746 | // Finished messages. If there was an error negotiating with the peer, |
| 10747 | // such as due to the peer requiring a client certificate when none was |
| 10748 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 10749 | // called. |
| 10750 | |
| 10751 | // Like the non-False Start case, when a client certificate is requested by |
| 10752 | // the peer, the handshake is aborted during the Connect() call. |
| 10753 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10754 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10755 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10756 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10757 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10758 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10759 | |
| 10760 | // When a client certificate is supplied, Connect() will not be aborted |
| 10761 | // when the peer requests the certificate. Instead, the handshake will |
| 10762 | // artificially succeed, allowing the caller to write the HTTP request to |
| 10763 | // the socket. The handshake messages are not processed until Read() is |
| 10764 | // called, which then detects that the handshake was aborted, due to the |
| 10765 | // peer sending a handshake_failure because it requires a client |
| 10766 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10767 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10768 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10770 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10771 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10772 | }; |
| 10773 | net::StaticSocketDataProvider data2( |
| 10774 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10775 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10776 | |
| 10777 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10778 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 10779 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10780 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10781 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10783 | net::StaticSocketDataProvider data3( |
| 10784 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10785 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10786 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10787 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 10788 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 10789 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 10790 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10792 | net::StaticSocketDataProvider data4( |
| 10793 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10794 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10795 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10796 | // Need one more if TLSv1.2 is enabled. |
| 10797 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 10798 | ssl_data5.cert_request_info = cert_request.get(); |
| 10799 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10800 | net::StaticSocketDataProvider data5( |
| 10801 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 10802 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10803 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10804 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10805 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10806 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10807 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10808 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10809 | TestCompletionCallback callback; |
| 10810 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10811 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10812 | |
| 10813 | // Complete the SSL handshake, which should abort due to requiring a |
| 10814 | // client certificate. |
| 10815 | rv = callback.WaitForResult(); |
| 10816 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10817 | |
| 10818 | // Indicate that no certificate should be supplied. From the perspective |
| 10819 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10820 | // certificate, so this is the same as supply a |
| 10821 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10822 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10823 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10824 | |
| 10825 | // Ensure the certificate was added to the client auth cache before |
| 10826 | // allowing the connection to continue restarting. |
| 10827 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10828 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10829 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10830 | ASSERT_EQ(NULL, client_cert.get()); |
| 10831 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10832 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10833 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10834 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10835 | rv = callback.WaitForResult(); |
| 10836 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10837 | |
| 10838 | // Ensure that the client certificate is removed from the cache on a |
| 10839 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10840 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10841 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10842 | } |
| 10843 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10844 | // Ensure that a client certificate is removed from the SSL client auth |
| 10845 | // cache when: |
| 10846 | // 1) An HTTPS proxy is involved. |
| 10847 | // 3) The HTTPS proxy requests a client certificate. |
| 10848 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 10849 | // proxy. |
| 10850 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 10851 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10852 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10853 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10854 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10855 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10856 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10857 | |
| 10858 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10859 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10860 | |
| 10861 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 10862 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 10863 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 10864 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10865 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10866 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10867 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10868 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10870 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10871 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10872 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10874 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10875 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10876 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10877 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 10878 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10879 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10880 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10882 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10883 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10884 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10885 | |
| 10886 | net::HttpRequestInfo requests[2]; |
| 10887 | requests[0].url = GURL("https://www.example.com/"); |
| 10888 | requests[0].method = "GET"; |
| 10889 | requests[0].load_flags = net::LOAD_NORMAL; |
| 10890 | |
| 10891 | requests[1].url = GURL("http://www.example.com/"); |
| 10892 | requests[1].method = "GET"; |
| 10893 | requests[1].load_flags = net::LOAD_NORMAL; |
| 10894 | |
| 10895 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10896 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 10897 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10898 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10899 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10900 | |
| 10901 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10902 | TestCompletionCallback callback; |
| 10903 | int rv = trans->Start( |
| 10904 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10905 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10906 | |
| 10907 | // Complete the SSL handshake, which should abort due to requiring a |
| 10908 | // client certificate. |
| 10909 | rv = callback.WaitForResult(); |
| 10910 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10911 | |
| 10912 | // Indicate that no certificate should be supplied. From the perspective |
| 10913 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10914 | // certificate, so this is the same as supply a |
| 10915 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10916 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10917 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10918 | |
| 10919 | // Ensure the certificate was added to the client auth cache before |
| 10920 | // allowing the connection to continue restarting. |
| 10921 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10922 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10923 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10924 | ASSERT_EQ(NULL, client_cert.get()); |
| 10925 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 10926 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10927 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10928 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10929 | |
| 10930 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 10931 | // then consume ssl_data3, which should also fail. The result code is |
| 10932 | // checked against what ssl_data3 should return. |
| 10933 | rv = callback.WaitForResult(); |
| 10934 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 10935 | |
| 10936 | // Now that the new handshake has failed, ensure that the client |
| 10937 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10938 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10939 | HostPortPair("proxy", 70), &client_cert)); |
| 10940 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10941 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10942 | } |
| 10943 | } |
| 10944 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10945 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 10946 | // TEST_P is a macro that expands directly to code that stringizes the |
| 10947 | // arguments. As a result, macros passed as parameters (such as prefix |
| 10948 | // or test_case_name) will not be expanded by the preprocessor. To |
| 10949 | // work around this, indirect the macro for TEST_P, so that the |
| 10950 | // pre-processor will expand macros such as MAYBE_test_name before |
| 10951 | // instantiating the test. |
| 10952 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 10953 | TEST_P(test_case_name, test_name) |
| 10954 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 10955 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 10956 | #if defined(OS_WIN) |
| 10957 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 10958 | #else |
| 10959 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 10960 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10961 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10962 | session_deps_.use_alternate_protocols = true; |
| 10963 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10964 | |
| 10965 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10966 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 10967 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 10968 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 10969 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10970 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10971 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10972 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10973 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10974 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10975 | scoped_ptr<SpdyFrame> host1_req( |
| 10976 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 10977 | scoped_ptr<SpdyFrame> host2_req( |
| 10978 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10979 | MockWrite spdy_writes[] = { |
| 10980 | CreateMockWrite(*host1_req, 1), |
| 10981 | CreateMockWrite(*host2_req, 4), |
| 10982 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10983 | scoped_ptr<SpdyFrame> host1_resp( |
| 10984 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10985 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 10986 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10987 | scoped_ptr<SpdyFrame> host2_resp( |
| 10988 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10989 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 10990 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10991 | MockRead spdy_reads[] = { |
| 10992 | CreateMockRead(*host1_resp, 2), |
| 10993 | CreateMockRead(*host1_resp_body, 3), |
| 10994 | CreateMockRead(*host2_resp, 5), |
| 10995 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10996 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 10997 | }; |
| 10998 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 10999 | IPAddressNumber ip; |
| 11000 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11001 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11002 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11003 | OrderedSocketData spdy_data( |
| 11004 | connect, |
| 11005 | spdy_reads, arraysize(spdy_reads), |
| 11006 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11007 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11008 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11009 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11010 | HttpRequestInfo request1; |
| 11011 | request1.method = "GET"; |
| 11012 | request1.url = GURL("https://www.google.com/"); |
| 11013 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11014 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11016 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11017 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11018 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11019 | |
| 11020 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11021 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11022 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11023 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11024 | |
| 11025 | std::string response_data; |
| 11026 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11027 | EXPECT_EQ("hello!", response_data); |
| 11028 | |
| 11029 | // Preload www.gmail.com into HostCache. |
| 11030 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11031 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11032 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11033 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11034 | DEFAULT_PRIORITY, |
| 11035 | &ignored, |
| 11036 | callback.callback(), |
| 11037 | NULL, |
| 11038 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11039 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11040 | rv = callback.WaitForResult(); |
| 11041 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11042 | |
| 11043 | HttpRequestInfo request2; |
| 11044 | request2.method = "GET"; |
| 11045 | request2.url = GURL("https://www.gmail.com/"); |
| 11046 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11047 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11049 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11050 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11051 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11052 | |
| 11053 | response = trans2.GetResponseInfo(); |
| 11054 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11055 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11056 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11057 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11058 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11059 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11060 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11061 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11062 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11063 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11064 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11065 | session_deps_.use_alternate_protocols = true; |
| 11066 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11067 | |
| 11068 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11069 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11070 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11071 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11072 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11073 | |
| 11074 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11075 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11076 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11077 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11078 | scoped_ptr<SpdyFrame> host1_req( |
| 11079 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11080 | scoped_ptr<SpdyFrame> host2_req( |
| 11081 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11082 | MockWrite spdy_writes[] = { |
| 11083 | CreateMockWrite(*host1_req, 1), |
| 11084 | CreateMockWrite(*host2_req, 4), |
| 11085 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11086 | scoped_ptr<SpdyFrame> host1_resp( |
| 11087 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11088 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11089 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11090 | scoped_ptr<SpdyFrame> host2_resp( |
| 11091 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11092 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11093 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11094 | MockRead spdy_reads[] = { |
| 11095 | CreateMockRead(*host1_resp, 2), |
| 11096 | CreateMockRead(*host1_resp_body, 3), |
| 11097 | CreateMockRead(*host2_resp, 5), |
| 11098 | CreateMockRead(*host2_resp_body, 6), |
| 11099 | MockRead(ASYNC, 0, 7), |
| 11100 | }; |
| 11101 | |
| 11102 | IPAddressNumber ip; |
| 11103 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11104 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11105 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11106 | OrderedSocketData spdy_data( |
| 11107 | connect, |
| 11108 | spdy_reads, arraysize(spdy_reads), |
| 11109 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11110 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11111 | |
| 11112 | TestCompletionCallback callback; |
| 11113 | HttpRequestInfo request1; |
| 11114 | request1.method = "GET"; |
| 11115 | request1.url = GURL("https://www.google.com/"); |
| 11116 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11117 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11118 | |
| 11119 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11120 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11121 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11122 | |
| 11123 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11124 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11125 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11126 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11127 | |
| 11128 | std::string response_data; |
| 11129 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11130 | EXPECT_EQ("hello!", response_data); |
| 11131 | |
| 11132 | HttpRequestInfo request2; |
| 11133 | request2.method = "GET"; |
| 11134 | request2.url = GURL("https://www.gmail.com/"); |
| 11135 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11136 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11137 | |
| 11138 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11139 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11140 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11141 | |
| 11142 | response = trans2.GetResponseInfo(); |
| 11143 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11144 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11146 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11147 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11148 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11149 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11150 | } |
| 11151 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11152 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 11153 | public: |
| 11154 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11155 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11156 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11157 | |
| 11158 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11159 | |
| 11160 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11161 | int Resolve(const RequestInfo& info, |
| 11162 | RequestPriority priority, |
| 11163 | AddressList* addresses, |
| 11164 | const CompletionCallback& callback, |
| 11165 | RequestHandle* out_req, |
| 11166 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11167 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11168 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11169 | } |
| 11170 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11171 | int ResolveFromCache(const RequestInfo& info, |
| 11172 | AddressList* addresses, |
| 11173 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11174 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11175 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11176 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11177 | return rv; |
| 11178 | } |
| 11179 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11180 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11181 | host_resolver_.CancelRequest(req); |
| 11182 | } |
| 11183 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11184 | MockCachingHostResolver* GetMockHostResolver() { |
| 11185 | return &host_resolver_; |
| 11186 | } |
| 11187 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11188 | private: |
| 11189 | MockCachingHostResolver host_resolver_; |
| 11190 | const HostPortPair host_port_; |
| 11191 | }; |
| 11192 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11193 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11194 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11195 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11196 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11197 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11198 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11199 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11200 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11201 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 11202 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11203 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 11204 | // prefix doesn't work with parametrized tests). |
| 11205 | #if defined(OS_WIN) |
| 11206 | return; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11207 | #else |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11208 | session_deps_.use_alternate_protocols = true; |
| 11209 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11210 | |
| 11211 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11212 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11213 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11214 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11215 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11216 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11217 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11218 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11219 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11220 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11221 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11222 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11223 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11224 | scoped_ptr<SpdyFrame> host1_req( |
| 11225 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11226 | scoped_ptr<SpdyFrame> host2_req( |
| 11227 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11228 | MockWrite spdy_writes[] = { |
| 11229 | CreateMockWrite(*host1_req, 1), |
| 11230 | CreateMockWrite(*host2_req, 4), |
| 11231 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11232 | scoped_ptr<SpdyFrame> host1_resp( |
| 11233 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11234 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11235 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11236 | scoped_ptr<SpdyFrame> host2_resp( |
| 11237 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11238 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11239 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11240 | MockRead spdy_reads[] = { |
| 11241 | CreateMockRead(*host1_resp, 2), |
| 11242 | CreateMockRead(*host1_resp_body, 3), |
| 11243 | CreateMockRead(*host2_resp, 5), |
| 11244 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11245 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11246 | }; |
| 11247 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11248 | IPAddressNumber ip; |
| 11249 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11250 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11251 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11252 | OrderedSocketData spdy_data( |
| 11253 | connect, |
| 11254 | spdy_reads, arraysize(spdy_reads), |
| 11255 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11256 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11257 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11258 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11259 | HttpRequestInfo request1; |
| 11260 | request1.method = "GET"; |
| 11261 | request1.url = GURL("https://www.google.com/"); |
| 11262 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11263 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11265 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11266 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11267 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11268 | |
| 11269 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11270 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11271 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11272 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11273 | |
| 11274 | std::string response_data; |
| 11275 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11276 | EXPECT_EQ("hello!", response_data); |
| 11277 | |
| 11278 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11279 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11280 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11281 | rv = host_resolver.Resolve(resolve_info, |
| 11282 | DEFAULT_PRIORITY, |
| 11283 | &ignored, |
| 11284 | callback.callback(), |
| 11285 | NULL, |
| 11286 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11287 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11288 | rv = callback.WaitForResult(); |
| 11289 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11290 | |
| 11291 | HttpRequestInfo request2; |
| 11292 | request2.method = "GET"; |
| 11293 | request2.url = GURL("https://www.gmail.com/"); |
| 11294 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11295 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11297 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11299 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11300 | |
| 11301 | response = trans2.GetResponseInfo(); |
| 11302 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11303 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11304 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11305 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11306 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11307 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11308 | EXPECT_EQ("hello!", response_data); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11309 | #endif |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11310 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11311 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11312 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11313 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11314 | const std::string https_url = "https://www.google.com:8080/"; |
| 11315 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11316 | |
| 11317 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11318 | scoped_ptr<SpdyFrame> req1( |
| 11319 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11320 | |
| 11321 | MockWrite writes1[] = { |
| 11322 | CreateMockWrite(*req1, 0), |
| 11323 | }; |
| 11324 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11325 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11326 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11327 | MockRead reads1[] = { |
| 11328 | CreateMockRead(*resp1, 1), |
| 11329 | CreateMockRead(*body1, 2), |
| 11330 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11331 | }; |
| 11332 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11333 | DelayedSocketData data1( |
| 11334 | 1, reads1, arraysize(reads1), |
| 11335 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11336 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11337 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11338 | |
| 11339 | // HTTP GET for the HTTP URL |
| 11340 | MockWrite writes2[] = { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11341 | MockWrite(ASYNC, 4, |
| 11342 | "GET / HTTP/1.1\r\n" |
| 11343 | "Host: www.google.com:8080\r\n" |
| 11344 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11345 | }; |
| 11346 | |
| 11347 | MockRead reads2[] = { |
| 11348 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11349 | MockRead(ASYNC, 6, "hello"), |
| 11350 | MockRead(ASYNC, 7, OK), |
| 11351 | }; |
| 11352 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11353 | DelayedSocketData data2( |
| 11354 | 1, reads2, arraysize(reads2), |
| 11355 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11356 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11357 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11358 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11360 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11361 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11362 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11363 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11364 | |
| 11365 | // Start the first transaction to set up the SpdySession |
| 11366 | HttpRequestInfo request1; |
| 11367 | request1.method = "GET"; |
| 11368 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11369 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11370 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11371 | TestCompletionCallback callback1; |
| 11372 | EXPECT_EQ(ERR_IO_PENDING, |
| 11373 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11374 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11375 | |
| 11376 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11377 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11378 | |
| 11379 | // Now, start the HTTP request |
| 11380 | HttpRequestInfo request2; |
| 11381 | request2.method = "GET"; |
| 11382 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11383 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11384 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11385 | TestCompletionCallback callback2; |
| 11386 | EXPECT_EQ(ERR_IO_PENDING, |
| 11387 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11388 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11389 | |
| 11390 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11391 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11392 | } |
| 11393 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11394 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11395 | const std::string https_url = "https://www.google.com:8080/"; |
| 11396 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11397 | |
| 11398 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11399 | const HostPortPair host_port_pair("www.google.com", 8080); |
| 11400 | scoped_ptr<SpdyFrame> connect( |
| 11401 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11402 | scoped_ptr<SpdyFrame> req1( |
| 11403 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11404 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 11405 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11406 | |
| 11407 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11408 | SpdyHeaderBlock req2_block; |
| 11409 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11410 | req2_block[spdy_util_.GetPathKey()] = "/"; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11411 | req2_block[spdy_util_.GetHostKey()] = "www.google.com:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11412 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 11413 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11414 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11415 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11416 | |
| 11417 | MockWrite writes1[] = { |
| 11418 | CreateMockWrite(*connect, 0), |
| 11419 | CreateMockWrite(*wrapped_req1, 2), |
| 11420 | CreateMockWrite(*req2, 5), |
| 11421 | }; |
| 11422 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11423 | scoped_ptr<SpdyFrame> conn_resp( |
| 11424 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11425 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11426 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11427 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 11428 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 11429 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 11430 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 11431 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11432 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11433 | MockRead reads1[] = { |
| 11434 | CreateMockRead(*conn_resp, 1), |
| 11435 | CreateMockRead(*wrapped_resp1, 3), |
| 11436 | CreateMockRead(*wrapped_body1, 4), |
| 11437 | CreateMockRead(*resp2, 6), |
| 11438 | CreateMockRead(*body2, 7), |
| 11439 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 11440 | }; |
| 11441 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11442 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 11443 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11444 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11445 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11446 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11447 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11448 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 11449 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11450 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11451 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11452 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11453 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11454 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11455 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11456 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11457 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11458 | |
| 11459 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11460 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11461 | |
| 11462 | // Start the first transaction to set up the SpdySession |
| 11463 | HttpRequestInfo request1; |
| 11464 | request1.method = "GET"; |
| 11465 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11466 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11467 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11468 | TestCompletionCallback callback1; |
| 11469 | EXPECT_EQ(ERR_IO_PENDING, |
| 11470 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11471 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11472 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11473 | |
| 11474 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11475 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11476 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11477 | LoadTimingInfo load_timing_info1; |
| 11478 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 11479 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 11480 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11481 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11482 | // Now, start the HTTP request |
| 11483 | HttpRequestInfo request2; |
| 11484 | request2.method = "GET"; |
| 11485 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11486 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11487 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11488 | TestCompletionCallback callback2; |
| 11489 | EXPECT_EQ(ERR_IO_PENDING, |
| 11490 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11491 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11492 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11493 | |
| 11494 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11495 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11496 | |
| 11497 | LoadTimingInfo load_timing_info2; |
| 11498 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 11499 | // The established SPDY sessions is considered reused by the HTTP request. |
| 11500 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 11501 | // HTTP requests over a SPDY session should have a different connection |
| 11502 | // socket_log_id than requests over a tunnel. |
| 11503 | 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] | 11504 | } |
| 11505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11506 | TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11507 | session_deps_.force_spdy_always = true; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11508 | const std::string https_url = "https://www.google.com:8080/"; |
| 11509 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11510 | |
| 11511 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11512 | scoped_ptr<SpdyFrame> req1( |
| 11513 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11514 | // SPDY GET for the HTTP URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11515 | scoped_ptr<SpdyFrame> req2( |
| 11516 | spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11517 | |
| 11518 | MockWrite writes[] = { |
| 11519 | CreateMockWrite(*req1, 1), |
| 11520 | CreateMockWrite(*req2, 4), |
| 11521 | }; |
| 11522 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11523 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11524 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11525 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11526 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11527 | MockRead reads[] = { |
| 11528 | CreateMockRead(*resp1, 2), |
| 11529 | CreateMockRead(*body1, 3), |
| 11530 | CreateMockRead(*resp2, 5), |
| 11531 | CreateMockRead(*body2, 6), |
| 11532 | MockRead(ASYNC, ERR_IO_PENDING, 7) |
| 11533 | }; |
| 11534 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11535 | OrderedSocketData data(reads, arraysize(reads), |
| 11536 | writes, arraysize(writes)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11537 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11538 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11539 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11541 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11542 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11543 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11544 | |
| 11545 | // Start the first transaction to set up the SpdySession |
| 11546 | HttpRequestInfo request1; |
| 11547 | request1.method = "GET"; |
| 11548 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11549 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11550 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11551 | TestCompletionCallback callback1; |
| 11552 | EXPECT_EQ(ERR_IO_PENDING, |
| 11553 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11554 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11555 | |
| 11556 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11557 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11558 | |
| 11559 | // Now, start the HTTP request |
| 11560 | HttpRequestInfo request2; |
| 11561 | request2.method = "GET"; |
| 11562 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11563 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11564 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11565 | TestCompletionCallback callback2; |
| 11566 | EXPECT_EQ(ERR_IO_PENDING, |
| 11567 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11568 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11569 | |
| 11570 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11571 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11572 | } |
| 11573 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11574 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11575 | // that we do not pool other origins that resolve to the same IP when |
| 11576 | // the certificate does not match the new origin. |
| 11577 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11578 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11579 | const std::string url1 = "http://www.google.com/"; |
| 11580 | const std::string url2 = "https://mail.google.com/"; |
| 11581 | const std::string ip_addr = "1.2.3.4"; |
| 11582 | |
| 11583 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11584 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11585 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11586 | scoped_ptr<SpdyFrame> req1( |
| 11587 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11588 | |
| 11589 | MockWrite writes1[] = { |
| 11590 | CreateMockWrite(*req1, 0), |
| 11591 | }; |
| 11592 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11593 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11594 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11595 | MockRead reads1[] = { |
| 11596 | CreateMockRead(*resp1, 1), |
| 11597 | CreateMockRead(*body1, 2), |
| 11598 | MockRead(ASYNC, OK, 3) // EOF |
| 11599 | }; |
| 11600 | |
| 11601 | scoped_ptr<DeterministicSocketData> data1( |
| 11602 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11603 | writes1, arraysize(writes1))); |
| 11604 | IPAddressNumber ip; |
| 11605 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11606 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11607 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11608 | data1->set_connect_data(connect_data1); |
| 11609 | |
| 11610 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11611 | scoped_ptr<SpdyFrame> req2( |
| 11612 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11613 | |
| 11614 | MockWrite writes2[] = { |
| 11615 | CreateMockWrite(*req2, 0), |
| 11616 | }; |
| 11617 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11618 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11619 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11620 | MockRead reads2[] = { |
| 11621 | CreateMockRead(*resp2, 1), |
| 11622 | CreateMockRead(*body2, 2), |
| 11623 | MockRead(ASYNC, OK, 3) // EOF |
| 11624 | }; |
| 11625 | |
| 11626 | scoped_ptr<DeterministicSocketData> data2( |
| 11627 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11628 | writes2, arraysize(writes2))); |
| 11629 | MockConnect connect_data2(ASYNC, OK); |
| 11630 | data2->set_connect_data(connect_data2); |
| 11631 | |
| 11632 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11633 | // all others direct. |
| 11634 | ProxyConfig proxy_config; |
| 11635 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 11636 | CapturingProxyResolver* capturing_proxy_resolver = |
| 11637 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11638 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11639 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 11640 | NULL)); |
| 11641 | |
| 11642 | // Load a valid cert. Note, that this does not need to |
| 11643 | // be valid for proxy because the MockSSLClientSocket does |
| 11644 | // not actually verify it. But SpdySession will use this |
| 11645 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11646 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11647 | scoped_refptr<X509Certificate> server_cert( |
| 11648 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11649 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11650 | |
| 11651 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11652 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11653 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11654 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11655 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11656 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11657 | |
| 11658 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11659 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11660 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11661 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11662 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11663 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11664 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11665 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11666 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11667 | |
| 11668 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11669 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11670 | |
| 11671 | // Start the first transaction to set up the SpdySession |
| 11672 | HttpRequestInfo request1; |
| 11673 | request1.method = "GET"; |
| 11674 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11675 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11676 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11677 | TestCompletionCallback callback1; |
| 11678 | ASSERT_EQ(ERR_IO_PENDING, |
| 11679 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11680 | data1->RunFor(3); |
| 11681 | |
| 11682 | ASSERT_TRUE(callback1.have_result()); |
| 11683 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11684 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11685 | |
| 11686 | // Now, start the HTTP request |
| 11687 | HttpRequestInfo request2; |
| 11688 | request2.method = "GET"; |
| 11689 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11690 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11691 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11692 | TestCompletionCallback callback2; |
| 11693 | EXPECT_EQ(ERR_IO_PENDING, |
| 11694 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11695 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11696 | data2->RunFor(3); |
| 11697 | |
| 11698 | ASSERT_TRUE(callback2.have_result()); |
| 11699 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11700 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11701 | } |
| 11702 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11703 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11704 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11705 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 11706 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11707 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11708 | const std::string https_url = "https://www.google.com/"; |
| 11709 | |
| 11710 | MockRead reads1[] = { |
| 11711 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11712 | }; |
| 11713 | |
| 11714 | scoped_ptr<DeterministicSocketData> data1( |
| 11715 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11716 | data1->SetStop(1); |
| 11717 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11718 | scoped_ptr<SpdyFrame> req2( |
| 11719 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11720 | MockWrite writes2[] = { |
| 11721 | CreateMockWrite(*req2, 0), |
| 11722 | }; |
| 11723 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11724 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11725 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11726 | MockRead reads2[] = { |
| 11727 | CreateMockRead(*resp2, 1), |
| 11728 | CreateMockRead(*body2, 2), |
| 11729 | MockRead(ASYNC, OK, 3) // EOF |
| 11730 | }; |
| 11731 | |
| 11732 | scoped_ptr<DeterministicSocketData> data2( |
| 11733 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11734 | writes2, arraysize(writes2))); |
| 11735 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11736 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11737 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11738 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11739 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11740 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11741 | |
| 11742 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11743 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11744 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11745 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11746 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11747 | |
| 11748 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11749 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11750 | |
| 11751 | // Start the first transaction to set up the SpdySession and verify that |
| 11752 | // connection was closed. |
| 11753 | HttpRequestInfo request1; |
| 11754 | request1.method = "GET"; |
| 11755 | request1.url = GURL(https_url); |
| 11756 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11757 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11758 | TestCompletionCallback callback1; |
| 11759 | EXPECT_EQ(ERR_IO_PENDING, |
| 11760 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11761 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11762 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11763 | |
| 11764 | // Now, start the second request and make sure it succeeds. |
| 11765 | HttpRequestInfo request2; |
| 11766 | request2.method = "GET"; |
| 11767 | request2.url = GURL(https_url); |
| 11768 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11769 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11770 | TestCompletionCallback callback2; |
| 11771 | EXPECT_EQ(ERR_IO_PENDING, |
| 11772 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11773 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11774 | data2->RunFor(3); |
| 11775 | |
| 11776 | ASSERT_TRUE(callback2.have_result()); |
| 11777 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11778 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11779 | } |
| 11780 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11781 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11782 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11783 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 11784 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11785 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 11786 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11787 | |
| 11788 | // Use two different hosts with different IPs so they don't get pooled. |
| 11789 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 11790 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 11791 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11792 | |
| 11793 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11794 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11795 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11796 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11799 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11800 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11801 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 11802 | MockWrite spdy1_writes[] = { |
| 11803 | CreateMockWrite(*host1_req, 1), |
| 11804 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11805 | scoped_ptr<SpdyFrame> host1_resp( |
| 11806 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11807 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11808 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11809 | MockRead spdy1_reads[] = { |
| 11810 | CreateMockRead(*host1_resp, 2), |
| 11811 | CreateMockRead(*host1_resp_body, 3), |
| 11812 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11813 | }; |
| 11814 | |
| 11815 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 11816 | new OrderedSocketData( |
| 11817 | spdy1_reads, arraysize(spdy1_reads), |
| 11818 | spdy1_writes, arraysize(spdy1_writes))); |
| 11819 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 11820 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11821 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11822 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 11823 | MockWrite spdy2_writes[] = { |
| 11824 | CreateMockWrite(*host2_req, 1), |
| 11825 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11826 | scoped_ptr<SpdyFrame> host2_resp( |
| 11827 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11828 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11829 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11830 | MockRead spdy2_reads[] = { |
| 11831 | CreateMockRead(*host2_resp, 2), |
| 11832 | CreateMockRead(*host2_resp_body, 3), |
| 11833 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11834 | }; |
| 11835 | |
| 11836 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 11837 | new OrderedSocketData( |
| 11838 | spdy2_reads, arraysize(spdy2_reads), |
| 11839 | spdy2_writes, arraysize(spdy2_writes))); |
| 11840 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 11841 | |
| 11842 | MockWrite http_write[] = { |
| 11843 | MockWrite("GET / HTTP/1.1\r\n" |
| 11844 | "Host: www.a.com\r\n" |
| 11845 | "Connection: keep-alive\r\n\r\n"), |
| 11846 | }; |
| 11847 | |
| 11848 | MockRead http_read[] = { |
| 11849 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11850 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11851 | MockRead("Content-Length: 6\r\n\r\n"), |
| 11852 | MockRead("hello!"), |
| 11853 | }; |
| 11854 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 11855 | http_write, arraysize(http_write)); |
| 11856 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11857 | |
| 11858 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11859 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11860 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11861 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11862 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11863 | |
| 11864 | TestCompletionCallback callback; |
| 11865 | HttpRequestInfo request1; |
| 11866 | request1.method = "GET"; |
| 11867 | request1.url = GURL("https://www.a.com/"); |
| 11868 | request1.load_flags = 0; |
| 11869 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11871 | |
| 11872 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 11873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11874 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11875 | |
| 11876 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11877 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11878 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11879 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11880 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11881 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11882 | |
| 11883 | std::string response_data; |
| 11884 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11885 | EXPECT_EQ("hello!", response_data); |
| 11886 | trans.reset(); |
| 11887 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11888 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11889 | |
| 11890 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11891 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11892 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11893 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11894 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11895 | HttpRequestInfo request2; |
| 11896 | request2.method = "GET"; |
| 11897 | request2.url = GURL("https://www.b.com/"); |
| 11898 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11899 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11900 | |
| 11901 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 11902 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11903 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11904 | |
| 11905 | response = trans->GetResponseInfo(); |
| 11906 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11907 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11908 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11909 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11910 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11911 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11912 | EXPECT_EQ("hello!", response_data); |
| 11913 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11914 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11915 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11916 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11917 | |
| 11918 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11919 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11920 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11921 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11922 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11923 | HttpRequestInfo request3; |
| 11924 | request3.method = "GET"; |
| 11925 | request3.url = GURL("http://www.a.com/"); |
| 11926 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11927 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11928 | |
| 11929 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 11930 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11931 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11932 | |
| 11933 | response = trans->GetResponseInfo(); |
| 11934 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11935 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11936 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11937 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11938 | EXPECT_FALSE(response->was_npn_negotiated); |
| 11939 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11940 | EXPECT_EQ("hello!", response_data); |
| 11941 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11942 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11943 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11944 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11945 | } |
| 11946 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11947 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 11948 | HttpRequestInfo request; |
| 11949 | request.method = "GET"; |
| 11950 | request.url = GURL("http://www.google.com/"); |
| 11951 | request.load_flags = 0; |
| 11952 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 11953 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11954 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11955 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11956 | |
| 11957 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 11958 | StaticSocketDataProvider data; |
| 11959 | data.set_connect_data(mock_connect); |
| 11960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11961 | |
| 11962 | TestCompletionCallback callback; |
| 11963 | |
| 11964 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11965 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11966 | |
| 11967 | rv = callback.WaitForResult(); |
| 11968 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11969 | |
| 11970 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 11971 | |
| 11972 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 11973 | HttpRequestHeaders request_headers; |
| 11974 | trans->GetFullRequestHeaders(&request_headers); |
| 11975 | } |
| 11976 | |
| 11977 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 11978 | HttpRequestInfo request; |
| 11979 | request.method = "GET"; |
| 11980 | request.url = GURL("http://www.google.com/"); |
| 11981 | request.load_flags = 0; |
| 11982 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 11983 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11984 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 11986 | |
| 11987 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11988 | StaticSocketDataProvider data; |
| 11989 | data.set_connect_data(mock_connect); |
| 11990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11991 | |
| 11992 | TestCompletionCallback callback; |
| 11993 | |
| 11994 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 11995 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11996 | |
| 11997 | rv = callback.WaitForResult(); |
| 11998 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 11999 | |
| 12000 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12001 | |
| 12002 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12003 | HttpRequestHeaders request_headers; |
| 12004 | trans->GetFullRequestHeaders(&request_headers); |
| 12005 | } |
| 12006 | |
| 12007 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12008 | HttpRequestInfo request; |
| 12009 | request.method = "GET"; |
| 12010 | request.url = GURL("http://www.google.com/"); |
| 12011 | request.load_flags = 0; |
| 12012 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12013 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12014 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12015 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12016 | |
| 12017 | MockWrite data_writes[] = { |
| 12018 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12019 | }; |
| 12020 | MockRead data_reads[] = { |
| 12021 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12022 | }; |
| 12023 | |
| 12024 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12025 | data_writes, arraysize(data_writes)); |
| 12026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12027 | |
| 12028 | TestCompletionCallback callback; |
| 12029 | |
| 12030 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12032 | |
| 12033 | rv = callback.WaitForResult(); |
| 12034 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12035 | |
| 12036 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12037 | |
| 12038 | HttpRequestHeaders request_headers; |
| 12039 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12040 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12041 | } |
| 12042 | |
| 12043 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12044 | HttpRequestInfo request; |
| 12045 | request.method = "GET"; |
| 12046 | request.url = GURL("http://www.google.com/"); |
| 12047 | request.load_flags = 0; |
| 12048 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12049 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12050 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12051 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12052 | |
| 12053 | MockWrite data_writes[] = { |
| 12054 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12055 | }; |
| 12056 | MockRead data_reads[] = { |
| 12057 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12058 | }; |
| 12059 | |
| 12060 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12061 | data_writes, arraysize(data_writes)); |
| 12062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12063 | |
| 12064 | TestCompletionCallback callback; |
| 12065 | |
| 12066 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12067 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12068 | |
| 12069 | rv = callback.WaitForResult(); |
| 12070 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12071 | |
| 12072 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12073 | |
| 12074 | HttpRequestHeaders request_headers; |
| 12075 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12076 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12077 | } |
| 12078 | |
| 12079 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12080 | HttpRequestInfo request; |
| 12081 | request.method = "GET"; |
| 12082 | request.url = GURL("http://www.google.com/"); |
| 12083 | request.load_flags = 0; |
| 12084 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12085 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12086 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12087 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12088 | |
| 12089 | MockWrite data_writes[] = { |
| 12090 | MockWrite("GET / HTTP/1.1\r\n" |
| 12091 | "Host: www.google.com\r\n" |
| 12092 | "Connection: keep-alive\r\n\r\n"), |
| 12093 | }; |
| 12094 | MockRead data_reads[] = { |
| 12095 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12096 | }; |
| 12097 | |
| 12098 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12099 | data_writes, arraysize(data_writes)); |
| 12100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12101 | |
| 12102 | TestCompletionCallback callback; |
| 12103 | |
| 12104 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12106 | |
| 12107 | rv = callback.WaitForResult(); |
| 12108 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12109 | |
| 12110 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12111 | |
| 12112 | HttpRequestHeaders request_headers; |
| 12113 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12114 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12115 | } |
| 12116 | |
| 12117 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 12118 | HttpRequestInfo request; |
| 12119 | request.method = "GET"; |
| 12120 | request.url = GURL("http://www.google.com/"); |
| 12121 | request.load_flags = 0; |
| 12122 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12123 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12124 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12126 | |
| 12127 | MockWrite data_writes[] = { |
| 12128 | MockWrite("GET / HTTP/1.1\r\n" |
| 12129 | "Host: www.google.com\r\n" |
| 12130 | "Connection: keep-alive\r\n\r\n"), |
| 12131 | }; |
| 12132 | MockRead data_reads[] = { |
| 12133 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 12134 | }; |
| 12135 | |
| 12136 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12137 | data_writes, arraysize(data_writes)); |
| 12138 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12139 | |
| 12140 | TestCompletionCallback callback; |
| 12141 | |
| 12142 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12144 | |
| 12145 | rv = callback.WaitForResult(); |
| 12146 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12147 | |
| 12148 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12149 | |
| 12150 | HttpRequestHeaders request_headers; |
| 12151 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12152 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12153 | } |
| 12154 | |
| 12155 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 12156 | HttpRequestInfo request; |
| 12157 | request.method = "GET"; |
| 12158 | request.url = GURL("http://www.google.com/"); |
| 12159 | request.load_flags = 0; |
| 12160 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 12161 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12162 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12163 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12165 | |
| 12166 | MockWrite data_writes[] = { |
| 12167 | MockWrite("GET / HTTP/1.1\r\n" |
| 12168 | "Host: www.google.com\r\n" |
| 12169 | "Connection: keep-alive\r\n" |
| 12170 | "X-Foo: bar\r\n\r\n"), |
| 12171 | }; |
| 12172 | MockRead data_reads[] = { |
| 12173 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12174 | "Content-Length: 5\r\n\r\n" |
| 12175 | "hello"), |
| 12176 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 12177 | }; |
| 12178 | |
| 12179 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12180 | data_writes, arraysize(data_writes)); |
| 12181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12182 | |
| 12183 | TestCompletionCallback callback; |
| 12184 | |
| 12185 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12186 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12187 | |
| 12188 | rv = callback.WaitForResult(); |
| 12189 | EXPECT_EQ(OK, rv); |
| 12190 | |
| 12191 | HttpRequestHeaders request_headers; |
| 12192 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12193 | std::string foo; |
| 12194 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 12195 | EXPECT_EQ("bar", foo); |
| 12196 | } |
| 12197 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12198 | namespace { |
| 12199 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12200 | // Fake HttpStream that simply records calls to SetPriority(). |
| 12201 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12202 | public base::SupportsWeakPtr<FakeStream> { |
| 12203 | public: |
| 12204 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12205 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12206 | |
| 12207 | RequestPriority priority() const { return priority_; } |
| 12208 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12209 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12210 | RequestPriority priority, |
| 12211 | const BoundNetLog& net_log, |
| 12212 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12213 | return ERR_IO_PENDING; |
| 12214 | } |
| 12215 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12216 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12217 | HttpResponseInfo* response, |
| 12218 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12219 | ADD_FAILURE(); |
| 12220 | return ERR_UNEXPECTED; |
| 12221 | } |
| 12222 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12223 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12224 | ADD_FAILURE(); |
| 12225 | return ERR_UNEXPECTED; |
| 12226 | } |
| 12227 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12228 | int ReadResponseBody(IOBuffer* buf, |
| 12229 | int buf_len, |
| 12230 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12231 | ADD_FAILURE(); |
| 12232 | return ERR_UNEXPECTED; |
| 12233 | } |
| 12234 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12235 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12236 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12237 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12238 | ADD_FAILURE(); |
| 12239 | return false; |
| 12240 | } |
| 12241 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12242 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12243 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12244 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12245 | ADD_FAILURE(); |
| 12246 | return false; |
| 12247 | } |
| 12248 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12249 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12250 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12251 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12252 | ADD_FAILURE(); |
| 12253 | return false; |
| 12254 | } |
| 12255 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12256 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 12257 | ADD_FAILURE(); |
| 12258 | return 0; |
| 12259 | } |
| 12260 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12261 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12262 | ADD_FAILURE(); |
| 12263 | return false; |
| 12264 | } |
| 12265 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12266 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 12267 | |
| 12268 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12269 | ADD_FAILURE(); |
| 12270 | } |
| 12271 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12272 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12273 | ADD_FAILURE(); |
| 12274 | return false; |
| 12275 | } |
| 12276 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12277 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12278 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12279 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12280 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12281 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 12282 | |
| 12283 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 12284 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12285 | private: |
| 12286 | RequestPriority priority_; |
| 12287 | |
| 12288 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 12289 | }; |
| 12290 | |
| 12291 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 12292 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12293 | class FakeStreamRequest : public HttpStreamRequest, |
| 12294 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 12295 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12296 | FakeStreamRequest(RequestPriority priority, |
| 12297 | HttpStreamRequest::Delegate* delegate) |
| 12298 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12299 | delegate_(delegate), |
| 12300 | websocket_stream_create_helper_(NULL) {} |
| 12301 | |
| 12302 | FakeStreamRequest(RequestPriority priority, |
| 12303 | HttpStreamRequest::Delegate* delegate, |
| 12304 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 12305 | : priority_(priority), |
| 12306 | delegate_(delegate), |
| 12307 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12308 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12309 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12310 | |
| 12311 | RequestPriority priority() const { return priority_; } |
| 12312 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12313 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 12314 | websocket_stream_create_helper() const { |
| 12315 | return websocket_stream_create_helper_; |
| 12316 | } |
| 12317 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12318 | // Create a new FakeStream and pass it to the request's |
| 12319 | // delegate. Returns a weak pointer to the FakeStream. |
| 12320 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 12321 | FakeStream* fake_stream = new FakeStream(priority_); |
| 12322 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 12323 | // immediately delete |fake_stream|. |
| 12324 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 12325 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 12326 | return weak_stream; |
| 12327 | } |
| 12328 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12329 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12330 | ADD_FAILURE(); |
| 12331 | return ERR_UNEXPECTED; |
| 12332 | } |
| 12333 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12334 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12335 | ADD_FAILURE(); |
| 12336 | return LoadState(); |
| 12337 | } |
| 12338 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12339 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12340 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12341 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12342 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12343 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12344 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12345 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12346 | |
| 12347 | private: |
| 12348 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12349 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12350 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12351 | |
| 12352 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 12353 | }; |
| 12354 | |
| 12355 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 12356 | class FakeStreamFactory : public HttpStreamFactory { |
| 12357 | public: |
| 12358 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12359 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12360 | |
| 12361 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 12362 | // RequestStream() (which may be NULL if it was destroyed already). |
| 12363 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 12364 | return last_stream_request_; |
| 12365 | } |
| 12366 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12367 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 12368 | RequestPriority priority, |
| 12369 | const SSLConfig& server_ssl_config, |
| 12370 | const SSLConfig& proxy_ssl_config, |
| 12371 | HttpStreamRequest::Delegate* delegate, |
| 12372 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12373 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12374 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12375 | return fake_request; |
| 12376 | } |
| 12377 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12378 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12379 | const HttpRequestInfo& info, |
| 12380 | RequestPriority priority, |
| 12381 | const SSLConfig& server_ssl_config, |
| 12382 | const SSLConfig& proxy_ssl_config, |
| 12383 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 12384 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12385 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12386 | FakeStreamRequest* fake_request = |
| 12387 | new FakeStreamRequest(priority, delegate, create_helper); |
| 12388 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12389 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12390 | } |
| 12391 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12392 | void PreconnectStreams(int num_streams, |
| 12393 | const HttpRequestInfo& info, |
| 12394 | RequestPriority priority, |
| 12395 | const SSLConfig& server_ssl_config, |
| 12396 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12397 | ADD_FAILURE(); |
| 12398 | } |
| 12399 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12400 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12401 | ADD_FAILURE(); |
| 12402 | return NULL; |
| 12403 | } |
| 12404 | |
| 12405 | private: |
| 12406 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 12407 | |
| 12408 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 12409 | }; |
| 12410 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12411 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 12412 | // worth doing. |
| 12413 | class FakeWebSocketStreamCreateHelper : |
| 12414 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 12415 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12416 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 12417 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12418 | bool using_proxy) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12419 | NOTREACHED(); |
| 12420 | return NULL; |
| 12421 | } |
| 12422 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12423 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12424 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12425 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12426 | NOTREACHED(); |
| 12427 | return NULL; |
| 12428 | }; |
| 12429 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12430 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12431 | |
| 12432 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 12433 | NOTREACHED(); |
| 12434 | return scoped_ptr<WebSocketStream>(); |
| 12435 | } |
| 12436 | }; |
| 12437 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12438 | } // namespace |
| 12439 | |
| 12440 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 12441 | // stream request on start. |
| 12442 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 12443 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12444 | HttpNetworkSessionPeer peer(session); |
| 12445 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12446 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12447 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12448 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12449 | |
| 12450 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 12451 | |
| 12452 | HttpRequestInfo request; |
| 12453 | TestCompletionCallback callback; |
| 12454 | EXPECT_EQ(ERR_IO_PENDING, |
| 12455 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12456 | |
| 12457 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12458 | fake_factory->last_stream_request(); |
| 12459 | ASSERT_TRUE(fake_request != NULL); |
| 12460 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12461 | } |
| 12462 | |
| 12463 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12464 | // updates to its stream request. |
| 12465 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 12466 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12467 | HttpNetworkSessionPeer peer(session); |
| 12468 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12469 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12470 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12471 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12472 | |
| 12473 | HttpRequestInfo request; |
| 12474 | TestCompletionCallback callback; |
| 12475 | EXPECT_EQ(ERR_IO_PENDING, |
| 12476 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12477 | |
| 12478 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12479 | fake_factory->last_stream_request(); |
| 12480 | ASSERT_TRUE(fake_request != NULL); |
| 12481 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12482 | |
| 12483 | trans.SetPriority(LOWEST); |
| 12484 | ASSERT_TRUE(fake_request != NULL); |
| 12485 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 12486 | } |
| 12487 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12488 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12489 | // updates to its stream. |
| 12490 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 12491 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12492 | HttpNetworkSessionPeer peer(session); |
| 12493 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12494 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12495 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12496 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12497 | |
| 12498 | HttpRequestInfo request; |
| 12499 | TestCompletionCallback callback; |
| 12500 | EXPECT_EQ(ERR_IO_PENDING, |
| 12501 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12502 | |
| 12503 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12504 | fake_factory->last_stream_request(); |
| 12505 | ASSERT_TRUE(fake_request != NULL); |
| 12506 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 12507 | ASSERT_TRUE(fake_stream != NULL); |
| 12508 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 12509 | |
| 12510 | trans.SetPriority(LOWEST); |
| 12511 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 12512 | } |
| 12513 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12514 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 12515 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 12516 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 12517 | // that the different schemes work. |
| 12518 | std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"}; |
| 12519 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 12520 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12521 | HttpNetworkSessionPeer peer(session); |
| 12522 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12523 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 12524 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12525 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 12526 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12527 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12528 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 12529 | &websocket_stream_create_helper); |
| 12530 | |
| 12531 | HttpRequestInfo request; |
| 12532 | TestCompletionCallback callback; |
| 12533 | request.method = "GET"; |
| 12534 | request.url = GURL(test_cases[i]); |
| 12535 | |
| 12536 | EXPECT_EQ(ERR_IO_PENDING, |
| 12537 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12538 | |
| 12539 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12540 | fake_factory->last_stream_request(); |
| 12541 | ASSERT_TRUE(fake_request != NULL); |
| 12542 | EXPECT_EQ(&websocket_stream_create_helper, |
| 12543 | fake_request->websocket_stream_create_helper()); |
| 12544 | } |
| 12545 | } |
| 12546 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12547 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 12548 | // if the transport socket pool is stalled on the global socket limit. |
| 12549 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 12550 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12551 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12552 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12553 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12554 | |
| 12555 | // Set up SSL request. |
| 12556 | |
| 12557 | HttpRequestInfo ssl_request; |
| 12558 | ssl_request.method = "GET"; |
| 12559 | ssl_request.url = GURL("https://www.google.com/"); |
| 12560 | |
| 12561 | MockWrite ssl_writes[] = { |
| 12562 | MockWrite("GET / HTTP/1.1\r\n" |
| 12563 | "Host: www.google.com\r\n" |
| 12564 | "Connection: keep-alive\r\n\r\n"), |
| 12565 | }; |
| 12566 | MockRead ssl_reads[] = { |
| 12567 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12568 | MockRead("Content-Length: 11\r\n\r\n"), |
| 12569 | MockRead("hello world"), |
| 12570 | MockRead(SYNCHRONOUS, OK), |
| 12571 | }; |
| 12572 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 12573 | ssl_writes, arraysize(ssl_writes)); |
| 12574 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12575 | |
| 12576 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12578 | |
| 12579 | // Set up HTTP request. |
| 12580 | |
| 12581 | HttpRequestInfo http_request; |
| 12582 | http_request.method = "GET"; |
| 12583 | http_request.url = GURL("http://www.google.com/"); |
| 12584 | |
| 12585 | MockWrite http_writes[] = { |
| 12586 | MockWrite("GET / HTTP/1.1\r\n" |
| 12587 | "Host: www.google.com\r\n" |
| 12588 | "Connection: keep-alive\r\n\r\n"), |
| 12589 | }; |
| 12590 | MockRead http_reads[] = { |
| 12591 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12592 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12593 | MockRead("falafel"), |
| 12594 | MockRead(SYNCHRONOUS, OK), |
| 12595 | }; |
| 12596 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12597 | http_writes, arraysize(http_writes)); |
| 12598 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12599 | |
| 12600 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12601 | |
| 12602 | // Start the SSL request. |
| 12603 | TestCompletionCallback ssl_callback; |
| 12604 | scoped_ptr<HttpTransaction> ssl_trans( |
| 12605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12606 | ASSERT_EQ(ERR_IO_PENDING, |
| 12607 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 12608 | BoundNetLog())); |
| 12609 | |
| 12610 | // Start the HTTP request. Pool should stall. |
| 12611 | TestCompletionCallback http_callback; |
| 12612 | scoped_ptr<HttpTransaction> http_trans( |
| 12613 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12614 | ASSERT_EQ(ERR_IO_PENDING, |
| 12615 | http_trans->Start(&http_request, http_callback.callback(), |
| 12616 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12617 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12618 | |
| 12619 | // Wait for response from SSL request. |
| 12620 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 12621 | std::string response_data; |
| 12622 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 12623 | EXPECT_EQ("hello world", response_data); |
| 12624 | |
| 12625 | // The SSL socket should automatically be closed, so the HTTP request can |
| 12626 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12627 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 12628 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12629 | |
| 12630 | // The HTTP request can now complete. |
| 12631 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12632 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12633 | EXPECT_EQ("falafel", response_data); |
| 12634 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12635 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12636 | } |
| 12637 | |
| 12638 | // Tests that when a SSL connection is established but there's no corresponding |
| 12639 | // request that needs it, the new socket is closed if the transport socket pool |
| 12640 | // is stalled on the global socket limit. |
| 12641 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 12642 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12643 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12644 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12645 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12646 | |
| 12647 | // Set up an ssl request. |
| 12648 | |
| 12649 | HttpRequestInfo ssl_request; |
| 12650 | ssl_request.method = "GET"; |
| 12651 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 12652 | |
| 12653 | // No data will be sent on the SSL socket. |
| 12654 | StaticSocketDataProvider ssl_data; |
| 12655 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12656 | |
| 12657 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12659 | |
| 12660 | // Set up HTTP request. |
| 12661 | |
| 12662 | HttpRequestInfo http_request; |
| 12663 | http_request.method = "GET"; |
| 12664 | http_request.url = GURL("http://www.google.com/"); |
| 12665 | |
| 12666 | MockWrite http_writes[] = { |
| 12667 | MockWrite("GET / HTTP/1.1\r\n" |
| 12668 | "Host: www.google.com\r\n" |
| 12669 | "Connection: keep-alive\r\n\r\n"), |
| 12670 | }; |
| 12671 | MockRead http_reads[] = { |
| 12672 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12673 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12674 | MockRead("falafel"), |
| 12675 | MockRead(SYNCHRONOUS, OK), |
| 12676 | }; |
| 12677 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12678 | http_writes, arraysize(http_writes)); |
| 12679 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12680 | |
| 12681 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12682 | |
| 12683 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 12684 | // cancelled when a normal transaction is cancelled. |
| 12685 | net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 12686 | net::SSLConfig ssl_config; |
| 12687 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 12688 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 12689 | ssl_config, ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12690 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12691 | |
| 12692 | // Start the HTTP request. Pool should stall. |
| 12693 | TestCompletionCallback http_callback; |
| 12694 | scoped_ptr<HttpTransaction> http_trans( |
| 12695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12696 | ASSERT_EQ(ERR_IO_PENDING, |
| 12697 | http_trans->Start(&http_request, http_callback.callback(), |
| 12698 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12699 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12700 | |
| 12701 | // The SSL connection will automatically be closed once the connection is |
| 12702 | // established, to let the HTTP request start. |
| 12703 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12704 | std::string response_data; |
| 12705 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12706 | EXPECT_EQ("falafel", response_data); |
| 12707 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12708 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12709 | } |
| 12710 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12711 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 12712 | ScopedVector<UploadElementReader> element_readers; |
| 12713 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12714 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12715 | |
| 12716 | HttpRequestInfo request; |
| 12717 | request.method = "POST"; |
| 12718 | request.url = GURL("http://www.foo.com/"); |
| 12719 | request.upload_data_stream = &upload_data_stream; |
| 12720 | request.load_flags = 0; |
| 12721 | |
| 12722 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12723 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12724 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12725 | // Send headers successfully, but get an error while sending the body. |
| 12726 | MockWrite data_writes[] = { |
| 12727 | MockWrite("POST / HTTP/1.1\r\n" |
| 12728 | "Host: www.foo.com\r\n" |
| 12729 | "Connection: keep-alive\r\n" |
| 12730 | "Content-Length: 3\r\n\r\n"), |
| 12731 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12732 | }; |
| 12733 | |
| 12734 | MockRead data_reads[] = { |
| 12735 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12736 | MockRead("hello world"), |
| 12737 | MockRead(SYNCHRONOUS, OK), |
| 12738 | }; |
| 12739 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12740 | arraysize(data_writes)); |
| 12741 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12742 | |
| 12743 | TestCompletionCallback callback; |
| 12744 | |
| 12745 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12746 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12747 | |
| 12748 | rv = callback.WaitForResult(); |
| 12749 | EXPECT_EQ(OK, rv); |
| 12750 | |
| 12751 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12752 | ASSERT_TRUE(response != NULL); |
| 12753 | |
| 12754 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12755 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12756 | |
| 12757 | std::string response_data; |
| 12758 | rv = ReadTransaction(trans.get(), &response_data); |
| 12759 | EXPECT_EQ(OK, rv); |
| 12760 | EXPECT_EQ("hello world", response_data); |
| 12761 | } |
| 12762 | |
| 12763 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 12764 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 12765 | TEST_P(HttpNetworkTransactionTest, |
| 12766 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 12767 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12768 | MockWrite data_writes[] = { |
| 12769 | MockWrite("GET / HTTP/1.1\r\n" |
| 12770 | "Host: www.foo.com\r\n" |
| 12771 | "Connection: keep-alive\r\n\r\n"), |
| 12772 | MockWrite("POST / HTTP/1.1\r\n" |
| 12773 | "Host: www.foo.com\r\n" |
| 12774 | "Connection: keep-alive\r\n" |
| 12775 | "Content-Length: 3\r\n\r\n"), |
| 12776 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12777 | }; |
| 12778 | |
| 12779 | MockRead data_reads[] = { |
| 12780 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 12781 | "Content-Length: 14\r\n\r\n"), |
| 12782 | MockRead("first response"), |
| 12783 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 12784 | "Content-Length: 15\r\n\r\n"), |
| 12785 | MockRead("second response"), |
| 12786 | MockRead(SYNCHRONOUS, OK), |
| 12787 | }; |
| 12788 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12789 | arraysize(data_writes)); |
| 12790 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12791 | |
| 12792 | TestCompletionCallback callback; |
| 12793 | HttpRequestInfo request1; |
| 12794 | request1.method = "GET"; |
| 12795 | request1.url = GURL("http://www.foo.com/"); |
| 12796 | request1.load_flags = 0; |
| 12797 | |
| 12798 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12799 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12800 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 12801 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12802 | |
| 12803 | rv = callback.WaitForResult(); |
| 12804 | EXPECT_EQ(OK, rv); |
| 12805 | |
| 12806 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12807 | ASSERT_TRUE(response1 != NULL); |
| 12808 | |
| 12809 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 12810 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 12811 | |
| 12812 | std::string response_data1; |
| 12813 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 12814 | EXPECT_EQ(OK, rv); |
| 12815 | EXPECT_EQ("first response", response_data1); |
| 12816 | // Delete the transaction to release the socket back into the socket pool. |
| 12817 | trans1.reset(); |
| 12818 | |
| 12819 | ScopedVector<UploadElementReader> element_readers; |
| 12820 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12821 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12822 | |
| 12823 | HttpRequestInfo request2; |
| 12824 | request2.method = "POST"; |
| 12825 | request2.url = GURL("http://www.foo.com/"); |
| 12826 | request2.upload_data_stream = &upload_data_stream; |
| 12827 | request2.load_flags = 0; |
| 12828 | |
| 12829 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12830 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12831 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 12832 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12833 | |
| 12834 | rv = callback.WaitForResult(); |
| 12835 | EXPECT_EQ(OK, rv); |
| 12836 | |
| 12837 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 12838 | ASSERT_TRUE(response2 != NULL); |
| 12839 | |
| 12840 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 12841 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 12842 | |
| 12843 | std::string response_data2; |
| 12844 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 12845 | EXPECT_EQ(OK, rv); |
| 12846 | EXPECT_EQ("second response", response_data2); |
| 12847 | } |
| 12848 | |
| 12849 | TEST_P(HttpNetworkTransactionTest, |
| 12850 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 12851 | ScopedVector<UploadElementReader> element_readers; |
| 12852 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12853 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12854 | |
| 12855 | HttpRequestInfo request; |
| 12856 | request.method = "POST"; |
| 12857 | request.url = GURL("http://www.foo.com/"); |
| 12858 | request.upload_data_stream = &upload_data_stream; |
| 12859 | request.load_flags = 0; |
| 12860 | |
| 12861 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12862 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12863 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12864 | // Send headers successfully, but get an error while sending the body. |
| 12865 | MockWrite data_writes[] = { |
| 12866 | MockWrite("POST / HTTP/1.1\r\n" |
| 12867 | "Host: www.foo.com\r\n" |
| 12868 | "Connection: keep-alive\r\n" |
| 12869 | "Content-Length: 3\r\n\r\n" |
| 12870 | "fo"), |
| 12871 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12872 | }; |
| 12873 | |
| 12874 | MockRead data_reads[] = { |
| 12875 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12876 | MockRead("hello world"), |
| 12877 | MockRead(SYNCHRONOUS, OK), |
| 12878 | }; |
| 12879 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12880 | arraysize(data_writes)); |
| 12881 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12882 | |
| 12883 | TestCompletionCallback callback; |
| 12884 | |
| 12885 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12886 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12887 | |
| 12888 | rv = callback.WaitForResult(); |
| 12889 | EXPECT_EQ(OK, rv); |
| 12890 | |
| 12891 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12892 | ASSERT_TRUE(response != NULL); |
| 12893 | |
| 12894 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12895 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12896 | |
| 12897 | std::string response_data; |
| 12898 | rv = ReadTransaction(trans.get(), &response_data); |
| 12899 | EXPECT_EQ(OK, rv); |
| 12900 | EXPECT_EQ("hello world", response_data); |
| 12901 | } |
| 12902 | |
| 12903 | // This tests the more common case than the previous test, where headers and |
| 12904 | // body are not merged into a single request. |
| 12905 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 12906 | ScopedVector<UploadElementReader> element_readers; |
| 12907 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12908 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12909 | |
| 12910 | HttpRequestInfo request; |
| 12911 | request.method = "POST"; |
| 12912 | request.url = GURL("http://www.foo.com/"); |
| 12913 | request.upload_data_stream = &upload_data_stream; |
| 12914 | request.load_flags = 0; |
| 12915 | |
| 12916 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12917 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12919 | // Send headers successfully, but get an error while sending the body. |
| 12920 | MockWrite data_writes[] = { |
| 12921 | MockWrite("POST / HTTP/1.1\r\n" |
| 12922 | "Host: www.foo.com\r\n" |
| 12923 | "Connection: keep-alive\r\n" |
| 12924 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 12925 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12926 | }; |
| 12927 | |
| 12928 | MockRead data_reads[] = { |
| 12929 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12930 | MockRead("hello world"), |
| 12931 | MockRead(SYNCHRONOUS, OK), |
| 12932 | }; |
| 12933 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12934 | arraysize(data_writes)); |
| 12935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12936 | |
| 12937 | TestCompletionCallback callback; |
| 12938 | |
| 12939 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12941 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 12942 | // they can't be merged with the body in a single send. Not currently |
| 12943 | // necessary since a chunked body is never merged with headers, but this makes |
| 12944 | // the test more future proof. |
| 12945 | base::RunLoop().RunUntilIdle(); |
| 12946 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12947 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12948 | |
| 12949 | rv = callback.WaitForResult(); |
| 12950 | EXPECT_EQ(OK, rv); |
| 12951 | |
| 12952 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12953 | ASSERT_TRUE(response != NULL); |
| 12954 | |
| 12955 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12956 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12957 | |
| 12958 | std::string response_data; |
| 12959 | rv = ReadTransaction(trans.get(), &response_data); |
| 12960 | EXPECT_EQ(OK, rv); |
| 12961 | EXPECT_EQ("hello world", response_data); |
| 12962 | } |
| 12963 | |
| 12964 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 12965 | ScopedVector<UploadElementReader> element_readers; |
| 12966 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12967 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12968 | |
| 12969 | HttpRequestInfo request; |
| 12970 | request.method = "POST"; |
| 12971 | request.url = GURL("http://www.foo.com/"); |
| 12972 | request.upload_data_stream = &upload_data_stream; |
| 12973 | request.load_flags = 0; |
| 12974 | |
| 12975 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12976 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12978 | |
| 12979 | MockWrite data_writes[] = { |
| 12980 | MockWrite("POST / HTTP/1.1\r\n" |
| 12981 | "Host: www.foo.com\r\n" |
| 12982 | "Connection: keep-alive\r\n" |
| 12983 | "Content-Length: 3\r\n\r\n"), |
| 12984 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12985 | }; |
| 12986 | |
| 12987 | MockRead data_reads[] = { |
| 12988 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 12989 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12990 | MockRead("hello world"), |
| 12991 | MockRead(SYNCHRONOUS, OK), |
| 12992 | }; |
| 12993 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12994 | arraysize(data_writes)); |
| 12995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12996 | |
| 12997 | TestCompletionCallback callback; |
| 12998 | |
| 12999 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13000 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13001 | |
| 13002 | rv = callback.WaitForResult(); |
| 13003 | EXPECT_EQ(OK, rv); |
| 13004 | |
| 13005 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13006 | ASSERT_TRUE(response != NULL); |
| 13007 | |
| 13008 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13009 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13010 | |
| 13011 | std::string response_data; |
| 13012 | rv = ReadTransaction(trans.get(), &response_data); |
| 13013 | EXPECT_EQ(OK, rv); |
| 13014 | EXPECT_EQ("hello world", response_data); |
| 13015 | } |
| 13016 | |
| 13017 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 13018 | ScopedVector<UploadElementReader> element_readers; |
| 13019 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13020 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13021 | |
| 13022 | HttpRequestInfo request; |
| 13023 | request.method = "POST"; |
| 13024 | request.url = GURL("http://www.foo.com/"); |
| 13025 | request.upload_data_stream = &upload_data_stream; |
| 13026 | request.load_flags = 0; |
| 13027 | |
| 13028 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13029 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13030 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13031 | // Send headers successfully, but get an error while sending the body. |
| 13032 | MockWrite data_writes[] = { |
| 13033 | MockWrite("POST / HTTP/1.1\r\n" |
| 13034 | "Host: www.foo.com\r\n" |
| 13035 | "Connection: keep-alive\r\n" |
| 13036 | "Content-Length: 3\r\n\r\n"), |
| 13037 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13038 | }; |
| 13039 | |
| 13040 | MockRead data_reads[] = { |
| 13041 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 13042 | MockRead("hello world"), |
| 13043 | MockRead(SYNCHRONOUS, OK), |
| 13044 | }; |
| 13045 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13046 | arraysize(data_writes)); |
| 13047 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13048 | |
| 13049 | TestCompletionCallback callback; |
| 13050 | |
| 13051 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13052 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13053 | |
| 13054 | rv = callback.WaitForResult(); |
| 13055 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13056 | |
| 13057 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13058 | EXPECT_TRUE(response == NULL); |
| 13059 | } |
| 13060 | |
| 13061 | TEST_P(HttpNetworkTransactionTest, |
| 13062 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 13063 | ScopedVector<UploadElementReader> element_readers; |
| 13064 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13065 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13066 | |
| 13067 | HttpRequestInfo request; |
| 13068 | request.method = "POST"; |
| 13069 | request.url = GURL("http://www.foo.com/"); |
| 13070 | request.upload_data_stream = &upload_data_stream; |
| 13071 | request.load_flags = 0; |
| 13072 | |
| 13073 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13074 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13075 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13076 | // Send headers successfully, but get an error while sending the body. |
| 13077 | MockWrite data_writes[] = { |
| 13078 | MockWrite("POST / HTTP/1.1\r\n" |
| 13079 | "Host: www.foo.com\r\n" |
| 13080 | "Connection: keep-alive\r\n" |
| 13081 | "Content-Length: 3\r\n\r\n"), |
| 13082 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13083 | }; |
| 13084 | |
| 13085 | MockRead data_reads[] = { |
| 13086 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13087 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 13088 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 13089 | MockRead("Content-Length: 0\r\n\r\n"), |
| 13090 | MockRead(SYNCHRONOUS, OK), |
| 13091 | }; |
| 13092 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13093 | arraysize(data_writes)); |
| 13094 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13095 | |
| 13096 | TestCompletionCallback callback; |
| 13097 | |
| 13098 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13099 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13100 | |
| 13101 | rv = callback.WaitForResult(); |
| 13102 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13103 | |
| 13104 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13105 | EXPECT_TRUE(response == NULL); |
| 13106 | } |
| 13107 | |
| 13108 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 13109 | ScopedVector<UploadElementReader> element_readers; |
| 13110 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13111 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13112 | |
| 13113 | HttpRequestInfo request; |
| 13114 | request.method = "POST"; |
| 13115 | request.url = GURL("http://www.foo.com/"); |
| 13116 | request.upload_data_stream = &upload_data_stream; |
| 13117 | request.load_flags = 0; |
| 13118 | |
| 13119 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13120 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13122 | // Send headers successfully, but get an error while sending the body. |
| 13123 | MockWrite data_writes[] = { |
| 13124 | MockWrite("POST / HTTP/1.1\r\n" |
| 13125 | "Host: www.foo.com\r\n" |
| 13126 | "Connection: keep-alive\r\n" |
| 13127 | "Content-Length: 3\r\n\r\n"), |
| 13128 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13129 | }; |
| 13130 | |
| 13131 | MockRead data_reads[] = { |
| 13132 | MockRead("HTTP 0.9 rocks!"), |
| 13133 | MockRead(SYNCHRONOUS, OK), |
| 13134 | }; |
| 13135 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13136 | arraysize(data_writes)); |
| 13137 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13138 | |
| 13139 | TestCompletionCallback callback; |
| 13140 | |
| 13141 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13142 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13143 | |
| 13144 | rv = callback.WaitForResult(); |
| 13145 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13146 | |
| 13147 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13148 | EXPECT_TRUE(response == NULL); |
| 13149 | } |
| 13150 | |
| 13151 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 13152 | ScopedVector<UploadElementReader> element_readers; |
| 13153 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13154 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13155 | |
| 13156 | HttpRequestInfo request; |
| 13157 | request.method = "POST"; |
| 13158 | request.url = GURL("http://www.foo.com/"); |
| 13159 | request.upload_data_stream = &upload_data_stream; |
| 13160 | request.load_flags = 0; |
| 13161 | |
| 13162 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13163 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13164 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13165 | // Send headers successfully, but get an error while sending the body. |
| 13166 | MockWrite data_writes[] = { |
| 13167 | MockWrite("POST / HTTP/1.1\r\n" |
| 13168 | "Host: www.foo.com\r\n" |
| 13169 | "Connection: keep-alive\r\n" |
| 13170 | "Content-Length: 3\r\n\r\n"), |
| 13171 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13172 | }; |
| 13173 | |
| 13174 | MockRead data_reads[] = { |
| 13175 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 13176 | MockRead(SYNCHRONOUS, OK), |
| 13177 | }; |
| 13178 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13179 | arraysize(data_writes)); |
| 13180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13181 | |
| 13182 | TestCompletionCallback callback; |
| 13183 | |
| 13184 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13185 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13186 | |
| 13187 | rv = callback.WaitForResult(); |
| 13188 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13189 | |
| 13190 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13191 | EXPECT_TRUE(response == NULL); |
| 13192 | } |
| 13193 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 13194 | } // namespace net |