[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" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 18 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 20 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 21 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 22 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 23 | #include "base/test/test_file_util.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 24 | #include "net/base/auth.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" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 30 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 31 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 32 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 33 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 34 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 35 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 36 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 37 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 38 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 39 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 40 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 41 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 42 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 43 | #include "net/http/http_basic_state.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" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 48 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 49 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 50 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 52 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 53 | #include "net/log/net_log.h" |
| 54 | #include "net/log/net_log_unittest.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 55 | #include "net/log/test_net_log.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 56 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 57 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 58 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 59 | #include "net/proxy/proxy_resolver.h" |
| 60 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 61 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 62 | #include "net/socket/client_socket_pool_manager.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 63 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 64 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 65 | #include "net/socket/socket_test_util.h" |
| 66 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 67 | #include "net/spdy/spdy_framer.h" |
| 68 | #include "net/spdy/spdy_session.h" |
| 69 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 70 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 71 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 72 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 73 | #include "net/ssl/ssl_config_service_defaults.h" |
| 74 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 75 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 76 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 77 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 78 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 79 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 80 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 81 | using base::ASCIIToUTF16; |
| 82 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 83 | //----------------------------------------------------------------------------- |
| 84 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 85 | namespace { |
| 86 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 87 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 88 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 89 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 90 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 91 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 92 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 93 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 94 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 95 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 96 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 97 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 98 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 99 | |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 100 | int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { |
| 101 | return session->GetTransportSocketPool( |
| 102 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 103 | } |
| 104 | |
| 105 | int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) { |
| 106 | return session->GetSSLSocketPool( |
| 107 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 108 | } |
| 109 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 110 | bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) { |
| 111 | return session->GetTransportSocketPool( |
| 112 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled(); |
| 113 | } |
| 114 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 115 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 116 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 117 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 118 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 119 | if (!params) |
| 120 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 121 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 122 | if (!params->GetList("headers", &header_list)) |
| 123 | return false; |
| 124 | std::string double_quote_headers; |
| 125 | base::JSONWriter::Write(header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 126 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 127 | return true; |
| 128 | } |
| 129 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 130 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 131 | // used. |
| 132 | void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) { |
| 133 | EXPECT_TRUE(load_timing_info.socket_reused); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 134 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 135 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 136 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 137 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 138 | |
| 139 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 140 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 141 | |
| 142 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 143 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 144 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 145 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 146 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 147 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 150 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 151 | // used. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 152 | void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info, |
| 153 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 154 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 155 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 156 | |
| 157 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 158 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 159 | |
| 160 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 161 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 163 | load_timing_info.send_start); |
| 164 | |
| 165 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 166 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 167 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 168 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 169 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 170 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 174 | // used. |
| 175 | void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) { |
| 176 | EXPECT_TRUE(load_timing_info.socket_reused); |
| 177 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 178 | |
| 179 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 180 | |
| 181 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 182 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 183 | load_timing_info.proxy_resolve_end); |
| 184 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 185 | load_timing_info.send_start); |
| 186 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 187 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 188 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 190 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 191 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 195 | // used. |
| 196 | void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info, |
| 197 | int connect_timing_flags) { |
| 198 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 199 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 200 | |
| 201 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 202 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 203 | load_timing_info.proxy_resolve_end); |
| 204 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 205 | load_timing_info.connect_timing.connect_start); |
| 206 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 207 | connect_timing_flags); |
| 208 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 209 | load_timing_info.send_start); |
| 210 | |
| 211 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 213 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 215 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 216 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 217 | } |
| 218 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 219 | void AddWebSocketHeaders(net::HttpRequestHeaders* headers) { |
| 220 | headers->SetHeader("Connection", "Upgrade"); |
| 221 | headers->SetHeader("Upgrade", "websocket"); |
| 222 | headers->SetHeader("Origin", "http://www.google.com"); |
| 223 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 224 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 225 | } |
| 226 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 227 | } // namespace |
| 228 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 229 | namespace net { |
| 230 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 231 | namespace { |
| 232 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 233 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 234 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 237 | } // namespace |
| 238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 239 | class HttpNetworkTransactionTest |
| 240 | : public PlatformTest, |
| 241 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 242 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 243 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | // Important to restore the per-pool limit first, since the pool limit must |
| 245 | // always be greater than group limit, and the tests reduce both limits. |
| 246 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 247 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 248 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 250 | } |
| 251 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 252 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 253 | HttpNetworkTransactionTest() |
| 254 | : spdy_util_(GetParam()), |
| 255 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 256 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 257 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 258 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 260 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 261 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 262 | struct SimpleGetHelperResult { |
| 263 | int rv; |
| 264 | std::string status_line; |
| 265 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 266 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 267 | LoadTimingInfo load_timing_info; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 268 | }; |
| 269 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 270 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 271 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 272 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 273 | } |
| 274 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 275 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 276 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 277 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 278 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 279 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 280 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 281 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 282 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 283 | } |
| 284 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 285 | const char* GetAlternateProtocolFromParam() { |
| 286 | return |
| 287 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 288 | } |
| 289 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 290 | // This is the expected return from a current server advertising SPDY. |
| 291 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 292 | return std::string("Alternate-Protocol: 443:") + |
| 293 | GetAlternateProtocolFromParam() + "\r\n\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 296 | // Either |write_failure| specifies a write failure or |read_failure| |
| 297 | // specifies a read failure when using a reused socket. In either case, the |
| 298 | // failure should cause the network transaction to resend the request, and the |
| 299 | // other argument should be NULL. |
| 300 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 301 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 302 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 303 | // Either |write_failure| specifies a write failure or |read_failure| |
| 304 | // specifies a read failure when using a reused socket. In either case, the |
| 305 | // failure should cause the network transaction to resend the request, and the |
| 306 | // other argument should be NULL. |
| 307 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 308 | const MockRead* read_failure, |
| 309 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 310 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 311 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 312 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 313 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 314 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 315 | HttpRequestInfo request; |
| 316 | request.method = "GET"; |
| 317 | request.url = GURL("http://www.google.com/"); |
| 318 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 319 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 320 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 321 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 322 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 323 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 324 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 325 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 326 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 327 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 328 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 330 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 331 | |
[email protected] | c47c037 | 2014-03-12 23:07:02 | [diff] [blame] | 332 | EXPECT_TRUE(log.bound().IsLogging()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 333 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 335 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 336 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 337 | |
| 338 | // Even in the failure cases that use this function, connections are always |
| 339 | // successfully established before the error. |
| 340 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 341 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 342 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 343 | if (out.rv != OK) |
| 344 | return out; |
| 345 | |
| 346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 347 | // Can't use ASSERT_* inside helper functions like this, so |
| 348 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 349 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 350 | out.rv = ERR_UNEXPECTED; |
| 351 | return out; |
| 352 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | out.status_line = response->headers->GetStatusLine(); |
| 354 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 355 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 356 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 357 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 358 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 359 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 360 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 361 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 362 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 363 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 364 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 365 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 366 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 367 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 368 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 369 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 370 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 371 | std::string line; |
| 372 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 373 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 374 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 375 | HttpRequestHeaders request_headers; |
| 376 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 377 | std::string value; |
| 378 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
| 379 | EXPECT_EQ("www.google.com", value); |
| 380 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 381 | EXPECT_EQ("keep-alive", value); |
| 382 | |
| 383 | std::string response_headers; |
| 384 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
| 385 | EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", |
| 386 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 387 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 388 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 389 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 390 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 391 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 392 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 393 | size_t reads_count) { |
| 394 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 395 | StaticSocketDataProvider* data[] = { &reads }; |
| 396 | return SimpleGetHelperForData(data, 1); |
| 397 | } |
| 398 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 399 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 400 | int64 size = 0; |
| 401 | for (size_t i = 0; i < reads_count; ++i) |
| 402 | size += data_reads[i].data_len; |
| 403 | return size; |
| 404 | } |
| 405 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 406 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 407 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 408 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 409 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 410 | |
| 411 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 412 | |
| 413 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 414 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 415 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 416 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 417 | |
| 418 | // Original socket limits. Some tests set these. Safest to always restore |
| 419 | // them once each test has been run. |
| 420 | int old_max_group_sockets_; |
| 421 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 422 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 423 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 424 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 425 | HttpNetworkTransactionTest, |
| 426 | testing::Values(kProtoSPDY31, |
| 427 | kProtoSPDY4_14, |
| 428 | kProtoSPDY4)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 429 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 430 | namespace { |
| 431 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 432 | class BeforeNetworkStartHandler { |
| 433 | public: |
| 434 | explicit BeforeNetworkStartHandler(bool defer) |
| 435 | : defer_on_before_network_start_(defer), |
| 436 | observed_before_network_start_(false) {} |
| 437 | |
| 438 | void OnBeforeNetworkStart(bool* defer) { |
| 439 | *defer = defer_on_before_network_start_; |
| 440 | observed_before_network_start_ = true; |
| 441 | } |
| 442 | |
| 443 | bool observed_before_network_start() const { |
| 444 | return observed_before_network_start_; |
| 445 | } |
| 446 | |
| 447 | private: |
| 448 | const bool defer_on_before_network_start_; |
| 449 | bool observed_before_network_start_; |
| 450 | |
| 451 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 452 | }; |
| 453 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 454 | class BeforeProxyHeadersSentHandler { |
| 455 | public: |
| 456 | BeforeProxyHeadersSentHandler() |
| 457 | : observed_before_proxy_headers_sent_(false) {} |
| 458 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 459 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 460 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 461 | observed_before_proxy_headers_sent_ = true; |
| 462 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 463 | } |
| 464 | |
| 465 | bool observed_before_proxy_headers_sent() const { |
| 466 | return observed_before_proxy_headers_sent_; |
| 467 | } |
| 468 | |
| 469 | std::string observed_proxy_server_uri() const { |
| 470 | return observed_proxy_server_uri_; |
| 471 | } |
| 472 | |
| 473 | private: |
| 474 | bool observed_before_proxy_headers_sent_; |
| 475 | std::string observed_proxy_server_uri_; |
| 476 | |
| 477 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 478 | }; |
| 479 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 480 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 481 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 482 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 483 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 484 | const int sizeof_row = strlen(row); |
| 485 | const int num_rows = static_cast<int>( |
| 486 | ceil(static_cast<float>(size) / sizeof_row)); |
| 487 | const int sizeof_data = num_rows * sizeof_row; |
| 488 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 489 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 490 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 491 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 492 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 495 | // Alternative functions that eliminate randomness and dependency on the local |
| 496 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 497 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 498 | static const uint8 bytes[] = { |
| 499 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 500 | }; |
| 501 | static size_t current_byte = 0; |
| 502 | for (size_t i = 0; i < n; ++i) { |
| 503 | output[i] = bytes[current_byte++]; |
| 504 | current_byte %= arraysize(bytes); |
| 505 | } |
| 506 | } |
| 507 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 508 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 509 | static const uint8 bytes[] = { |
| 510 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 511 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 512 | }; |
| 513 | static size_t current_byte = 0; |
| 514 | for (size_t i = 0; i < n; ++i) { |
| 515 | output[i] = bytes[current_byte++]; |
| 516 | current_byte %= arraysize(bytes); |
| 517 | } |
| 518 | } |
| 519 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 520 | std::string MockGetHostName() { |
| 521 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 524 | template<typename ParentPool> |
| 525 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 526 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 527 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 528 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 529 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 530 | const std::string last_group_name_received() const { |
| 531 | return last_group_name_; |
| 532 | } |
| 533 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 534 | int RequestSocket(const std::string& group_name, |
| 535 | const void* socket_params, |
| 536 | RequestPriority priority, |
| 537 | ClientSocketHandle* handle, |
| 538 | const CompletionCallback& callback, |
| 539 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 540 | last_group_name_ = group_name; |
| 541 | return ERR_IO_PENDING; |
| 542 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 543 | void CancelRequest(const std::string& group_name, |
| 544 | ClientSocketHandle* handle) override {} |
| 545 | void ReleaseSocket(const std::string& group_name, |
| 546 | scoped_ptr<StreamSocket> socket, |
| 547 | int id) override {} |
| 548 | void CloseIdleSockets() override {} |
| 549 | int IdleSocketCount() const override { return 0; } |
| 550 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 551 | return 0; |
| 552 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 553 | LoadState GetLoadState(const std::string& group_name, |
| 554 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 555 | return LOAD_STATE_IDLE; |
| 556 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 557 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 558 | return base::TimeDelta(); |
| 559 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 560 | |
| 561 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 562 | std::string last_group_name_; |
| 563 | }; |
| 564 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 565 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 566 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 567 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 568 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 569 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 570 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 571 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 572 | CaptureGroupNameSSLSocketPool; |
| 573 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 574 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 575 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 576 | HostResolver* host_resolver, |
| 577 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 578 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 579 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 580 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 581 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 582 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 583 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 584 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 585 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 586 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 587 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 588 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 589 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 590 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 591 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 592 | : SSLClientSocketPool(0, |
| 593 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 594 | cert_verifier, |
| 595 | NULL, |
| 596 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 597 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 598 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 599 | std::string(), |
| 600 | NULL, |
| 601 | NULL, |
| 602 | NULL, |
| 603 | NULL, |
| 604 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 605 | NULL) { |
| 606 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 607 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 608 | //----------------------------------------------------------------------------- |
| 609 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 610 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 611 | // configured for common cases. |
| 612 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 613 | if (!auth_challenge) |
| 614 | return false; |
| 615 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 616 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 617 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 618 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 619 | return true; |
| 620 | } |
| 621 | |
| 622 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 623 | if (!auth_challenge) |
| 624 | return false; |
| 625 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 626 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 627 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 628 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 629 | return true; |
| 630 | } |
| 631 | |
| 632 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 633 | if (!auth_challenge) |
| 634 | return false; |
| 635 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 636 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 637 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 638 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 639 | return true; |
| 640 | } |
| 641 | |
| 642 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 643 | if (!auth_challenge) |
| 644 | return false; |
| 645 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 646 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 647 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 648 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 649 | return true; |
| 650 | } |
| 651 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 652 | } // namespace |
| 653 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 654 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 655 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 656 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 658 | } |
| 659 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 660 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 661 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 662 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 663 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 664 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 665 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 666 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 667 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 668 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 669 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 670 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 671 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 672 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 676 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 677 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 678 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 679 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 680 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 681 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 682 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 683 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 684 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 685 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 686 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 687 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 691 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 692 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 693 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 695 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 696 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 697 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 698 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 699 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 700 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 701 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 702 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 706 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 707 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 708 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 710 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 711 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 712 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 713 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 714 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 715 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 716 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 717 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | // 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] | 721 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 723 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 726 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 727 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 728 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 729 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 730 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 731 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 732 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 736 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 738 | MockRead("\n"), |
| 739 | MockRead("\n"), |
| 740 | MockRead("Q"), |
| 741 | MockRead("J"), |
| 742 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 743 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 745 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 746 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 747 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 748 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 749 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 750 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 751 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 755 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 756 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 757 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 758 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 759 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 760 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 761 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 762 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 764 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 765 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 766 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 767 | } |
| 768 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 769 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 770 | // persistent connection. The response should still terminate since a 204 |
| 771 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 772 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 773 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 774 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 775 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 776 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 777 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 778 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 779 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 780 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 781 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 782 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 783 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 784 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 785 | int64 response_size = reads_size - strlen(junk); |
| 786 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 789 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 790 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 791 | std::string final_chunk = "0\r\n\r\n"; |
| 792 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 793 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 794 | MockRead data_reads[] = { |
| 795 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 796 | MockRead("5\r\nHello\r\n"), |
| 797 | MockRead("1\r\n"), |
| 798 | MockRead(" \r\n"), |
| 799 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 800 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 802 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 803 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 804 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 805 | EXPECT_EQ(OK, out.rv); |
| 806 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 807 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 808 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 809 | int64 response_size = reads_size - extra_data.size(); |
| 810 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 811 | } |
| 812 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 813 | // Next tests deal with http://crbug.com/56344. |
| 814 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 815 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 816 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 817 | MockRead data_reads[] = { |
| 818 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 819 | MockRead("Content-Length: 10\r\n"), |
| 820 | MockRead("Content-Length: 5\r\n\r\n"), |
| 821 | }; |
| 822 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 823 | arraysize(data_reads)); |
| 824 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 825 | } |
| 826 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 827 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 828 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 829 | MockRead data_reads[] = { |
| 830 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 831 | MockRead("Content-Length: 5\r\n"), |
| 832 | MockRead("Content-Length: 5\r\n\r\n"), |
| 833 | MockRead("Hello"), |
| 834 | }; |
| 835 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 836 | arraysize(data_reads)); |
| 837 | EXPECT_EQ(OK, out.rv); |
| 838 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 839 | EXPECT_EQ("Hello", out.response_data); |
| 840 | } |
| 841 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 842 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 843 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 844 | // More than 2 dupes. |
| 845 | { |
| 846 | MockRead data_reads[] = { |
| 847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 848 | MockRead("Content-Length: 5\r\n"), |
| 849 | MockRead("Content-Length: 5\r\n"), |
| 850 | MockRead("Content-Length: 5\r\n\r\n"), |
| 851 | MockRead("Hello"), |
| 852 | }; |
| 853 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 854 | arraysize(data_reads)); |
| 855 | EXPECT_EQ(OK, out.rv); |
| 856 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 857 | EXPECT_EQ("Hello", out.response_data); |
| 858 | } |
| 859 | // HTTP/1.0 |
| 860 | { |
| 861 | MockRead data_reads[] = { |
| 862 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 863 | MockRead("Content-Length: 5\r\n"), |
| 864 | MockRead("Content-Length: 5\r\n"), |
| 865 | MockRead("Content-Length: 5\r\n\r\n"), |
| 866 | MockRead("Hello"), |
| 867 | }; |
| 868 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 869 | arraysize(data_reads)); |
| 870 | EXPECT_EQ(OK, out.rv); |
| 871 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 872 | EXPECT_EQ("Hello", out.response_data); |
| 873 | } |
| 874 | // 2 dupes and one mismatched. |
| 875 | { |
| 876 | MockRead data_reads[] = { |
| 877 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 878 | MockRead("Content-Length: 10\r\n"), |
| 879 | MockRead("Content-Length: 10\r\n"), |
| 880 | MockRead("Content-Length: 5\r\n\r\n"), |
| 881 | }; |
| 882 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 883 | arraysize(data_reads)); |
| 884 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 885 | } |
| 886 | } |
| 887 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 888 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 889 | MultipleContentLengthHeadersTransferEncoding) { |
| 890 | MockRead data_reads[] = { |
| 891 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 892 | MockRead("Content-Length: 666\r\n"), |
| 893 | MockRead("Content-Length: 1337\r\n"), |
| 894 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 895 | MockRead("5\r\nHello\r\n"), |
| 896 | MockRead("1\r\n"), |
| 897 | MockRead(" \r\n"), |
| 898 | MockRead("5\r\nworld\r\n"), |
| 899 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 900 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 901 | }; |
| 902 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 903 | arraysize(data_reads)); |
| 904 | EXPECT_EQ(OK, out.rv); |
| 905 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 906 | EXPECT_EQ("Hello world", out.response_data); |
| 907 | } |
| 908 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 909 | // Next tests deal with http://crbug.com/98895. |
| 910 | |
| 911 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 912 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 913 | MockRead data_reads[] = { |
| 914 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 915 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 916 | MockRead("Content-Length: 5\r\n\r\n"), |
| 917 | MockRead("Hello"), |
| 918 | }; |
| 919 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 920 | arraysize(data_reads)); |
| 921 | EXPECT_EQ(OK, out.rv); |
| 922 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 923 | EXPECT_EQ("Hello", out.response_data); |
| 924 | } |
| 925 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 926 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 927 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 928 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 929 | MockRead data_reads[] = { |
| 930 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 931 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 932 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 933 | MockRead("Content-Length: 5\r\n\r\n"), |
| 934 | MockRead("Hello"), |
| 935 | }; |
| 936 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 937 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 938 | EXPECT_EQ(OK, out.rv); |
| 939 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 940 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 944 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 945 | MockRead data_reads[] = { |
| 946 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 947 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 948 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 949 | MockRead("Content-Length: 5\r\n\r\n"), |
| 950 | MockRead("Hello"), |
| 951 | }; |
| 952 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 953 | arraysize(data_reads)); |
| 954 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 955 | } |
| 956 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 957 | // Checks that two identical Location headers result in no error. |
| 958 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 959 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 960 | MockRead data_reads[] = { |
| 961 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 962 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 963 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 964 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 966 | }; |
| 967 | |
| 968 | HttpRequestInfo request; |
| 969 | request.method = "GET"; |
| 970 | request.url = GURL("http://redirect.com/"); |
| 971 | request.load_flags = 0; |
| 972 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 973 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 974 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 975 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 976 | |
| 977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 980 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 982 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 983 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 984 | |
| 985 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 986 | |
| 987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 988 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 989 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 990 | std::string url; |
| 991 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 992 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 993 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 994 | } |
| 995 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 996 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 997 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 998 | MockRead data_reads[] = { |
| 999 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1000 | MockRead("Location: http://good.com/\r\n"), |
| 1001 | MockRead("Location: http://evil.com/\r\n"), |
| 1002 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1003 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1004 | }; |
| 1005 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1006 | arraysize(data_reads)); |
| 1007 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1008 | } |
| 1009 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1010 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1011 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1012 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1013 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1014 | request.method = "HEAD"; |
| 1015 | request.url = GURL("http://www.google.com/"); |
| 1016 | request.load_flags = 0; |
| 1017 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1018 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1019 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1021 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1022 | trans->SetBeforeProxyHeadersSentCallback( |
| 1023 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1024 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1025 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1026 | MockWrite data_writes1[] = { |
| 1027 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1028 | "Host: www.google.com\r\n" |
| 1029 | "Connection: keep-alive\r\n" |
| 1030 | "Content-Length: 0\r\n\r\n"), |
| 1031 | }; |
| 1032 | MockRead data_reads1[] = { |
| 1033 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1034 | MockRead("Server: Blah\r\n"), |
| 1035 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1036 | |
| 1037 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1038 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1039 | }; |
| 1040 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1041 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1042 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1043 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1045 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1047 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1048 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1049 | |
| 1050 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1051 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1052 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1053 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1054 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1055 | |
| 1056 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1057 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1058 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1059 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1060 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1061 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1062 | |
| 1063 | std::string server_header; |
| 1064 | void* iter = NULL; |
| 1065 | bool has_server_header = response->headers->EnumerateHeader( |
| 1066 | &iter, "Server", &server_header); |
| 1067 | EXPECT_TRUE(has_server_header); |
| 1068 | EXPECT_EQ("Blah", server_header); |
| 1069 | |
| 1070 | // Reading should give EOF right away, since there is no message body |
| 1071 | // (despite non-zero content-length). |
| 1072 | std::string response_data; |
| 1073 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1074 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1075 | EXPECT_EQ("", response_data); |
| 1076 | } |
| 1077 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1078 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1079 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1080 | |
| 1081 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1082 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1083 | MockRead("hello"), |
| 1084 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1085 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1086 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1087 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1088 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1089 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1090 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1091 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1092 | "hello", "world" |
| 1093 | }; |
| 1094 | |
| 1095 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1096 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1097 | request.method = "GET"; |
| 1098 | request.url = GURL("http://www.google.com/"); |
| 1099 | request.load_flags = 0; |
| 1100 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1101 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1102 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1104 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1106 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1108 | |
| 1109 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1110 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1111 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1112 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1113 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1114 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1115 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1116 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1117 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1118 | |
| 1119 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1120 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1121 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1122 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1126 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1127 | ScopedVector<UploadElementReader> element_readers; |
| 1128 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1129 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1130 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1131 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1132 | request.method = "POST"; |
| 1133 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1134 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1135 | request.load_flags = 0; |
| 1136 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1137 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1138 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1139 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1140 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1141 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1142 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1143 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1144 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1145 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1146 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1147 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1150 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1152 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1154 | |
| 1155 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1156 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1157 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1158 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1159 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1160 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1161 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1162 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1163 | |
| 1164 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1165 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1167 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1168 | } |
| 1169 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1170 | // This test is almost the same as Ignores100 above, but the response contains |
| 1171 | // 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] | 1172 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1173 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1174 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1175 | request.method = "GET"; |
| 1176 | request.url = GURL("http://www.foo.com/"); |
| 1177 | request.load_flags = 0; |
| 1178 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1179 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1180 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1182 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1183 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1184 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1185 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1186 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1187 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1188 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1189 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1190 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1191 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1192 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1194 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1195 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1196 | |
| 1197 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1198 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1199 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1200 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1201 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1202 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1203 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1204 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1205 | |
| 1206 | std::string response_data; |
| 1207 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1208 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1209 | EXPECT_EQ("hello world", response_data); |
| 1210 | } |
| 1211 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1212 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1213 | HttpRequestInfo request; |
| 1214 | request.method = "POST"; |
| 1215 | request.url = GURL("http://www.foo.com/"); |
| 1216 | request.load_flags = 0; |
| 1217 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1218 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1219 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1221 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1222 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1223 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1224 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1225 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1226 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1228 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1229 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1231 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1232 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1233 | |
| 1234 | rv = callback.WaitForResult(); |
| 1235 | EXPECT_EQ(OK, rv); |
| 1236 | |
| 1237 | std::string response_data; |
| 1238 | rv = ReadTransaction(trans.get(), &response_data); |
| 1239 | EXPECT_EQ(OK, rv); |
| 1240 | EXPECT_EQ("", response_data); |
| 1241 | } |
| 1242 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1243 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1244 | HttpRequestInfo request; |
| 1245 | request.method = "POST"; |
| 1246 | request.url = GURL("http://www.foo.com/"); |
| 1247 | request.load_flags = 0; |
| 1248 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1249 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1250 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1252 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1253 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1254 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1255 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1259 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1261 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1262 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1263 | |
| 1264 | rv = callback.WaitForResult(); |
| 1265 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1266 | } |
| 1267 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1268 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1269 | const MockWrite* write_failure, |
| 1270 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1271 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1272 | request.method = "GET"; |
| 1273 | request.url = GURL("http://www.foo.com/"); |
| 1274 | request.load_flags = 0; |
| 1275 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 1276 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1277 | session_deps_.net_log = &net_log; |
| 1278 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1279 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1280 | // Written data for successfully sending both requests. |
| 1281 | MockWrite data1_writes[] = { |
| 1282 | MockWrite("GET / HTTP/1.1\r\n" |
| 1283 | "Host: www.foo.com\r\n" |
| 1284 | "Connection: keep-alive\r\n\r\n"), |
| 1285 | MockWrite("GET / HTTP/1.1\r\n" |
| 1286 | "Host: www.foo.com\r\n" |
| 1287 | "Connection: keep-alive\r\n\r\n") |
| 1288 | }; |
| 1289 | |
| 1290 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1291 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1292 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1293 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1294 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1295 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1296 | |
| 1297 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1298 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1299 | data1_writes[1] = *write_failure; |
| 1300 | } else { |
| 1301 | ASSERT_TRUE(read_failure); |
| 1302 | data1_reads[2] = *read_failure; |
| 1303 | } |
| 1304 | |
| 1305 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1306 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1307 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1308 | |
| 1309 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1310 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1311 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1312 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1314 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1315 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1317 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | "hello", "world" |
| 1319 | }; |
| 1320 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1321 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1323 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1325 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1326 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1328 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1329 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | |
| 1331 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1332 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1334 | LoadTimingInfo load_timing_info; |
| 1335 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1336 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1337 | if (i == 0) { |
| 1338 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1339 | } else { |
| 1340 | // The second request should be using a new socket. |
| 1341 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1342 | } |
| 1343 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1344 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1345 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1347 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1348 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
| 1350 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1351 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1352 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1353 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1354 | } |
| 1355 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1356 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1357 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1358 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1359 | const MockRead* read_failure, |
| 1360 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1361 | HttpRequestInfo request; |
| 1362 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1363 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1364 | request.load_flags = 0; |
| 1365 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 1366 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1367 | session_deps_.net_log = &net_log; |
| 1368 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1369 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1370 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1371 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1372 | if (use_spdy) { |
| 1373 | ssl1.SetNextProto(GetParam()); |
| 1374 | ssl2.SetNextProto(GetParam()); |
| 1375 | } |
| 1376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1378 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1379 | // SPDY versions of the request and response. |
| 1380 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1381 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1382 | scoped_ptr<SpdyFrame> spdy_response( |
| 1383 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1384 | scoped_ptr<SpdyFrame> spdy_data( |
| 1385 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1386 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1387 | // HTTP/1.1 versions of the request and response. |
| 1388 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1389 | "Host: www.foo.com\r\n" |
| 1390 | "Connection: keep-alive\r\n\r\n"; |
| 1391 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1392 | const char kHttpData[] = "hello"; |
| 1393 | |
| 1394 | std::vector<MockRead> data1_reads; |
| 1395 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1396 | if (write_failure) { |
| 1397 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1398 | data1_writes.push_back(*write_failure); |
| 1399 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1400 | } else { |
| 1401 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1402 | if (use_spdy) { |
| 1403 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1404 | } else { |
| 1405 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1406 | } |
| 1407 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1408 | } |
| 1409 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1410 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1411 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1412 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1413 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1414 | std::vector<MockRead> data2_reads; |
| 1415 | std::vector<MockWrite> data2_writes; |
| 1416 | |
| 1417 | if (use_spdy) { |
| 1418 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1419 | |
| 1420 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1421 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1422 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1423 | } else { |
| 1424 | data2_writes.push_back( |
| 1425 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1426 | |
| 1427 | data2_reads.push_back( |
| 1428 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1429 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1430 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1431 | } |
| 1432 | OrderedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1433 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1434 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1435 | |
| 1436 | // Preconnect a socket. |
| 1437 | net::SSLConfig ssl_config; |
| 1438 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1439 | session->GetNextProtos(&ssl_config.next_protos); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1440 | session->http_stream_factory()->PreconnectStreams( |
| 1441 | 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config); |
| 1442 | // Wait for the preconnect to complete. |
| 1443 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1444 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1445 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1446 | |
| 1447 | // Make the request. |
| 1448 | TestCompletionCallback callback; |
| 1449 | |
| 1450 | scoped_ptr<HttpTransaction> trans( |
| 1451 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1452 | |
| 1453 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1454 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1455 | |
| 1456 | rv = callback.WaitForResult(); |
| 1457 | EXPECT_EQ(OK, rv); |
| 1458 | |
| 1459 | LoadTimingInfo load_timing_info; |
| 1460 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1461 | TestLoadTimingNotReused( |
| 1462 | load_timing_info, |
| 1463 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1464 | |
| 1465 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1466 | ASSERT_TRUE(response != NULL); |
| 1467 | |
| 1468 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1469 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1470 | |
| 1471 | std::string response_data; |
| 1472 | rv = ReadTransaction(trans.get(), &response_data); |
| 1473 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1474 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1475 | } |
| 1476 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1477 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1478 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1479 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1480 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1481 | } |
| 1482 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1483 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1484 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1485 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1486 | } |
| 1487 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1488 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1489 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1490 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1491 | } |
| 1492 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1493 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1494 | // if the socket was a reused keep alive socket. |
| 1495 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1496 | MockRead read_failure(SYNCHRONOUS, |
| 1497 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1498 | "Connection: Keep-Alive\r\n" |
| 1499 | "Content-Length: 6\r\n\r\n" |
| 1500 | "Pickle"); |
| 1501 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1502 | } |
| 1503 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | TEST_P(HttpNetworkTransactionTest, |
| 1505 | PreconnectErrorNotConnectedOnWrite) { |
| 1506 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1507 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1511 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1512 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1516 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1517 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1518 | } |
| 1519 | |
| 1520 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1521 | MockRead read_failure(ASYNC, OK); // EOF |
| 1522 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1523 | } |
| 1524 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1525 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1526 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1527 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1528 | MockRead read_failure(SYNCHRONOUS, |
| 1529 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1530 | "Connection: Keep-Alive\r\n" |
| 1531 | "Content-Length: 6\r\n\r\n" |
| 1532 | "Pickle"); |
| 1533 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1534 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1535 | } |
| 1536 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1537 | TEST_P(HttpNetworkTransactionTest, |
| 1538 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1539 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1540 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1541 | } |
| 1542 | |
| 1543 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1544 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1545 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1546 | } |
| 1547 | |
| 1548 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1549 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1550 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1551 | } |
| 1552 | |
| 1553 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1554 | MockRead read_failure(ASYNC, OK); // EOF |
| 1555 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1556 | } |
| 1557 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1558 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1559 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1560 | request.method = "GET"; |
| 1561 | request.url = GURL("http://www.google.com/"); |
| 1562 | request.load_flags = 0; |
| 1563 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1564 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1565 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1566 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1567 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1568 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1569 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1570 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1571 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1572 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1573 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1574 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1575 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1577 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1579 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1581 | |
| 1582 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1583 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1584 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1586 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | // What do various browsers do when the server closes a non-keepalive |
| 1590 | // connection without sending any response header or body? |
| 1591 | // |
| 1592 | // IE7: error page |
| 1593 | // Safari 3.1.2 (Windows): error page |
| 1594 | // Firefox 3.0.1: blank page |
| 1595 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1596 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1597 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1598 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1599 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1600 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1601 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1602 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1603 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1604 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1605 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1606 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1607 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1608 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1609 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1610 | // Test that network access can be deferred and resumed. |
| 1611 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1612 | HttpRequestInfo request; |
| 1613 | request.method = "GET"; |
| 1614 | request.url = GURL("http://www.google.com/"); |
| 1615 | request.load_flags = 0; |
| 1616 | |
| 1617 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1618 | scoped_ptr<HttpTransaction> trans( |
| 1619 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1620 | |
| 1621 | // Defer on OnBeforeNetworkStart. |
| 1622 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1623 | trans->SetBeforeNetworkStartCallback( |
| 1624 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1625 | base::Unretained(&net_start_handler))); |
| 1626 | |
| 1627 | MockRead data_reads[] = { |
| 1628 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1629 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1630 | MockRead("hello"), |
| 1631 | MockRead(SYNCHRONOUS, 0), |
| 1632 | }; |
| 1633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1635 | |
| 1636 | TestCompletionCallback callback; |
| 1637 | |
| 1638 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1640 | base::MessageLoop::current()->RunUntilIdle(); |
| 1641 | |
| 1642 | // Should have deferred for network start. |
| 1643 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1644 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1645 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1646 | |
| 1647 | trans->ResumeNetworkStart(); |
| 1648 | rv = callback.WaitForResult(); |
| 1649 | EXPECT_EQ(OK, rv); |
| 1650 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1651 | |
| 1652 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1653 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1654 | if (rv == ERR_IO_PENDING) |
| 1655 | rv = callback.WaitForResult(); |
| 1656 | EXPECT_EQ(5, rv); |
| 1657 | trans.reset(); |
| 1658 | } |
| 1659 | |
| 1660 | // Test that network use can be deferred and canceled. |
| 1661 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1662 | HttpRequestInfo request; |
| 1663 | request.method = "GET"; |
| 1664 | request.url = GURL("http://www.google.com/"); |
| 1665 | request.load_flags = 0; |
| 1666 | |
| 1667 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1668 | scoped_ptr<HttpTransaction> trans( |
| 1669 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1670 | |
| 1671 | // Defer on OnBeforeNetworkStart. |
| 1672 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1673 | trans->SetBeforeNetworkStartCallback( |
| 1674 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1675 | base::Unretained(&net_start_handler))); |
| 1676 | |
| 1677 | TestCompletionCallback callback; |
| 1678 | |
| 1679 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1680 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1681 | base::MessageLoop::current()->RunUntilIdle(); |
| 1682 | |
| 1683 | // Should have deferred for network start. |
| 1684 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1685 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1686 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1687 | } |
| 1688 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1689 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1690 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1691 | // destructor in such situations. |
| 1692 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1693 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1694 | HttpRequestInfo request; |
| 1695 | request.method = "GET"; |
| 1696 | request.url = GURL("http://www.google.com/"); |
| 1697 | request.load_flags = 0; |
| 1698 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1699 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1700 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1701 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1702 | |
| 1703 | MockRead data_reads[] = { |
| 1704 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1705 | MockRead("Connection: keep-alive\r\n"), |
| 1706 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1707 | MockRead("hello"), |
| 1708 | MockRead(SYNCHRONOUS, 0), |
| 1709 | }; |
| 1710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1712 | |
| 1713 | TestCompletionCallback callback; |
| 1714 | |
| 1715 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1716 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1717 | |
| 1718 | rv = callback.WaitForResult(); |
| 1719 | EXPECT_EQ(OK, rv); |
| 1720 | |
| 1721 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1722 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1723 | if (rv == ERR_IO_PENDING) |
| 1724 | rv = callback.WaitForResult(); |
| 1725 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1726 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1727 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1728 | |
| 1729 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1730 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1731 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1732 | } |
| 1733 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1734 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1735 | HttpRequestInfo request; |
| 1736 | request.method = "GET"; |
| 1737 | request.url = GURL("http://www.google.com/"); |
| 1738 | request.load_flags = 0; |
| 1739 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1740 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1741 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1742 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1743 | |
| 1744 | MockRead data_reads[] = { |
| 1745 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1746 | MockRead("Connection: keep-alive\r\n"), |
| 1747 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1748 | MockRead(SYNCHRONOUS, 0), |
| 1749 | }; |
| 1750 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1752 | |
| 1753 | TestCompletionCallback callback; |
| 1754 | |
| 1755 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1757 | |
| 1758 | rv = callback.WaitForResult(); |
| 1759 | EXPECT_EQ(OK, rv); |
| 1760 | |
| 1761 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1762 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1763 | if (rv == ERR_IO_PENDING) |
| 1764 | rv = callback.WaitForResult(); |
| 1765 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1766 | |
| 1767 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1768 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1769 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1770 | } |
| 1771 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1772 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1773 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1774 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1775 | HttpRequestInfo request; |
| 1776 | request.method = "GET"; |
| 1777 | request.url = GURL("http://www.foo.com/"); |
| 1778 | request.load_flags = 0; |
| 1779 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 1780 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1781 | session_deps_.net_log = &net_log; |
| 1782 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1783 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1784 | // Note that because all these reads happen in the same |
| 1785 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1786 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1787 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1788 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1789 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1790 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1791 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1792 | "Content-Length: 0\r\n\r\n"), |
| 1793 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1794 | "Content-Length: 5\r\n\r\n" |
| 1795 | "hello"), |
| 1796 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1797 | "Content-Length: 0\r\n\r\n"), |
| 1798 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1799 | "Content-Length: 5\r\n\r\n" |
| 1800 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1801 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1802 | MockRead("hello"), |
| 1803 | }; |
| 1804 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1805 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1806 | |
| 1807 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1808 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1809 | }; |
| 1810 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1811 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1812 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1813 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1814 | std::string response_lines[kNumUnreadBodies]; |
| 1815 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1816 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1817 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1818 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1819 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1820 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1821 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1823 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1824 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1825 | |
| 1826 | rv = callback.WaitForResult(); |
| 1827 | EXPECT_EQ(OK, rv); |
| 1828 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1829 | LoadTimingInfo load_timing_info; |
| 1830 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1831 | if (i == 0) { |
| 1832 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1833 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1834 | } else { |
| 1835 | TestLoadTimingReused(load_timing_info); |
| 1836 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1837 | } |
| 1838 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1839 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1840 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1841 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1842 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1843 | response_lines[i] = response->headers->GetStatusLine(); |
| 1844 | |
| 1845 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1846 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1847 | |
| 1848 | const char* const kStatusLines[] = { |
| 1849 | "HTTP/1.1 204 No Content", |
| 1850 | "HTTP/1.1 205 Reset Content", |
| 1851 | "HTTP/1.1 304 Not Modified", |
| 1852 | "HTTP/1.1 302 Found", |
| 1853 | "HTTP/1.1 302 Found", |
| 1854 | "HTTP/1.1 301 Moved Permanently", |
| 1855 | "HTTP/1.1 301 Moved Permanently", |
| 1856 | }; |
| 1857 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1858 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1859 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1860 | |
| 1861 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1862 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1864 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1865 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1866 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1867 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1868 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1869 | rv = callback.WaitForResult(); |
| 1870 | EXPECT_EQ(OK, rv); |
| 1871 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1872 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1873 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1874 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1875 | std::string response_data; |
| 1876 | rv = ReadTransaction(trans.get(), &response_data); |
| 1877 | EXPECT_EQ(OK, rv); |
| 1878 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1879 | } |
| 1880 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1881 | // Test the request-challenge-retry sequence for basic auth. |
| 1882 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1883 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1884 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1885 | request.method = "GET"; |
| 1886 | request.url = GURL("http://www.google.com/"); |
| 1887 | request.load_flags = 0; |
| 1888 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 1889 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1890 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1891 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1892 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1893 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1894 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1895 | MockWrite data_writes1[] = { |
| 1896 | MockWrite("GET / HTTP/1.1\r\n" |
| 1897 | "Host: www.google.com\r\n" |
| 1898 | "Connection: keep-alive\r\n\r\n"), |
| 1899 | }; |
| 1900 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1901 | MockRead data_reads1[] = { |
| 1902 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1903 | // Give a couple authenticate options (only the middle one is actually |
| 1904 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1905 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1906 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1907 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1908 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1909 | // Large content-length -- won't matter, as connection will be reset. |
| 1910 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1911 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1912 | }; |
| 1913 | |
| 1914 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1915 | // be issuing -- the final header line contains the credentials. |
| 1916 | MockWrite data_writes2[] = { |
| 1917 | MockWrite("GET / HTTP/1.1\r\n" |
| 1918 | "Host: www.google.com\r\n" |
| 1919 | "Connection: keep-alive\r\n" |
| 1920 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1921 | }; |
| 1922 | |
| 1923 | // Lastly, the server responds with the actual content. |
| 1924 | MockRead data_reads2[] = { |
| 1925 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1926 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1927 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1928 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1929 | }; |
| 1930 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1931 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1932 | data_writes1, arraysize(data_writes1)); |
| 1933 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1934 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1935 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1936 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1938 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1940 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1941 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1942 | |
| 1943 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1944 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1945 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1946 | LoadTimingInfo load_timing_info1; |
| 1947 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1948 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1949 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1950 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1951 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1952 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1953 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1954 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1955 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1957 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1959 | rv = trans->RestartWithAuth( |
| 1960 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1961 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1962 | |
| 1963 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1964 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1965 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1966 | LoadTimingInfo load_timing_info2; |
| 1967 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1968 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1969 | // The load timing after restart should have a new socket ID, and times after |
| 1970 | // those of the first load timing. |
| 1971 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1972 | load_timing_info2.connect_timing.connect_start); |
| 1973 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1974 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1975 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1976 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1977 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1978 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1979 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1980 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1981 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1982 | } |
| 1983 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1984 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1985 | HttpRequestInfo request; |
| 1986 | request.method = "GET"; |
| 1987 | request.url = GURL("http://www.google.com/"); |
| 1988 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1989 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1990 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1991 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1992 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1993 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1994 | MockWrite data_writes[] = { |
| 1995 | MockWrite("GET / HTTP/1.1\r\n" |
| 1996 | "Host: www.google.com\r\n" |
| 1997 | "Connection: keep-alive\r\n\r\n"), |
| 1998 | }; |
| 1999 | |
| 2000 | MockRead data_reads[] = { |
| 2001 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2002 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2003 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2004 | // Large content-length -- won't matter, as connection will be reset. |
| 2005 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2006 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2007 | }; |
| 2008 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2009 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2010 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2012 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2014 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2015 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2016 | |
| 2017 | rv = callback.WaitForResult(); |
| 2018 | EXPECT_EQ(0, rv); |
| 2019 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2020 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2021 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2022 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2023 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2024 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2025 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2026 | } |
| 2027 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2028 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2029 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2030 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2031 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2032 | request.method = "GET"; |
| 2033 | request.url = GURL("http://www.google.com/"); |
| 2034 | request.load_flags = 0; |
| 2035 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2036 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2037 | session_deps_.net_log = &log; |
| 2038 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2039 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2040 | MockWrite data_writes1[] = { |
| 2041 | MockWrite("GET / HTTP/1.1\r\n" |
| 2042 | "Host: www.google.com\r\n" |
| 2043 | "Connection: keep-alive\r\n\r\n"), |
| 2044 | |
| 2045 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2046 | // be issuing -- the final header line contains the credentials. |
| 2047 | MockWrite("GET / HTTP/1.1\r\n" |
| 2048 | "Host: www.google.com\r\n" |
| 2049 | "Connection: keep-alive\r\n" |
| 2050 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2051 | }; |
| 2052 | |
| 2053 | MockRead data_reads1[] = { |
| 2054 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2055 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2056 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2057 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2058 | MockRead("Unauthorized\r\n"), |
| 2059 | |
| 2060 | // Lastly, the server responds with the actual content. |
| 2061 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2062 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2063 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2064 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2065 | }; |
| 2066 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2067 | // If there is a regression where we disconnect a Keep-Alive |
| 2068 | // connection during an auth roundtrip, we'll end up reading this. |
| 2069 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2070 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2071 | }; |
| 2072 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2073 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2074 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2075 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2076 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2077 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2078 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2080 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2081 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2082 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2084 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2085 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2086 | |
| 2087 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2088 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2089 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2090 | LoadTimingInfo load_timing_info1; |
| 2091 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2092 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2093 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2094 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2095 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2096 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2098 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2100 | rv = trans->RestartWithAuth( |
| 2101 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2103 | |
| 2104 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2105 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2106 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2107 | LoadTimingInfo load_timing_info2; |
| 2108 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2109 | TestLoadTimingReused(load_timing_info2); |
| 2110 | // The load timing after restart should have the same socket ID, and times |
| 2111 | // those of the first load timing. |
| 2112 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2113 | load_timing_info2.send_start); |
| 2114 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2115 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2116 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2117 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2118 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2119 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2120 | |
| 2121 | std::string response_data; |
| 2122 | rv = ReadTransaction(trans.get(), &response_data); |
| 2123 | EXPECT_EQ(OK, rv); |
| 2124 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2125 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2129 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2130 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2131 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2132 | request.method = "GET"; |
| 2133 | request.url = GURL("http://www.google.com/"); |
| 2134 | request.load_flags = 0; |
| 2135 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2136 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2137 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2138 | MockWrite data_writes1[] = { |
| 2139 | MockWrite("GET / HTTP/1.1\r\n" |
| 2140 | "Host: www.google.com\r\n" |
| 2141 | "Connection: keep-alive\r\n\r\n"), |
| 2142 | |
| 2143 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2144 | // be issuing -- the final header line contains the credentials. |
| 2145 | MockWrite("GET / HTTP/1.1\r\n" |
| 2146 | "Host: www.google.com\r\n" |
| 2147 | "Connection: keep-alive\r\n" |
| 2148 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2149 | }; |
| 2150 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2151 | MockRead data_reads1[] = { |
| 2152 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2153 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2154 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2155 | |
| 2156 | // Lastly, the server responds with the actual content. |
| 2157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2158 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2159 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2160 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2161 | }; |
| 2162 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2163 | // An incorrect reconnect would cause this to be read. |
| 2164 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2165 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2166 | }; |
| 2167 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2168 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2169 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2170 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2171 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2172 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2173 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2175 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2176 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2177 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2178 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2179 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[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 = callback1.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 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2185 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2186 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2187 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2189 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2191 | rv = trans->RestartWithAuth( |
| 2192 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2193 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2194 | |
| 2195 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2196 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2197 | |
| 2198 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2199 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2200 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2201 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2205 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2206 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2207 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2208 | request.method = "GET"; |
| 2209 | request.url = GURL("http://www.google.com/"); |
| 2210 | request.load_flags = 0; |
| 2211 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2212 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2213 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2214 | MockWrite data_writes1[] = { |
| 2215 | MockWrite("GET / HTTP/1.1\r\n" |
| 2216 | "Host: www.google.com\r\n" |
| 2217 | "Connection: keep-alive\r\n\r\n"), |
| 2218 | |
| 2219 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2220 | // be issuing -- the final header line contains the credentials. |
| 2221 | MockWrite("GET / HTTP/1.1\r\n" |
| 2222 | "Host: www.google.com\r\n" |
| 2223 | "Connection: keep-alive\r\n" |
| 2224 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2225 | }; |
| 2226 | |
| 2227 | // Respond with 5 kb of response body. |
| 2228 | std::string large_body_string("Unauthorized"); |
| 2229 | large_body_string.append(5 * 1024, ' '); |
| 2230 | large_body_string.append("\r\n"); |
| 2231 | |
| 2232 | MockRead data_reads1[] = { |
| 2233 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2234 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2235 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2236 | // 5134 = 12 + 5 * 1024 + 2 |
| 2237 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2238 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2239 | |
| 2240 | // Lastly, the server responds with the actual content. |
| 2241 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2242 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2243 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2244 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2245 | }; |
| 2246 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2247 | // An incorrect reconnect would cause this to be read. |
| 2248 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2249 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2250 | }; |
| 2251 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2252 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2253 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2254 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2255 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2256 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2257 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2259 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2260 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2261 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2262 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2263 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[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 = callback1.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 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2269 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2270 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2271 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2273 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2275 | rv = trans->RestartWithAuth( |
| 2276 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2278 | |
| 2279 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2280 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2281 | |
| 2282 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2283 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2284 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2285 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2289 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2290 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2291 | HttpRequestInfo request; |
| 2292 | request.method = "GET"; |
| 2293 | request.url = GURL("http://www.google.com/"); |
| 2294 | request.load_flags = 0; |
| 2295 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2296 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2297 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2298 | MockWrite data_writes1[] = { |
| 2299 | MockWrite("GET / HTTP/1.1\r\n" |
| 2300 | "Host: www.google.com\r\n" |
| 2301 | "Connection: keep-alive\r\n\r\n"), |
| 2302 | // This simulates the seemingly successful write to a closed connection |
| 2303 | // if the bug is not fixed. |
| 2304 | MockWrite("GET / HTTP/1.1\r\n" |
| 2305 | "Host: www.google.com\r\n" |
| 2306 | "Connection: keep-alive\r\n" |
| 2307 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2308 | }; |
| 2309 | |
| 2310 | MockRead data_reads1[] = { |
| 2311 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2312 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2313 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2314 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2315 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2316 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2317 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2318 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2319 | }; |
| 2320 | |
| 2321 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2322 | // be issuing -- the final header line contains the credentials. |
| 2323 | MockWrite data_writes2[] = { |
| 2324 | MockWrite("GET / HTTP/1.1\r\n" |
| 2325 | "Host: www.google.com\r\n" |
| 2326 | "Connection: keep-alive\r\n" |
| 2327 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2328 | }; |
| 2329 | |
| 2330 | // Lastly, the server responds with the actual content. |
| 2331 | MockRead data_reads2[] = { |
| 2332 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2333 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2334 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2335 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2336 | }; |
| 2337 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2338 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2339 | data_writes1, arraysize(data_writes1)); |
| 2340 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2341 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2342 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2343 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2345 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2346 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2347 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2348 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2349 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2351 | |
| 2352 | rv = callback1.WaitForResult(); |
| 2353 | EXPECT_EQ(OK, rv); |
| 2354 | |
| 2355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2356 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2357 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2358 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2359 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2361 | rv = trans->RestartWithAuth( |
| 2362 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2363 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2364 | |
| 2365 | rv = callback2.WaitForResult(); |
| 2366 | EXPECT_EQ(OK, rv); |
| 2367 | |
| 2368 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2369 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2370 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2371 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2372 | } |
| 2373 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2374 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2375 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2376 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2377 | HttpRequestInfo request; |
| 2378 | request.method = "GET"; |
| 2379 | request.url = GURL("https://www.google.com/"); |
| 2380 | // when the no authentication data flag is set. |
| 2381 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2382 | |
| 2383 | // Configure against proxy server "myproxy:70". |
| 2384 | session_deps_.proxy_service.reset( |
| 2385 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2386 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2387 | session_deps_.net_log = log.bound().net_log(); |
| 2388 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2389 | |
| 2390 | // Since we have proxy, should try to establish tunnel. |
| 2391 | MockWrite data_writes1[] = { |
| 2392 | MockWrite( |
| 2393 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2394 | "Host: www.google.com\r\n" |
| 2395 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2396 | |
| 2397 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2398 | // be issuing -- the final header line contains the credentials. |
| 2399 | MockWrite( |
| 2400 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2401 | "Host: www.google.com\r\n" |
| 2402 | "Proxy-Connection: keep-alive\r\n" |
| 2403 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2404 | |
| 2405 | MockWrite( |
| 2406 | "GET / HTTP/1.1\r\n" |
| 2407 | "Host: www.google.com\r\n" |
| 2408 | "Connection: keep-alive\r\n\r\n"), |
| 2409 | }; |
| 2410 | |
| 2411 | // The proxy responds to the connect with a 407, using a persistent |
| 2412 | // connection. |
| 2413 | MockRead data_reads1[] = { |
| 2414 | // No credentials. |
| 2415 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2416 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 2417 | |
| 2418 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2419 | |
| 2420 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2421 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2422 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2423 | MockRead(SYNCHRONOUS, "hello"), |
| 2424 | }; |
| 2425 | |
| 2426 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2427 | data_writes1, arraysize(data_writes1)); |
| 2428 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2429 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2430 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2431 | |
| 2432 | TestCompletionCallback callback1; |
| 2433 | |
| 2434 | scoped_ptr<HttpTransaction> trans( |
| 2435 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2436 | |
| 2437 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2438 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2439 | |
| 2440 | rv = callback1.WaitForResult(); |
| 2441 | EXPECT_EQ(OK, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2442 | net::TestNetLog::CapturedEntryList entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2443 | log.GetEntries(&entries); |
| 2444 | size_t pos = ExpectLogContainsSomewhere( |
| 2445 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2446 | NetLog::PHASE_NONE); |
| 2447 | ExpectLogContainsSomewhere( |
| 2448 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2449 | NetLog::PHASE_NONE); |
| 2450 | |
| 2451 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2452 | ASSERT_TRUE(response != NULL); |
| 2453 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2454 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2455 | EXPECT_EQ(407, response->headers->response_code()); |
| 2456 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2457 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2458 | |
| 2459 | LoadTimingInfo load_timing_info; |
| 2460 | // CONNECT requests and responses are handled at the connect job level, so |
| 2461 | // the transaction does not yet have a connection. |
| 2462 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2463 | |
| 2464 | TestCompletionCallback callback2; |
| 2465 | |
| 2466 | rv = |
| 2467 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2468 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2469 | |
| 2470 | rv = callback2.WaitForResult(); |
| 2471 | EXPECT_EQ(OK, rv); |
| 2472 | |
| 2473 | response = trans->GetResponseInfo(); |
| 2474 | ASSERT_TRUE(response != NULL); |
| 2475 | |
| 2476 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2477 | EXPECT_EQ(200, response->headers->response_code()); |
| 2478 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2479 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2480 | |
| 2481 | // The password prompt info should not be set. |
| 2482 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2483 | |
| 2484 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2485 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2486 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2487 | |
| 2488 | trans.reset(); |
| 2489 | session->CloseAllConnections(); |
| 2490 | } |
| 2491 | |
| 2492 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2493 | // that requires a restart when setting up an SSL tunnel. |
| 2494 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2495 | HttpRequestInfo request; |
| 2496 | request.method = "GET"; |
| 2497 | request.url = GURL("https://www.google.com/"); |
| 2498 | // when the no authentication data flag is set. |
| 2499 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2500 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2501 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2502 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2503 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2504 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2505 | session_deps_.net_log = log.bound().net_log(); |
| 2506 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2507 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2508 | // Since we have proxy, should try to establish tunnel. |
| 2509 | MockWrite data_writes1[] = { |
| 2510 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2511 | "Host: www.google.com\r\n" |
| 2512 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2513 | |
| 2514 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2515 | // be issuing -- the final header line contains the credentials. |
| 2516 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2517 | "Host: www.google.com\r\n" |
| 2518 | "Proxy-Connection: keep-alive\r\n" |
| 2519 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2520 | |
| 2521 | MockWrite("GET / HTTP/1.1\r\n" |
| 2522 | "Host: www.google.com\r\n" |
| 2523 | "Connection: keep-alive\r\n\r\n"), |
| 2524 | }; |
| 2525 | |
| 2526 | // The proxy responds to the connect with a 407, using a persistent |
| 2527 | // connection. |
| 2528 | MockRead data_reads1[] = { |
| 2529 | // No credentials. |
| 2530 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2531 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2532 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2533 | |
| 2534 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2535 | |
| 2536 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2537 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2538 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2539 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2540 | }; |
| 2541 | |
| 2542 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2543 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2544 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2545 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2546 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2547 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2548 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2549 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2550 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2551 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2552 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2553 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2554 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2555 | |
| 2556 | rv = callback1.WaitForResult(); |
| 2557 | EXPECT_EQ(OK, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2558 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2559 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2560 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2561 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2562 | NetLog::PHASE_NONE); |
| 2563 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2564 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2565 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2566 | NetLog::PHASE_NONE); |
| 2567 | |
| 2568 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2569 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2570 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2571 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2572 | EXPECT_EQ(407, response->headers->response_code()); |
| 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] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2575 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2576 | LoadTimingInfo load_timing_info; |
| 2577 | // CONNECT requests and responses are handled at the connect job level, so |
| 2578 | // the transaction does not yet have a connection. |
| 2579 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2581 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2582 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2583 | rv = trans->RestartWithAuth( |
| 2584 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2586 | |
| 2587 | rv = callback2.WaitForResult(); |
| 2588 | EXPECT_EQ(OK, rv); |
| 2589 | |
| 2590 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2591 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2592 | |
| 2593 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2594 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2595 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2596 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2597 | |
| 2598 | // The password prompt info should not be set. |
| 2599 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2600 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2601 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2602 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2603 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2604 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2605 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2606 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2607 | } |
| 2608 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2609 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2610 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2611 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2612 | HttpRequestInfo request; |
| 2613 | request.method = "GET"; |
| 2614 | request.url = GURL("https://www.google.com/"); |
| 2615 | // Ensure that proxy authentication is attempted even |
| 2616 | // when the no authentication data flag is set. |
| 2617 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2618 | |
| 2619 | // Configure against proxy server "myproxy:70". |
| 2620 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2621 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2622 | session_deps_.net_log = log.bound().net_log(); |
| 2623 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2624 | |
| 2625 | scoped_ptr<HttpTransaction> trans( |
| 2626 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2627 | |
| 2628 | // Since we have proxy, should try to establish tunnel. |
| 2629 | MockWrite data_writes1[] = { |
| 2630 | MockWrite( |
| 2631 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2632 | "Host: www.google.com\r\n" |
| 2633 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2634 | |
| 2635 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2636 | // be issuing -- the final header line contains the credentials. |
| 2637 | MockWrite( |
| 2638 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2639 | "Host: www.google.com\r\n" |
| 2640 | "Proxy-Connection: keep-alive\r\n" |
| 2641 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2642 | }; |
| 2643 | |
| 2644 | // The proxy responds to the connect with a 407, using a persistent |
| 2645 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2646 | MockRead data_reads1[] = { |
| 2647 | // No credentials. |
| 2648 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2649 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2650 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2651 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2652 | MockRead("0123456789"), |
| 2653 | |
| 2654 | // Wrong credentials (wrong password). |
| 2655 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2656 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2657 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2658 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2659 | // No response body because the test stops reading here. |
| 2660 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2661 | }; |
| 2662 | |
| 2663 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2664 | data_writes1, arraysize(data_writes1)); |
| 2665 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2666 | |
| 2667 | TestCompletionCallback callback1; |
| 2668 | |
| 2669 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2671 | |
| 2672 | rv = callback1.WaitForResult(); |
| 2673 | EXPECT_EQ(OK, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2674 | net::TestNetLog::CapturedEntryList entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2675 | log.GetEntries(&entries); |
| 2676 | size_t pos = ExpectLogContainsSomewhere( |
| 2677 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2678 | NetLog::PHASE_NONE); |
| 2679 | ExpectLogContainsSomewhere( |
| 2680 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2681 | NetLog::PHASE_NONE); |
| 2682 | |
| 2683 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2684 | ASSERT_TRUE(response); |
| 2685 | ASSERT_TRUE(response->headers); |
| 2686 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2687 | EXPECT_EQ(407, response->headers->response_code()); |
| 2688 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2689 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2690 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2691 | |
| 2692 | TestCompletionCallback callback2; |
| 2693 | |
| 2694 | // Wrong password (should be "bar"). |
| 2695 | rv = |
| 2696 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2697 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2698 | |
| 2699 | rv = callback2.WaitForResult(); |
| 2700 | EXPECT_EQ(OK, rv); |
| 2701 | |
| 2702 | response = trans->GetResponseInfo(); |
| 2703 | ASSERT_TRUE(response); |
| 2704 | ASSERT_TRUE(response->headers); |
| 2705 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2706 | EXPECT_EQ(407, response->headers->response_code()); |
| 2707 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2708 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2709 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2710 | |
| 2711 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2712 | // out of scope. |
| 2713 | session->CloseAllConnections(); |
| 2714 | } |
| 2715 | |
| 2716 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2717 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2718 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2719 | HttpRequestInfo request; |
| 2720 | request.method = "GET"; |
| 2721 | request.url = GURL("https://www.google.com/"); |
| 2722 | // Ensure that proxy authentication is attempted even |
| 2723 | // when the no authentication data flag is set. |
| 2724 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2725 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2726 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2727 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2728 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2729 | session_deps_.net_log = log.bound().net_log(); |
| 2730 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2731 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2732 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2733 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2735 | // Since we have proxy, should try to establish tunnel. |
| 2736 | MockWrite data_writes1[] = { |
| 2737 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2738 | "Host: www.google.com\r\n" |
| 2739 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2740 | |
| 2741 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2742 | // be issuing -- the final header line contains the credentials. |
| 2743 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2744 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2745 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2746 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2747 | }; |
| 2748 | |
| 2749 | // The proxy responds to the connect with a 407, using a persistent |
| 2750 | // connection. |
| 2751 | MockRead data_reads1[] = { |
| 2752 | // No credentials. |
| 2753 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2754 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2755 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2756 | MockRead("0123456789"), |
| 2757 | |
| 2758 | // Wrong credentials (wrong password). |
| 2759 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2760 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2761 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2762 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2763 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2764 | }; |
| 2765 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2766 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2767 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2768 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2769 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2770 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2772 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2774 | |
| 2775 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2776 | EXPECT_EQ(OK, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2777 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2778 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2779 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2780 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2781 | NetLog::PHASE_NONE); |
| 2782 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2783 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2784 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2785 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2787 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2788 | ASSERT_TRUE(response); |
| 2789 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2790 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2791 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2792 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2793 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2794 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2796 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | |
| 2798 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2799 | rv = trans->RestartWithAuth( |
| 2800 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2801 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2802 | |
| 2803 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2804 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | |
| 2806 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2807 | ASSERT_TRUE(response); |
| 2808 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2809 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2810 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2811 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2812 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2813 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2814 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2815 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2816 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2817 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2818 | } |
| 2819 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2820 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2821 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2822 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2823 | HttpRequestInfo request; |
| 2824 | request.method = "GET"; |
| 2825 | request.url = GURL("https://www.google.com/"); |
| 2826 | request.load_flags = 0; |
| 2827 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2828 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2829 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2830 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2831 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2832 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2833 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2834 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2835 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2836 | // Since we have proxy, should try to establish tunnel. |
| 2837 | MockWrite data_writes[] = { |
| 2838 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2839 | "Host: www.google.com\r\n" |
| 2840 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2841 | }; |
| 2842 | |
| 2843 | // The proxy responds to the connect with a 407. |
| 2844 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2845 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2846 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2847 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2848 | MockRead("0123456789"), // Should not be reached. |
| 2849 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2850 | }; |
| 2851 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2852 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2853 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2855 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2856 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2858 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2859 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2860 | |
| 2861 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2862 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2863 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2864 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2865 | ASSERT_TRUE(response); |
| 2866 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2867 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2868 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2869 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2870 | |
| 2871 | std::string response_data; |
| 2872 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2873 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2874 | |
| 2875 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2876 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2877 | } |
| 2878 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2879 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 2880 | // caller when the proxy responds to CONNECT with 407. |
| 2881 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 2882 | HttpRequestInfo request; |
| 2883 | request.method = "GET"; |
| 2884 | request.url = GURL("https://www.google.com/"); |
| 2885 | request.load_flags = 0; |
| 2886 | |
| 2887 | // Configure against proxy server "myproxy:70". |
| 2888 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2889 | |
| 2890 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2891 | |
| 2892 | scoped_ptr<HttpTransaction> trans( |
| 2893 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2894 | |
| 2895 | // Since we have proxy, should try to establish tunnel. |
| 2896 | MockWrite data_writes[] = { |
| 2897 | MockWrite( |
| 2898 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2899 | "Host: www.google.com\r\n" |
| 2900 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2901 | }; |
| 2902 | |
| 2903 | // The proxy responds to the connect with a 407. |
| 2904 | MockRead data_reads[] = { |
| 2905 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2906 | MockRead("X-Foo: bar\r\n"), |
| 2907 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 2908 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2909 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2910 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2911 | }; |
| 2912 | |
| 2913 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2914 | arraysize(data_writes)); |
| 2915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2916 | |
| 2917 | TestCompletionCallback callback; |
| 2918 | |
| 2919 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2921 | |
| 2922 | rv = callback.WaitForResult(); |
| 2923 | EXPECT_EQ(OK, rv); |
| 2924 | |
| 2925 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2926 | ASSERT_TRUE(response); |
| 2927 | ASSERT_TRUE(response->headers); |
| 2928 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2929 | EXPECT_EQ(407, response->headers->response_code()); |
| 2930 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2931 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 2932 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 2933 | |
| 2934 | std::string response_data; |
| 2935 | rv = ReadTransaction(trans.get(), &response_data); |
| 2936 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 2937 | |
| 2938 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 2939 | session->CloseAllConnections(); |
| 2940 | } |
| 2941 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2942 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2943 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2944 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2945 | HttpRequestInfo request; |
| 2946 | request.method = "GET"; |
| 2947 | request.url = GURL("http://www.google.com/"); |
| 2948 | request.load_flags = 0; |
| 2949 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2950 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2951 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2952 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2953 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2954 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2955 | MockWrite data_writes1[] = { |
| 2956 | MockWrite("GET / HTTP/1.1\r\n" |
| 2957 | "Host: www.google.com\r\n" |
| 2958 | "Connection: keep-alive\r\n\r\n"), |
| 2959 | }; |
| 2960 | |
| 2961 | MockRead data_reads1[] = { |
| 2962 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2963 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2964 | // Large content-length -- won't matter, as connection will be reset. |
| 2965 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2966 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [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] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2973 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2974 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2975 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2976 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2977 | |
| 2978 | rv = callback.WaitForResult(); |
| 2979 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2980 | } |
| 2981 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2982 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2983 | // through a non-authenticating proxy. The request should fail with |
| 2984 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2985 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2986 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2987 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2988 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2989 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2990 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2991 | HttpRequestInfo request; |
| 2992 | request.method = "GET"; |
| 2993 | request.url = GURL("https://www.google.com/"); |
| 2994 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2995 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 2996 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2997 | session_deps_.net_log = log.bound().net_log(); |
| 2998 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2999 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3000 | // Since we have proxy, should try to establish tunnel. |
| 3001 | MockWrite data_writes1[] = { |
| 3002 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 3003 | "Host: www.google.com\r\n" |
| 3004 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3005 | |
| 3006 | MockWrite("GET / HTTP/1.1\r\n" |
| 3007 | "Host: www.google.com\r\n" |
| 3008 | "Connection: keep-alive\r\n\r\n"), |
| 3009 | }; |
| 3010 | |
| 3011 | MockRead data_reads1[] = { |
| 3012 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3013 | |
| 3014 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3015 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3016 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3017 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3018 | }; |
| 3019 | |
| 3020 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3021 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3022 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3023 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3026 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3027 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3028 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3031 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3033 | |
| 3034 | rv = callback1.WaitForResult(); |
| 3035 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3036 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3037 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3038 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3039 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3040 | NetLog::PHASE_NONE); |
| 3041 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3042 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3043 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3044 | NetLog::PHASE_NONE); |
| 3045 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3046 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3047 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3048 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3049 | HttpRequestInfo request1; |
| 3050 | request1.method = "GET"; |
| 3051 | request1.url = GURL("https://www.google.com/1"); |
| 3052 | |
| 3053 | HttpRequestInfo request2; |
| 3054 | request2.method = "GET"; |
| 3055 | request2.url = GURL("https://www.google.com/2"); |
| 3056 | |
| 3057 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3058 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3059 | ProxyService::CreateFixed("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3060 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3061 | session_deps_.net_log = log.bound().net_log(); |
| 3062 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3063 | |
| 3064 | // Since we have proxy, should try to establish tunnel. |
| 3065 | MockWrite data_writes1[] = { |
| 3066 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 3067 | "Host: www.google.com\r\n" |
| 3068 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3069 | |
| 3070 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3071 | "Host: www.google.com\r\n" |
| 3072 | "Connection: keep-alive\r\n\r\n"), |
| 3073 | |
| 3074 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3075 | "Host: www.google.com\r\n" |
| 3076 | "Connection: keep-alive\r\n\r\n"), |
| 3077 | }; |
| 3078 | |
| 3079 | // The proxy responds to the connect with a 407, using a persistent |
| 3080 | // connection. |
| 3081 | MockRead data_reads1[] = { |
| 3082 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3083 | |
| 3084 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3085 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3086 | MockRead(SYNCHRONOUS, "1"), |
| 3087 | |
| 3088 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3089 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3090 | MockRead(SYNCHRONOUS, "22"), |
| 3091 | }; |
| 3092 | |
| 3093 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3094 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3095 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3096 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3098 | |
| 3099 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3100 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3101 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3102 | |
| 3103 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3104 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3105 | |
| 3106 | rv = callback1.WaitForResult(); |
| 3107 | EXPECT_EQ(OK, rv); |
| 3108 | |
| 3109 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3110 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3111 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3112 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3113 | |
| 3114 | LoadTimingInfo load_timing_info1; |
| 3115 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3116 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3117 | |
| 3118 | trans1.reset(); |
| 3119 | |
| 3120 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3121 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3122 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3123 | |
| 3124 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3125 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3126 | |
| 3127 | rv = callback2.WaitForResult(); |
| 3128 | EXPECT_EQ(OK, rv); |
| 3129 | |
| 3130 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3131 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3132 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3133 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3134 | |
| 3135 | LoadTimingInfo load_timing_info2; |
| 3136 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3137 | TestLoadTimingReused(load_timing_info2); |
| 3138 | |
| 3139 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3140 | |
| 3141 | trans2.reset(); |
| 3142 | session->CloseAllConnections(); |
| 3143 | } |
| 3144 | |
| 3145 | // 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] | 3146 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3147 | HttpRequestInfo request1; |
| 3148 | request1.method = "GET"; |
| 3149 | request1.url = GURL("https://www.google.com/1"); |
| 3150 | |
| 3151 | HttpRequestInfo request2; |
| 3152 | request2.method = "GET"; |
| 3153 | request2.url = GURL("https://www.google.com/2"); |
| 3154 | |
| 3155 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3156 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3157 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3158 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3159 | session_deps_.net_log = log.bound().net_log(); |
| 3160 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3161 | |
| 3162 | // Since we have proxy, should try to establish tunnel. |
| 3163 | MockWrite data_writes1[] = { |
| 3164 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 3165 | "Host: www.google.com\r\n" |
| 3166 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3167 | |
| 3168 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3169 | "Host: www.google.com\r\n" |
| 3170 | "Connection: keep-alive\r\n\r\n"), |
| 3171 | |
| 3172 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3173 | "Host: www.google.com\r\n" |
| 3174 | "Connection: keep-alive\r\n\r\n"), |
| 3175 | }; |
| 3176 | |
| 3177 | // The proxy responds to the connect with a 407, using a persistent |
| 3178 | // connection. |
| 3179 | MockRead data_reads1[] = { |
| 3180 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3181 | |
| 3182 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3183 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3184 | MockRead(SYNCHRONOUS, "1"), |
| 3185 | |
| 3186 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3187 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3188 | MockRead(SYNCHRONOUS, "22"), |
| 3189 | }; |
| 3190 | |
| 3191 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3192 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3193 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3194 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3196 | |
| 3197 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3198 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3200 | |
| 3201 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3203 | |
| 3204 | rv = callback1.WaitForResult(); |
| 3205 | EXPECT_EQ(OK, rv); |
| 3206 | |
| 3207 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3208 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3209 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3210 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3211 | |
| 3212 | LoadTimingInfo load_timing_info1; |
| 3213 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3214 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3215 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3216 | |
| 3217 | trans1.reset(); |
| 3218 | |
| 3219 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3220 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3221 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3222 | |
| 3223 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3224 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3225 | |
| 3226 | rv = callback2.WaitForResult(); |
| 3227 | EXPECT_EQ(OK, rv); |
| 3228 | |
| 3229 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3230 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3231 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3232 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3233 | |
| 3234 | LoadTimingInfo load_timing_info2; |
| 3235 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3236 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3237 | |
| 3238 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3239 | |
| 3240 | trans2.reset(); |
| 3241 | session->CloseAllConnections(); |
| 3242 | } |
| 3243 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3244 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3245 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3246 | HttpRequestInfo request; |
| 3247 | request.method = "GET"; |
| 3248 | request.url = GURL("http://www.google.com/"); |
| 3249 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3250 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3251 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3252 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3253 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3254 | session_deps_.net_log = log.bound().net_log(); |
| 3255 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3256 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3257 | // Since we have proxy, should use full url |
| 3258 | MockWrite data_writes1[] = { |
| 3259 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3260 | "Host: www.google.com\r\n" |
| 3261 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3262 | }; |
| 3263 | |
| 3264 | MockRead data_reads1[] = { |
| 3265 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3266 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3267 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3268 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3269 | }; |
| 3270 | |
| 3271 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3272 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3273 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3274 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3277 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3278 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3279 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3282 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3283 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3284 | |
| 3285 | rv = callback1.WaitForResult(); |
| 3286 | EXPECT_EQ(OK, rv); |
| 3287 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3288 | LoadTimingInfo load_timing_info; |
| 3289 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3290 | TestLoadTimingNotReused(load_timing_info, |
| 3291 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3292 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3293 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3294 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3295 | |
| 3296 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3297 | EXPECT_EQ(200, response->headers->response_code()); |
| 3298 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3299 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3300 | |
| 3301 | // The password prompt info should not be set. |
| 3302 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3303 | } |
| 3304 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3305 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3306 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3307 | HttpRequestInfo request; |
| 3308 | request.method = "GET"; |
| 3309 | request.url = GURL("http://www.google.com/"); |
| 3310 | request.load_flags = 0; |
| 3311 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3312 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3313 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3314 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3315 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3316 | session_deps_.net_log = log.bound().net_log(); |
| 3317 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3318 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3319 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3320 | scoped_ptr<SpdyFrame> req( |
| 3321 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3322 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 3323 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3324 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3325 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3326 | MockRead spdy_reads[] = { |
| 3327 | CreateMockRead(*resp), |
| 3328 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3329 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3330 | }; |
| 3331 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3332 | DelayedSocketData spdy_data( |
| 3333 | 1, // wait for one write to finish before reading. |
| 3334 | spdy_reads, arraysize(spdy_reads), |
| 3335 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3336 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3337 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3338 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3339 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3341 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3342 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3343 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3344 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3347 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3348 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3349 | |
| 3350 | rv = callback1.WaitForResult(); |
| 3351 | EXPECT_EQ(OK, rv); |
| 3352 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3353 | LoadTimingInfo load_timing_info; |
| 3354 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3355 | TestLoadTimingNotReused(load_timing_info, |
| 3356 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3357 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3358 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3359 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3360 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3361 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3362 | |
| 3363 | std::string response_data; |
| 3364 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3365 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3366 | } |
| 3367 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3368 | // Verifies that a session which races and wins against the owning transaction |
| 3369 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3370 | // Regression test for crbug.com/334413. |
| 3371 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3372 | HttpRequestInfo request; |
| 3373 | request.method = "GET"; |
| 3374 | request.url = GURL("http://www.google.com/"); |
| 3375 | request.load_flags = 0; |
| 3376 | |
| 3377 | // Configure SPDY proxy server "proxy:70". |
| 3378 | session_deps_.proxy_service.reset( |
| 3379 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3380 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3381 | session_deps_.net_log = log.bound().net_log(); |
| 3382 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3383 | |
| 3384 | // Fetch http://www.google.com/ through the SPDY proxy. |
| 3385 | scoped_ptr<SpdyFrame> req( |
| 3386 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
| 3387 | MockWrite spdy_writes[] = {CreateMockWrite(*req)}; |
| 3388 | |
| 3389 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3390 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3391 | MockRead spdy_reads[] = { |
| 3392 | CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0), |
| 3393 | }; |
| 3394 | |
| 3395 | DelayedSocketData spdy_data( |
| 3396 | 1, // wait for one write to finish before reading. |
| 3397 | spdy_reads, |
| 3398 | arraysize(spdy_reads), |
| 3399 | spdy_writes, |
| 3400 | arraysize(spdy_writes)); |
| 3401 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3402 | |
| 3403 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3404 | ssl.SetNextProto(GetParam()); |
| 3405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3406 | |
| 3407 | TestCompletionCallback callback1; |
| 3408 | |
| 3409 | scoped_ptr<HttpTransaction> trans( |
| 3410 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3411 | |
| 3412 | // Stall the hostname resolution begun by the transaction. |
| 3413 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3414 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3415 | |
| 3416 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3417 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3418 | |
| 3419 | // Race a session to the proxy, which completes first. |
| 3420 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3421 | SpdySessionKey key( |
| 3422 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3423 | base::WeakPtr<SpdySession> spdy_session = |
| 3424 | CreateSecureSpdySession(session, key, log.bound()); |
| 3425 | |
| 3426 | // Unstall the resolution begun by the transaction. |
| 3427 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3428 | session_deps_.host_resolver->ResolveAllPending(); |
| 3429 | |
| 3430 | EXPECT_FALSE(callback1.have_result()); |
| 3431 | rv = callback1.WaitForResult(); |
| 3432 | EXPECT_EQ(OK, rv); |
| 3433 | |
| 3434 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3435 | ASSERT_TRUE(response != NULL); |
| 3436 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3437 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3438 | |
| 3439 | std::string response_data; |
| 3440 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3441 | EXPECT_EQ(kUploadData, response_data); |
| 3442 | } |
| 3443 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3444 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3445 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3446 | HttpRequestInfo request; |
| 3447 | request.method = "GET"; |
| 3448 | request.url = GURL("http://www.google.com/"); |
| 3449 | request.load_flags = 0; |
| 3450 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3451 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3452 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3453 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3454 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3455 | session_deps_.net_log = log.bound().net_log(); |
| 3456 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3457 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3458 | // The first request will be a bare GET, the second request will be a |
| 3459 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3460 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3461 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3462 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3463 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3464 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3465 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3466 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3467 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3468 | false, |
| 3469 | 3, |
| 3470 | LOWEST, |
| 3471 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3472 | MockWrite spdy_writes[] = { |
| 3473 | CreateMockWrite(*req_get, 1), |
| 3474 | CreateMockWrite(*req_get_authorization, 4), |
| 3475 | }; |
| 3476 | |
| 3477 | // The first response is a 407 proxy authentication challenge, and the second |
| 3478 | // response will be a 200 response since the second request includes a valid |
| 3479 | // Authorization header. |
| 3480 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3481 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3482 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3483 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3484 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3485 | "407 Proxy Authentication Required", |
| 3486 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3487 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3488 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3489 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3490 | scoped_ptr<SpdyFrame> resp_data( |
| 3491 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3492 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3493 | MockRead spdy_reads[] = { |
| 3494 | CreateMockRead(*resp_authentication, 2), |
| 3495 | CreateMockRead(*body_authentication, 3), |
| 3496 | CreateMockRead(*resp_data, 5), |
| 3497 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3498 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3499 | }; |
| 3500 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3501 | OrderedSocketData data( |
| 3502 | spdy_reads, arraysize(spdy_reads), |
| 3503 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3504 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3505 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3506 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3507 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3508 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3510 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3511 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3512 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3515 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3517 | |
| 3518 | rv = callback1.WaitForResult(); |
| 3519 | EXPECT_EQ(OK, rv); |
| 3520 | |
| 3521 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3522 | |
| 3523 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3524 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3525 | EXPECT_EQ(407, response->headers->response_code()); |
| 3526 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3527 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3528 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3529 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3531 | rv = trans->RestartWithAuth( |
| 3532 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3533 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3534 | |
| 3535 | rv = callback2.WaitForResult(); |
| 3536 | EXPECT_EQ(OK, rv); |
| 3537 | |
| 3538 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3539 | |
| 3540 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3541 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3542 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3543 | // The password prompt info should not be set. |
| 3544 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3545 | } |
| 3546 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3547 | // 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] | 3548 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3549 | HttpRequestInfo request; |
| 3550 | request.method = "GET"; |
| 3551 | request.url = GURL("https://www.google.com/"); |
| 3552 | request.load_flags = 0; |
| 3553 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3554 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3555 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3556 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3557 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3558 | session_deps_.net_log = log.bound().net_log(); |
| 3559 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3560 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3561 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3562 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3563 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3564 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3565 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3566 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3567 | // fetch https://www.google.com/ via HTTP |
| 3568 | |
| 3569 | const char get[] = "GET / HTTP/1.1\r\n" |
| 3570 | "Host: www.google.com\r\n" |
| 3571 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3572 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3573 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3574 | scoped_ptr<SpdyFrame> conn_resp( |
| 3575 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3576 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3577 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3578 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3579 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3580 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3581 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3582 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3583 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3584 | |
| 3585 | MockWrite spdy_writes[] = { |
| 3586 | CreateMockWrite(*connect, 1), |
| 3587 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3588 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3589 | }; |
| 3590 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3591 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3592 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3593 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3594 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3595 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 3596 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3597 | }; |
| 3598 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3599 | OrderedSocketData spdy_data( |
| 3600 | spdy_reads, arraysize(spdy_reads), |
| 3601 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3602 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3603 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3604 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3605 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3607 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3608 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 3609 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3612 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3614 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3615 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3616 | |
| 3617 | rv = callback1.WaitForResult(); |
| 3618 | EXPECT_EQ(OK, rv); |
| 3619 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3620 | LoadTimingInfo load_timing_info; |
| 3621 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3622 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3623 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3624 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3625 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3626 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3627 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3628 | |
| 3629 | std::string response_data; |
| 3630 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3631 | EXPECT_EQ("1234567890", response_data); |
| 3632 | } |
| 3633 | |
| 3634 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3635 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3636 | HttpRequestInfo request; |
| 3637 | request.method = "GET"; |
| 3638 | request.url = GURL("https://www.google.com/"); |
| 3639 | request.load_flags = 0; |
| 3640 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3641 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3642 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3643 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3644 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3645 | session_deps_.net_log = log.bound().net_log(); |
| 3646 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3647 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3648 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3649 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3650 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3651 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3652 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3653 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3654 | // fetch https://www.google.com/ via SPDY |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 3655 | const char kMyUrl[] = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3656 | scoped_ptr<SpdyFrame> get( |
| 3657 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3658 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3659 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3660 | scoped_ptr<SpdyFrame> conn_resp( |
| 3661 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3662 | scoped_ptr<SpdyFrame> get_resp( |
| 3663 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3664 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3665 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3666 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3667 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3668 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3669 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3670 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3671 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3672 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3673 | |
| 3674 | MockWrite spdy_writes[] = { |
| 3675 | CreateMockWrite(*connect, 1), |
| 3676 | CreateMockWrite(*wrapped_get, 3), |
| 3677 | CreateMockWrite(*window_update_get_resp, 5), |
| 3678 | CreateMockWrite(*window_update_body, 7), |
| 3679 | }; |
| 3680 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3681 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3682 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3683 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3684 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3685 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3686 | }; |
| 3687 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3688 | OrderedSocketData spdy_data( |
| 3689 | spdy_reads, arraysize(spdy_reads), |
| 3690 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3691 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3692 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3693 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3694 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3696 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3697 | ssl2.SetNextProto(GetParam()); |
| 3698 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3701 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3702 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3703 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3704 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3705 | |
| 3706 | rv = callback1.WaitForResult(); |
| 3707 | EXPECT_EQ(OK, rv); |
| 3708 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3709 | LoadTimingInfo load_timing_info; |
| 3710 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3711 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3712 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3713 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3714 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3715 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3716 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3717 | |
| 3718 | std::string response_data; |
| 3719 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3720 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3724 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3725 | HttpRequestInfo request; |
| 3726 | request.method = "GET"; |
| 3727 | request.url = GURL("https://www.google.com/"); |
| 3728 | request.load_flags = 0; |
| 3729 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3730 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3731 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3732 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3733 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3734 | session_deps_.net_log = log.bound().net_log(); |
| 3735 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3736 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3737 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3738 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3739 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3740 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3741 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3742 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3743 | scoped_ptr<SpdyFrame> get( |
| 3744 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3745 | |
| 3746 | MockWrite spdy_writes[] = { |
| 3747 | CreateMockWrite(*connect, 1), |
| 3748 | CreateMockWrite(*get, 3), |
| 3749 | }; |
| 3750 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3751 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3752 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3753 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3754 | CreateMockRead(*resp, 2, ASYNC), |
| 3755 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3756 | }; |
| 3757 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3758 | OrderedSocketData spdy_data( |
| 3759 | spdy_reads, arraysize(spdy_reads), |
| 3760 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3761 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3762 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3763 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3764 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3766 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3767 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3768 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3769 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3770 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3772 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3774 | |
| 3775 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3776 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3777 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3778 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3779 | } |
| 3780 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3781 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3782 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3783 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3784 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3785 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3786 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3787 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3788 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3789 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3790 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3791 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3792 | |
| 3793 | HttpRequestInfo request1; |
| 3794 | request1.method = "GET"; |
| 3795 | request1.url = GURL("https://www.google.com/"); |
| 3796 | request1.load_flags = 0; |
| 3797 | |
| 3798 | HttpRequestInfo request2; |
| 3799 | request2.method = "GET"; |
| 3800 | request2.url = GURL("https://news.google.com/"); |
| 3801 | request2.load_flags = 0; |
| 3802 | |
| 3803 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3804 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3805 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3806 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3807 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3808 | |
| 3809 | // Fetch https://www.google.com/ via HTTP. |
| 3810 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3811 | "Host: www.google.com\r\n" |
| 3812 | "Connection: keep-alive\r\n\r\n"; |
| 3813 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3814 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3815 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3816 | "Content-Length: 1\r\n\r\n"; |
| 3817 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3818 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3819 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3820 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3821 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3822 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3823 | |
| 3824 | // CONNECT to news.google.com:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3825 | SpdyHeaderBlock connect2_block; |
| 3826 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 3827 | connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443"; |
| 3828 | connect2_block[spdy_util_.GetHostKey()] = "news.google.com"; |
| 3829 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3830 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3831 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3832 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3833 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3834 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3835 | |
| 3836 | // Fetch https://news.google.com/ via HTTP. |
| 3837 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3838 | "Host: news.google.com\r\n" |
| 3839 | "Connection: keep-alive\r\n\r\n"; |
| 3840 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3841 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3842 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3843 | "Content-Length: 2\r\n\r\n"; |
| 3844 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3845 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3846 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3847 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3848 | |
| 3849 | MockWrite spdy_writes[] = { |
| 3850 | CreateMockWrite(*connect1, 0), |
| 3851 | CreateMockWrite(*wrapped_get1, 2), |
| 3852 | CreateMockWrite(*connect2, 5), |
| 3853 | CreateMockWrite(*wrapped_get2, 7), |
| 3854 | }; |
| 3855 | |
| 3856 | MockRead spdy_reads[] = { |
| 3857 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3858 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3859 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3860 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3861 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3862 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3863 | MockRead(ASYNC, 0, 10), |
| 3864 | }; |
| 3865 | |
| 3866 | DeterministicSocketData spdy_data( |
| 3867 | spdy_reads, arraysize(spdy_reads), |
| 3868 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3869 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3870 | |
| 3871 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3872 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3873 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3874 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3875 | ssl2.was_npn_negotiated = false; |
| 3876 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3877 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3878 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3879 | ssl3.was_npn_negotiated = false; |
| 3880 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3881 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3882 | |
| 3883 | TestCompletionCallback callback; |
| 3884 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3885 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3886 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3887 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3889 | // The first connect and request, each of their responses, and the body. |
| 3890 | spdy_data.RunFor(5); |
| 3891 | |
| 3892 | rv = callback.WaitForResult(); |
| 3893 | EXPECT_EQ(OK, rv); |
| 3894 | |
| 3895 | LoadTimingInfo load_timing_info; |
| 3896 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3897 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3898 | |
| 3899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3900 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3901 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3902 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3903 | |
| 3904 | std::string response_data; |
| 3905 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3906 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3907 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3908 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3909 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3910 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3911 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3912 | |
| 3913 | // The second connect and request, each of their responses, and the body. |
| 3914 | spdy_data.RunFor(5); |
| 3915 | rv = callback.WaitForResult(); |
| 3916 | EXPECT_EQ(OK, rv); |
| 3917 | |
| 3918 | LoadTimingInfo load_timing_info2; |
| 3919 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3920 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3921 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3922 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3923 | |
| 3924 | // The requests should have different IDs, since they each are using their own |
| 3925 | // separate stream. |
| 3926 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3927 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3928 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3932 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3933 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3934 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3935 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3936 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3937 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 3938 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3939 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3940 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3941 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3942 | |
| 3943 | HttpRequestInfo request1; |
| 3944 | request1.method = "GET"; |
| 3945 | request1.url = GURL("https://www.google.com/"); |
| 3946 | request1.load_flags = 0; |
| 3947 | |
| 3948 | HttpRequestInfo request2; |
| 3949 | request2.method = "GET"; |
| 3950 | request2.url = GURL("https://www.google.com/2"); |
| 3951 | request2.load_flags = 0; |
| 3952 | |
| 3953 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3954 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3955 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3956 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3957 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3958 | |
| 3959 | // Fetch https://www.google.com/ via HTTP. |
| 3960 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3961 | "Host: www.google.com\r\n" |
| 3962 | "Connection: keep-alive\r\n\r\n"; |
| 3963 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3964 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3965 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3966 | "Content-Length: 1\r\n\r\n"; |
| 3967 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3968 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3969 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3970 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3971 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3972 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3973 | |
| 3974 | // Fetch https://www.google.com/2 via HTTP. |
| 3975 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3976 | "Host: www.google.com\r\n" |
| 3977 | "Connection: keep-alive\r\n\r\n"; |
| 3978 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3979 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3980 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3981 | "Content-Length: 2\r\n\r\n"; |
| 3982 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3983 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3984 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3985 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3986 | |
| 3987 | MockWrite spdy_writes[] = { |
| 3988 | CreateMockWrite(*connect1, 0), |
| 3989 | CreateMockWrite(*wrapped_get1, 2), |
| 3990 | CreateMockWrite(*wrapped_get2, 5), |
| 3991 | }; |
| 3992 | |
| 3993 | MockRead spdy_reads[] = { |
| 3994 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3995 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3996 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3997 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3998 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3999 | MockRead(ASYNC, 0, 8), |
| 4000 | }; |
| 4001 | |
| 4002 | DeterministicSocketData spdy_data( |
| 4003 | spdy_reads, arraysize(spdy_reads), |
| 4004 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4005 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4006 | |
| 4007 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4008 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4009 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4010 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 4011 | ssl2.was_npn_negotiated = false; |
| 4012 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4013 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4014 | |
| 4015 | TestCompletionCallback callback; |
| 4016 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4017 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4018 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4019 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4020 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4021 | // The first connect and request, each of their responses, and the body. |
| 4022 | spdy_data.RunFor(5); |
| 4023 | |
| 4024 | rv = callback.WaitForResult(); |
| 4025 | EXPECT_EQ(OK, rv); |
| 4026 | |
| 4027 | LoadTimingInfo load_timing_info; |
| 4028 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4029 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4030 | |
| 4031 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4032 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4033 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4034 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4035 | |
| 4036 | std::string response_data; |
| 4037 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4038 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4039 | trans.reset(); |
| 4040 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4041 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4043 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4044 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4045 | |
| 4046 | // The second request, response, and body. There should not be a second |
| 4047 | // connect. |
| 4048 | spdy_data.RunFor(3); |
| 4049 | rv = callback.WaitForResult(); |
| 4050 | EXPECT_EQ(OK, rv); |
| 4051 | |
| 4052 | LoadTimingInfo load_timing_info2; |
| 4053 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4054 | TestLoadTimingReused(load_timing_info2); |
| 4055 | |
| 4056 | // The requests should have the same ID. |
| 4057 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4058 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4059 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4063 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4064 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4065 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 4066 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4067 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4068 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 4069 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4070 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4071 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4072 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4073 | |
| 4074 | HttpRequestInfo request1; |
| 4075 | request1.method = "GET"; |
| 4076 | request1.url = GURL("http://www.google.com/"); |
| 4077 | request1.load_flags = 0; |
| 4078 | |
| 4079 | HttpRequestInfo request2; |
| 4080 | request2.method = "GET"; |
| 4081 | request2.url = GURL("http://news.google.com/"); |
| 4082 | request2.load_flags = 0; |
| 4083 | |
| 4084 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4085 | scoped_ptr<SpdyHeaderBlock> headers( |
| 4086 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4087 | scoped_ptr<SpdyFrame> get1( |
| 4088 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4089 | scoped_ptr<SpdyFrame> get_resp1( |
| 4090 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4091 | scoped_ptr<SpdyFrame> body1( |
| 4092 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4093 | |
| 4094 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4095 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 4096 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4097 | scoped_ptr<SpdyFrame> get2( |
| 4098 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4099 | scoped_ptr<SpdyFrame> get_resp2( |
| 4100 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4101 | scoped_ptr<SpdyFrame> body2( |
| 4102 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4103 | |
| 4104 | MockWrite spdy_writes[] = { |
| 4105 | CreateMockWrite(*get1, 0), |
| 4106 | CreateMockWrite(*get2, 3), |
| 4107 | }; |
| 4108 | |
| 4109 | MockRead spdy_reads[] = { |
| 4110 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4111 | CreateMockRead(*body1, 2, ASYNC), |
| 4112 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4113 | CreateMockRead(*body2, 5, ASYNC), |
| 4114 | MockRead(ASYNC, 0, 6), |
| 4115 | }; |
| 4116 | |
| 4117 | DeterministicSocketData spdy_data( |
| 4118 | spdy_reads, arraysize(spdy_reads), |
| 4119 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4120 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4121 | |
| 4122 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4123 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4124 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4125 | |
| 4126 | TestCompletionCallback callback; |
| 4127 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4128 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4129 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4130 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4131 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4132 | spdy_data.RunFor(2); |
| 4133 | |
| 4134 | rv = callback.WaitForResult(); |
| 4135 | EXPECT_EQ(OK, rv); |
| 4136 | |
| 4137 | LoadTimingInfo load_timing_info; |
| 4138 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4139 | TestLoadTimingNotReused(load_timing_info, |
| 4140 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4141 | |
| 4142 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4143 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4144 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4146 | |
| 4147 | std::string response_data; |
| 4148 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4149 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4150 | spdy_data.RunFor(1); |
| 4151 | EXPECT_EQ(1, callback.WaitForResult()); |
| 4152 | // Delete the first request, so the second one can reuse the socket. |
| 4153 | trans.reset(); |
| 4154 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4155 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4156 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4157 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4158 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4159 | |
| 4160 | spdy_data.RunFor(2); |
| 4161 | rv = callback.WaitForResult(); |
| 4162 | EXPECT_EQ(OK, rv); |
| 4163 | |
| 4164 | LoadTimingInfo load_timing_info2; |
| 4165 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4166 | TestLoadTimingReused(load_timing_info2); |
| 4167 | |
| 4168 | // The requests should have the same ID. |
| 4169 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4170 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4171 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4172 | spdy_data.RunFor(1); |
| 4173 | EXPECT_EQ(2, callback.WaitForResult()); |
| 4174 | } |
| 4175 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4176 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4177 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4178 | HttpRequestInfo request; |
| 4179 | request.method = "GET"; |
| 4180 | request.url = GURL("http://www.google.com/"); |
| 4181 | // when the no authentication data flag is set. |
| 4182 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 4183 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4184 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4185 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4186 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 4187 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4188 | session_deps_.net_log = log.bound().net_log(); |
| 4189 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4190 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4191 | // Since we have proxy, should use full url |
| 4192 | MockWrite data_writes1[] = { |
| 4193 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4194 | "Host: www.google.com\r\n" |
| 4195 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4196 | |
| 4197 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4198 | // be issuing -- the final header line contains the credentials. |
| 4199 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4200 | "Host: www.google.com\r\n" |
| 4201 | "Proxy-Connection: keep-alive\r\n" |
| 4202 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4203 | }; |
| 4204 | |
| 4205 | // The proxy responds to the GET with a 407, using a persistent |
| 4206 | // connection. |
| 4207 | MockRead data_reads1[] = { |
| 4208 | // No credentials. |
| 4209 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4210 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4211 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4212 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4213 | |
| 4214 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4215 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4216 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4217 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4218 | }; |
| 4219 | |
| 4220 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4221 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4222 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4223 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4226 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4227 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4228 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4229 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4231 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4232 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4233 | |
| 4234 | rv = callback1.WaitForResult(); |
| 4235 | EXPECT_EQ(OK, rv); |
| 4236 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4237 | LoadTimingInfo load_timing_info; |
| 4238 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4239 | TestLoadTimingNotReused(load_timing_info, |
| 4240 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4241 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4242 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4243 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4244 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4245 | EXPECT_EQ(407, response->headers->response_code()); |
| 4246 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4247 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4249 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4251 | rv = trans->RestartWithAuth( |
| 4252 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4254 | |
| 4255 | rv = callback2.WaitForResult(); |
| 4256 | EXPECT_EQ(OK, rv); |
| 4257 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4258 | load_timing_info = LoadTimingInfo(); |
| 4259 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4260 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4261 | TestLoadTimingReused(load_timing_info); |
| 4262 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4263 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4264 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4265 | |
| 4266 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4267 | EXPECT_EQ(200, response->headers->response_code()); |
| 4268 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4269 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4270 | |
| 4271 | // The password prompt info should not be set. |
| 4272 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4273 | } |
| 4274 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4275 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4276 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4277 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4278 | request.method = "GET"; |
| 4279 | request.url = GURL("https://www.google.com/"); |
| 4280 | request.load_flags = 0; |
| 4281 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4282 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4283 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4284 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4285 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4286 | // Since we have proxy, should try to establish tunnel. |
| 4287 | MockWrite data_writes[] = { |
| 4288 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4289 | "Host: www.google.com\r\n" |
| 4290 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4291 | }; |
| 4292 | |
| 4293 | MockRead data_reads[] = { |
| 4294 | status, |
| 4295 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4296 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4297 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4298 | }; |
| 4299 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4300 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4301 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4302 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4304 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4305 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4306 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4309 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4311 | |
| 4312 | rv = callback.WaitForResult(); |
| 4313 | EXPECT_EQ(expected_status, rv); |
| 4314 | } |
| 4315 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4316 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4317 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4318 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4319 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4320 | } |
| 4321 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4322 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4323 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4324 | } |
| 4325 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4326 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4327 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4328 | } |
| 4329 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4330 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4331 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4332 | } |
| 4333 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4334 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4335 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4336 | } |
| 4337 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4338 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4339 | ConnectStatusHelper( |
| 4340 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4341 | } |
| 4342 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4343 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4344 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4345 | } |
| 4346 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4347 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4348 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4349 | } |
| 4350 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4351 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4352 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4353 | } |
| 4354 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4355 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4356 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4357 | } |
| 4358 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4359 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4360 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4361 | } |
| 4362 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4363 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4364 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4365 | } |
| 4366 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4367 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4368 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4369 | } |
| 4370 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4371 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4372 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4373 | } |
| 4374 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4375 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4376 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4377 | } |
| 4378 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4379 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4380 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4381 | } |
| 4382 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4383 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4384 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4385 | } |
| 4386 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4387 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4388 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4389 | } |
| 4390 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4391 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4392 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4393 | } |
| 4394 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4395 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4396 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4397 | } |
| 4398 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4399 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4400 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4401 | } |
| 4402 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4403 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4404 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4405 | } |
| 4406 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4407 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4408 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4409 | } |
| 4410 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4411 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4412 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4413 | } |
| 4414 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4415 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4416 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4417 | } |
| 4418 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4419 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4420 | ConnectStatusHelperWithExpectedStatus( |
| 4421 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4422 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4423 | } |
| 4424 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4425 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4426 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4427 | } |
| 4428 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4429 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4430 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4431 | } |
| 4432 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4433 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4434 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4435 | } |
| 4436 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4437 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4438 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4439 | } |
| 4440 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4441 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4442 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4443 | } |
| 4444 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4445 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4446 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4447 | } |
| 4448 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4449 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4450 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4451 | } |
| 4452 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4453 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4454 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4455 | } |
| 4456 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4457 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4458 | ConnectStatusHelper( |
| 4459 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4460 | } |
| 4461 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4462 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4463 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4464 | } |
| 4465 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4466 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4467 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4468 | } |
| 4469 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4470 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4471 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4472 | } |
| 4473 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4474 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4475 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4476 | } |
| 4477 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4478 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4479 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4480 | } |
| 4481 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4482 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4483 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4484 | } |
| 4485 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4486 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4487 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4488 | } |
| 4489 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4490 | // Test the flow when both the proxy server AND origin server require |
| 4491 | // authentication. Again, this uses basic auth for both since that is |
| 4492 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4493 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4494 | HttpRequestInfo request; |
| 4495 | request.method = "GET"; |
| 4496 | request.url = GURL("http://www.google.com/"); |
| 4497 | request.load_flags = 0; |
| 4498 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4499 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4500 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4501 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4502 | |
| 4503 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4504 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4505 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4506 | MockWrite data_writes1[] = { |
| 4507 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4508 | "Host: www.google.com\r\n" |
| 4509 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4510 | }; |
| 4511 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4512 | MockRead data_reads1[] = { |
| 4513 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4514 | // Give a couple authenticate options (only the middle one is actually |
| 4515 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4516 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4517 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4518 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4519 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4520 | // Large content-length -- won't matter, as connection will be reset. |
| 4521 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4522 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4523 | }; |
| 4524 | |
| 4525 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4526 | // request we should be issuing -- the final header line contains the |
| 4527 | // proxy's credentials. |
| 4528 | MockWrite data_writes2[] = { |
| 4529 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4530 | "Host: www.google.com\r\n" |
| 4531 | "Proxy-Connection: keep-alive\r\n" |
| 4532 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4533 | }; |
| 4534 | |
| 4535 | // Now the proxy server lets the request pass through to origin server. |
| 4536 | // The origin server responds with a 401. |
| 4537 | MockRead data_reads2[] = { |
| 4538 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4539 | // Note: We are using the same realm-name as the proxy server. This is |
| 4540 | // completely valid, as realms are unique across hosts. |
| 4541 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4542 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4543 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4544 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4545 | }; |
| 4546 | |
| 4547 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4548 | // the credentials for both the proxy and origin server. |
| 4549 | MockWrite data_writes3[] = { |
| 4550 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4551 | "Host: www.google.com\r\n" |
| 4552 | "Proxy-Connection: keep-alive\r\n" |
| 4553 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4554 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4555 | }; |
| 4556 | |
| 4557 | // Lastly we get the desired content. |
| 4558 | MockRead data_reads3[] = { |
| 4559 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4560 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4561 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4562 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4563 | }; |
| 4564 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4565 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4566 | data_writes1, arraysize(data_writes1)); |
| 4567 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4568 | data_writes2, arraysize(data_writes2)); |
| 4569 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4570 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4571 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4572 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4573 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4574 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4575 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4577 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4578 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4579 | |
| 4580 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4581 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4582 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4583 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4584 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4585 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4587 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4589 | rv = trans->RestartWithAuth( |
| 4590 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4591 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4592 | |
| 4593 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4594 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4595 | |
| 4596 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4597 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4598 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4600 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4601 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4602 | rv = trans->RestartWithAuth( |
| 4603 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4605 | |
| 4606 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4607 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4608 | |
| 4609 | response = trans->GetResponseInfo(); |
| 4610 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4611 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4612 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4613 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4614 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4615 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4616 | // authorization headers. |
| 4617 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4618 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4619 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4620 | // bytes in the debugger. |
| 4621 | |
| 4622 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4623 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4624 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4625 | request.method = "GET"; |
| 4626 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4627 | |
| 4628 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4629 | // to other auth schemes. |
| 4630 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4631 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4632 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4633 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4634 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4635 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4636 | MockWrite data_writes1[] = { |
| 4637 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4638 | "Host: 172.22.68.17\r\n" |
| 4639 | "Connection: keep-alive\r\n\r\n"), |
| 4640 | }; |
| 4641 | |
| 4642 | MockRead data_reads1[] = { |
| 4643 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4644 | // Negotiate and NTLM are often requested together. However, we only want |
| 4645 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4646 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4647 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4648 | MockRead("Connection: close\r\n"), |
| 4649 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4650 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4651 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4652 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4653 | }; |
| 4654 | |
| 4655 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4656 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4657 | // request we should be issuing -- the final header line contains a Type |
| 4658 | // 1 message. |
| 4659 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4660 | "Host: 172.22.68.17\r\n" |
| 4661 | "Connection: keep-alive\r\n" |
| 4662 | "Authorization: NTLM " |
| 4663 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4664 | |
| 4665 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4666 | // (the credentials for the origin server). The second request continues |
| 4667 | // on the same connection. |
| 4668 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4669 | "Host: 172.22.68.17\r\n" |
| 4670 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4671 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4672 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4673 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4674 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4675 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4676 | }; |
| 4677 | |
| 4678 | MockRead data_reads2[] = { |
| 4679 | // The origin server responds with a Type 2 message. |
| 4680 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4681 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4682 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4683 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4684 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4685 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4686 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4687 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4688 | "BtAAAAAAA=\r\n"), |
| 4689 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4690 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4691 | MockRead("You are not authorized to view this page\r\n"), |
| 4692 | |
| 4693 | // Lastly we get the desired content. |
| 4694 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4695 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4696 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4697 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4698 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4699 | }; |
| 4700 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4701 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4702 | data_writes1, arraysize(data_writes1)); |
| 4703 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4704 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4705 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4706 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4708 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4709 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4710 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4711 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4712 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4713 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4714 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4715 | |
| 4716 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4717 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4718 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4719 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4720 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4721 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4722 | ASSERT_FALSE(response == NULL); |
| 4723 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4725 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4726 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4727 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4728 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4729 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4730 | |
| 4731 | rv = callback2.WaitForResult(); |
| 4732 | EXPECT_EQ(OK, rv); |
| 4733 | |
| 4734 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4735 | |
| 4736 | response = trans->GetResponseInfo(); |
| 4737 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4738 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4740 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4742 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4744 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4745 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4746 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4747 | |
| 4748 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4749 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4750 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4751 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4752 | } |
| 4753 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4754 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4755 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4756 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4757 | request.method = "GET"; |
| 4758 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4759 | request.load_flags = 0; |
| 4760 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4761 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4762 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4763 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4764 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4765 | MockWrite data_writes1[] = { |
| 4766 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4767 | "Host: 172.22.68.17\r\n" |
| 4768 | "Connection: keep-alive\r\n\r\n"), |
| 4769 | }; |
| 4770 | |
| 4771 | MockRead data_reads1[] = { |
| 4772 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4773 | // Negotiate and NTLM are often requested together. However, we only want |
| 4774 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4775 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4776 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4777 | MockRead("Connection: close\r\n"), |
| 4778 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4779 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4780 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4781 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4782 | }; |
| 4783 | |
| 4784 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4785 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4786 | // request we should be issuing -- the final header line contains a Type |
| 4787 | // 1 message. |
| 4788 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4789 | "Host: 172.22.68.17\r\n" |
| 4790 | "Connection: keep-alive\r\n" |
| 4791 | "Authorization: NTLM " |
| 4792 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4793 | |
| 4794 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4795 | // (the credentials for the origin server). The second request continues |
| 4796 | // on the same connection. |
| 4797 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4798 | "Host: 172.22.68.17\r\n" |
| 4799 | "Connection: keep-alive\r\n" |
| 4800 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4801 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4802 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4803 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4804 | "4Ww7b7E=\r\n\r\n"), |
| 4805 | }; |
| 4806 | |
| 4807 | MockRead data_reads2[] = { |
| 4808 | // The origin server responds with a Type 2 message. |
| 4809 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4810 | MockRead("WWW-Authenticate: NTLM " |
| 4811 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4812 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4813 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4814 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4815 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4816 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4817 | "BtAAAAAAA=\r\n"), |
| 4818 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4819 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4820 | MockRead("You are not authorized to view this page\r\n"), |
| 4821 | |
| 4822 | // Wrong password. |
| 4823 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4824 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4825 | MockRead("Connection: close\r\n"), |
| 4826 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4827 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4828 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4829 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4830 | }; |
| 4831 | |
| 4832 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4833 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4834 | // request we should be issuing -- the final header line contains a Type |
| 4835 | // 1 message. |
| 4836 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4837 | "Host: 172.22.68.17\r\n" |
| 4838 | "Connection: keep-alive\r\n" |
| 4839 | "Authorization: NTLM " |
| 4840 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4841 | |
| 4842 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4843 | // (the credentials for the origin server). The second request continues |
| 4844 | // on the same connection. |
| 4845 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4846 | "Host: 172.22.68.17\r\n" |
| 4847 | "Connection: keep-alive\r\n" |
| 4848 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4849 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4850 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4851 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4852 | "+4MUm7c=\r\n\r\n"), |
| 4853 | }; |
| 4854 | |
| 4855 | MockRead data_reads3[] = { |
| 4856 | // The origin server responds with a Type 2 message. |
| 4857 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4858 | MockRead("WWW-Authenticate: NTLM " |
| 4859 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4860 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4861 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4862 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4863 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4864 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4865 | "BtAAAAAAA=\r\n"), |
| 4866 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4867 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4868 | MockRead("You are not authorized to view this page\r\n"), |
| 4869 | |
| 4870 | // Lastly we get the desired content. |
| 4871 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4872 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4873 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4874 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4875 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4876 | }; |
| 4877 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4878 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4879 | data_writes1, arraysize(data_writes1)); |
| 4880 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4881 | data_writes2, arraysize(data_writes2)); |
| 4882 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4883 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4884 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4885 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4886 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4888 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4889 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4890 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4893 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4895 | |
| 4896 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4897 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4898 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4899 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4900 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4901 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4902 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4903 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4905 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4906 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4907 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4908 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4909 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4910 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4911 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4912 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4913 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4914 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4915 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4916 | TestCompletionCallback callback3; |
| 4917 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4919 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4920 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4921 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4922 | |
| 4923 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4924 | ASSERT_FALSE(response == NULL); |
| 4925 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4927 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4928 | |
| 4929 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4930 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4931 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4932 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4933 | |
| 4934 | rv = callback4.WaitForResult(); |
| 4935 | EXPECT_EQ(OK, rv); |
| 4936 | |
| 4937 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4939 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4940 | |
| 4941 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4942 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4943 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4944 | |
| 4945 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4946 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4947 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4948 | response = trans->GetResponseInfo(); |
| 4949 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4950 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4951 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4952 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4953 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4954 | // Test reading a server response which has only headers, and no body. |
| 4955 | // After some maximum number of bytes is consumed, the transaction should |
| 4956 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4957 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4958 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4959 | request.method = "GET"; |
| 4960 | request.url = GURL("http://www.google.com/"); |
| 4961 | request.load_flags = 0; |
| 4962 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4963 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4964 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4965 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4966 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4967 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4968 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4969 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4970 | |
| 4971 | MockRead data_reads[] = { |
| 4972 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4973 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4974 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4975 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4976 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4980 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4982 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4983 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4984 | |
| 4985 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4986 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4987 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4988 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4989 | EXPECT_TRUE(response == NULL); |
| 4990 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4991 | |
| 4992 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4993 | // establish tunnel. |
| 4994 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4995 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4996 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4997 | HttpRequestInfo request; |
| 4998 | request.method = "GET"; |
| 4999 | request.url = GURL("https://www.google.com/"); |
| 5000 | request.load_flags = 0; |
| 5001 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5002 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5003 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5004 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5005 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5006 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5007 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5008 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5009 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5010 | // Since we have proxy, should try to establish tunnel. |
| 5011 | MockWrite data_writes1[] = { |
| 5012 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 5013 | "Host: www.google.com\r\n" |
| 5014 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5015 | }; |
| 5016 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5017 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5018 | // connection. Usually a proxy would return 501 (not implemented), |
| 5019 | // or 200 (tunnel established). |
| 5020 | MockRead data_reads1[] = { |
| 5021 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5022 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5023 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5024 | }; |
| 5025 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5026 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5027 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5028 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5030 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5032 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5034 | |
| 5035 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5036 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5037 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5038 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5039 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5040 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5041 | // Empty the current queue. This is necessary because idle sockets are |
| 5042 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5043 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5044 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5045 | // We now check to make sure the TCPClientSocket was not added back to |
| 5046 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5047 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5048 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5049 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5050 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5051 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5052 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5053 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5054 | // 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] | 5055 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5056 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5057 | request.method = "GET"; |
| 5058 | request.url = GURL("http://www.google.com/"); |
| 5059 | request.load_flags = 0; |
| 5060 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5061 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5062 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5063 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5065 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5066 | MockRead data_reads[] = { |
| 5067 | // A part of the response body is received with the response headers. |
| 5068 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5069 | // The rest of the response body is received in two parts. |
| 5070 | MockRead("lo"), |
| 5071 | MockRead(" world"), |
| 5072 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5073 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5074 | }; |
| 5075 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5076 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5077 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5079 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5081 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5083 | |
| 5084 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5085 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5086 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5088 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5089 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5090 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5091 | std::string status_line = response->headers->GetStatusLine(); |
| 5092 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5093 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5094 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5095 | |
| 5096 | std::string response_data; |
| 5097 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5098 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5099 | EXPECT_EQ("hello world", response_data); |
| 5100 | |
| 5101 | // Empty the current queue. This is necessary because idle sockets are |
| 5102 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5103 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5104 | |
| 5105 | // 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] | 5106 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5107 | } |
| 5108 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5109 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5110 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5111 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5112 | HttpRequestInfo request; |
| 5113 | request.method = "GET"; |
| 5114 | request.url = GURL("https://www.google.com/"); |
| 5115 | request.load_flags = 0; |
| 5116 | |
| 5117 | MockWrite data_writes[] = { |
| 5118 | MockWrite("GET / HTTP/1.1\r\n" |
| 5119 | "Host: www.google.com\r\n" |
| 5120 | "Connection: keep-alive\r\n\r\n"), |
| 5121 | }; |
| 5122 | |
| 5123 | MockRead data_reads[] = { |
| 5124 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5125 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5126 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5127 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5128 | }; |
| 5129 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5130 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5132 | |
| 5133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5134 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5137 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5138 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5139 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5140 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5141 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5143 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5144 | |
| 5145 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5146 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5147 | |
| 5148 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5149 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5150 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5151 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5152 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5153 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5154 | |
| 5155 | std::string response_data; |
| 5156 | rv = ReadTransaction(trans.get(), &response_data); |
| 5157 | EXPECT_EQ(OK, rv); |
| 5158 | EXPECT_EQ("hello world", response_data); |
| 5159 | |
| 5160 | // Empty the current queue. This is necessary because idle sockets are |
| 5161 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5162 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5163 | |
| 5164 | // 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] | 5165 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5169 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5170 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5171 | HttpRequestInfo request; |
| 5172 | request.method = "GET"; |
| 5173 | request.url = GURL("https://www.google.com/"); |
| 5174 | request.load_flags = 0; |
| 5175 | |
| 5176 | MockWrite data_writes[] = { |
| 5177 | MockWrite("GET / HTTP/1.1\r\n" |
| 5178 | "Host: www.google.com\r\n" |
| 5179 | "Connection: keep-alive\r\n\r\n"), |
| 5180 | MockWrite("GET / HTTP/1.1\r\n" |
| 5181 | "Host: www.google.com\r\n" |
| 5182 | "Connection: keep-alive\r\n\r\n"), |
| 5183 | }; |
| 5184 | |
| 5185 | MockRead data_reads[] = { |
| 5186 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5187 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5188 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5189 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5190 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5191 | }; |
| 5192 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5193 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5194 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5197 | |
| 5198 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5199 | data_writes, arraysize(data_writes)); |
| 5200 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5201 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5202 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5203 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5205 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5206 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5207 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5208 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5211 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5212 | |
| 5213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5214 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5215 | |
| 5216 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5217 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5218 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5219 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5220 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5221 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5222 | |
| 5223 | std::string response_data; |
| 5224 | rv = ReadTransaction(trans.get(), &response_data); |
| 5225 | EXPECT_EQ(OK, rv); |
| 5226 | EXPECT_EQ("hello world", response_data); |
| 5227 | |
| 5228 | // Empty the current queue. This is necessary because idle sockets are |
| 5229 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5230 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5231 | |
| 5232 | // 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] | 5233 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5234 | |
| 5235 | // Now start the second transaction, which should reuse the previous socket. |
| 5236 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5237 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5239 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5240 | |
| 5241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5242 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5243 | |
| 5244 | response = trans->GetResponseInfo(); |
| 5245 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5246 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5247 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5248 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5249 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5250 | |
| 5251 | rv = ReadTransaction(trans.get(), &response_data); |
| 5252 | EXPECT_EQ(OK, rv); |
| 5253 | EXPECT_EQ("hello world", response_data); |
| 5254 | |
| 5255 | // Empty the current queue. This is necessary because idle sockets are |
| 5256 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5257 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5258 | |
| 5259 | // 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] | 5260 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5261 | } |
| 5262 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5263 | // Make sure that we recycle a socket after a zero-length response. |
| 5264 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5265 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5266 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5267 | request.method = "GET"; |
| 5268 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 5269 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5270 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5271 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 5272 | request.load_flags = 0; |
| 5273 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5274 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5275 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5276 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5278 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5279 | MockRead data_reads[] = { |
| 5280 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5281 | "Content-Length: 0\r\n" |
| 5282 | "Content-Type: text/html\r\n\r\n"), |
| 5283 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5284 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5285 | }; |
| 5286 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5287 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5288 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5290 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5292 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5294 | |
| 5295 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5296 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5297 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5298 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5299 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5300 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5301 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5302 | std::string status_line = response->headers->GetStatusLine(); |
| 5303 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5304 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5305 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5306 | |
| 5307 | std::string response_data; |
| 5308 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5309 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5310 | EXPECT_EQ("", response_data); |
| 5311 | |
| 5312 | // Empty the current queue. This is necessary because idle sockets are |
| 5313 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5314 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5315 | |
| 5316 | // 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] | 5317 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5318 | } |
| 5319 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5320 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5321 | ScopedVector<UploadElementReader> element_readers; |
| 5322 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5323 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5324 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5325 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5326 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5327 | // after use. |
| 5328 | request[0].method = "GET"; |
| 5329 | request[0].url = GURL("http://www.google.com/"); |
| 5330 | request[0].load_flags = 0; |
| 5331 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5332 | // transaction 1. The first attempts fails when writing the POST data. |
| 5333 | // This causes the transaction to retry with a new socket. The second |
| 5334 | // attempt succeeds. |
| 5335 | request[1].method = "POST"; |
| 5336 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5337 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5338 | request[1].load_flags = 0; |
| 5339 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5340 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5341 | |
| 5342 | // The first socket is used for transaction 1 and the first attempt of |
| 5343 | // transaction 2. |
| 5344 | |
| 5345 | // The response of transaction 1. |
| 5346 | MockRead data_reads1[] = { |
| 5347 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5348 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5349 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5350 | }; |
| 5351 | // The mock write results of transaction 1 and the first attempt of |
| 5352 | // transaction 2. |
| 5353 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5354 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5355 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5356 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5357 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5358 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5359 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5360 | |
| 5361 | // The second socket is used for the second attempt of transaction 2. |
| 5362 | |
| 5363 | // The response of transaction 2. |
| 5364 | MockRead data_reads2[] = { |
| 5365 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5366 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5367 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5368 | }; |
| 5369 | // The mock write results of the second attempt of transaction 2. |
| 5370 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5371 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5372 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5373 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5374 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5375 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5376 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5377 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5378 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5379 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5380 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5381 | "hello world", "welcome" |
| 5382 | }; |
| 5383 | |
| 5384 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5385 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5386 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5387 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5388 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5390 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5391 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5392 | |
| 5393 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5394 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5395 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5396 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5397 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5398 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5399 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5400 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5401 | |
| 5402 | std::string response_data; |
| 5403 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5404 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5405 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5406 | } |
| 5407 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5408 | |
| 5409 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5410 | // 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] | 5411 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5412 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5413 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5414 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5415 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5416 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5417 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5418 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5419 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5421 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5422 | // The password contains an escaped character -- for this test to pass it |
| 5423 | // will need to be unescaped by HttpNetworkTransaction. |
| 5424 | EXPECT_EQ("b%40r", request.url.password()); |
| 5425 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5426 | MockWrite data_writes1[] = { |
| 5427 | MockWrite("GET / HTTP/1.1\r\n" |
| 5428 | "Host: www.google.com\r\n" |
| 5429 | "Connection: keep-alive\r\n\r\n"), |
| 5430 | }; |
| 5431 | |
| 5432 | MockRead data_reads1[] = { |
| 5433 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5434 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5435 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5436 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5437 | }; |
| 5438 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5439 | // After the challenge above, the transaction will be restarted using the |
| 5440 | // identity from the url (foo, b@r) to answer the challenge. |
| 5441 | MockWrite data_writes2[] = { |
| 5442 | MockWrite("GET / HTTP/1.1\r\n" |
| 5443 | "Host: www.google.com\r\n" |
| 5444 | "Connection: keep-alive\r\n" |
| 5445 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 5446 | }; |
| 5447 | |
| 5448 | MockRead data_reads2[] = { |
| 5449 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5450 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5451 | MockRead(SYNCHRONOUS, OK), |
| 5452 | }; |
| 5453 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5454 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5455 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5456 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5457 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5458 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5459 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5461 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5462 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5463 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5464 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5465 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5466 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5467 | |
| 5468 | TestCompletionCallback callback2; |
| 5469 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5470 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5471 | rv = callback2.WaitForResult(); |
| 5472 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5473 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5474 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5475 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5476 | ASSERT_TRUE(response != NULL); |
| 5477 | |
| 5478 | // There is no challenge info, since the identity in URL worked. |
| 5479 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5480 | |
| 5481 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5482 | |
| 5483 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5484 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5488 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5489 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5490 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5491 | HttpRequestInfo request; |
| 5492 | request.method = "GET"; |
| 5493 | // Note: the URL has a username:password in it. The password "baz" is |
| 5494 | // wrong (should be "bar"). |
| 5495 | request.url = GURL("http://foo:[email protected]/"); |
| 5496 | |
| 5497 | request.load_flags = LOAD_NORMAL; |
| 5498 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5499 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5500 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5501 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5502 | |
| 5503 | MockWrite data_writes1[] = { |
| 5504 | MockWrite("GET / HTTP/1.1\r\n" |
| 5505 | "Host: www.google.com\r\n" |
| 5506 | "Connection: keep-alive\r\n\r\n"), |
| 5507 | }; |
| 5508 | |
| 5509 | MockRead data_reads1[] = { |
| 5510 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5511 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5512 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5513 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5514 | }; |
| 5515 | |
| 5516 | // After the challenge above, the transaction will be restarted using the |
| 5517 | // identity from the url (foo, baz) to answer the challenge. |
| 5518 | MockWrite data_writes2[] = { |
| 5519 | MockWrite("GET / HTTP/1.1\r\n" |
| 5520 | "Host: www.google.com\r\n" |
| 5521 | "Connection: keep-alive\r\n" |
| 5522 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 5523 | }; |
| 5524 | |
| 5525 | MockRead data_reads2[] = { |
| 5526 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5527 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5528 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5529 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5530 | }; |
| 5531 | |
| 5532 | // After the challenge above, the transaction will be restarted using the |
| 5533 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5534 | MockWrite data_writes3[] = { |
| 5535 | MockWrite("GET / HTTP/1.1\r\n" |
| 5536 | "Host: www.google.com\r\n" |
| 5537 | "Connection: keep-alive\r\n" |
| 5538 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5539 | }; |
| 5540 | |
| 5541 | MockRead data_reads3[] = { |
| 5542 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5543 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5544 | MockRead(SYNCHRONOUS, OK), |
| 5545 | }; |
| 5546 | |
| 5547 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5548 | data_writes1, arraysize(data_writes1)); |
| 5549 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5550 | data_writes2, arraysize(data_writes2)); |
| 5551 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5552 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5553 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5554 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5555 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5556 | |
| 5557 | TestCompletionCallback callback1; |
| 5558 | |
| 5559 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5560 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5561 | |
| 5562 | rv = callback1.WaitForResult(); |
| 5563 | EXPECT_EQ(OK, rv); |
| 5564 | |
| 5565 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5566 | TestCompletionCallback callback2; |
| 5567 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5568 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5569 | rv = callback2.WaitForResult(); |
| 5570 | EXPECT_EQ(OK, rv); |
| 5571 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5572 | |
| 5573 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5574 | ASSERT_TRUE(response != NULL); |
| 5575 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5576 | |
| 5577 | TestCompletionCallback callback3; |
| 5578 | rv = trans->RestartWithAuth( |
| 5579 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5581 | rv = callback3.WaitForResult(); |
| 5582 | EXPECT_EQ(OK, rv); |
| 5583 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5584 | |
| 5585 | response = trans->GetResponseInfo(); |
| 5586 | ASSERT_TRUE(response != NULL); |
| 5587 | |
| 5588 | // There is no challenge info, since the identity worked. |
| 5589 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5590 | |
| 5591 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5592 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5593 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5594 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5595 | } |
| 5596 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5597 | |
| 5598 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5599 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5600 | // from the URL should never be used. |
| 5601 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5602 | HttpRequestInfo request; |
| 5603 | request.method = "GET"; |
| 5604 | request.url = GURL("http://foo:[email protected]/"); |
| 5605 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5606 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5607 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5608 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5610 | |
| 5611 | MockWrite data_writes1[] = { |
| 5612 | MockWrite("GET / HTTP/1.1\r\n" |
| 5613 | "Host: www.google.com\r\n" |
| 5614 | "Connection: keep-alive\r\n\r\n"), |
| 5615 | }; |
| 5616 | |
| 5617 | MockRead data_reads1[] = { |
| 5618 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5619 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5620 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5621 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5622 | }; |
| 5623 | |
| 5624 | // After the challenge above, the transaction will be restarted using the |
| 5625 | // identity supplied by the user, not the one in the URL, to answer the |
| 5626 | // challenge. |
| 5627 | MockWrite data_writes3[] = { |
| 5628 | MockWrite("GET / HTTP/1.1\r\n" |
| 5629 | "Host: www.google.com\r\n" |
| 5630 | "Connection: keep-alive\r\n" |
| 5631 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5632 | }; |
| 5633 | |
| 5634 | MockRead data_reads3[] = { |
| 5635 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5636 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5637 | MockRead(SYNCHRONOUS, OK), |
| 5638 | }; |
| 5639 | |
| 5640 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5641 | data_writes1, arraysize(data_writes1)); |
| 5642 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5643 | data_writes3, arraysize(data_writes3)); |
| 5644 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5645 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5646 | |
| 5647 | TestCompletionCallback callback1; |
| 5648 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5649 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5650 | rv = callback1.WaitForResult(); |
| 5651 | EXPECT_EQ(OK, rv); |
| 5652 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5653 | |
| 5654 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5655 | ASSERT_TRUE(response != NULL); |
| 5656 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5657 | |
| 5658 | TestCompletionCallback callback3; |
| 5659 | rv = trans->RestartWithAuth( |
| 5660 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5662 | rv = callback3.WaitForResult(); |
| 5663 | EXPECT_EQ(OK, rv); |
| 5664 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5665 | |
| 5666 | response = trans->GetResponseInfo(); |
| 5667 | ASSERT_TRUE(response != NULL); |
| 5668 | |
| 5669 | // There is no challenge info, since the identity worked. |
| 5670 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5671 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5672 | |
| 5673 | // Empty the current queue. |
| 5674 | base::MessageLoop::current()->RunUntilIdle(); |
| 5675 | } |
| 5676 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5677 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5678 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5679 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5680 | |
| 5681 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5682 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5683 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5684 | request.method = "GET"; |
| 5685 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5686 | request.load_flags = 0; |
| 5687 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5688 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5689 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5690 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5691 | MockWrite data_writes1[] = { |
| 5692 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5693 | "Host: www.google.com\r\n" |
| 5694 | "Connection: keep-alive\r\n\r\n"), |
| 5695 | }; |
| 5696 | |
| 5697 | MockRead data_reads1[] = { |
| 5698 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5699 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5700 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5701 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5702 | }; |
| 5703 | |
| 5704 | // Resend with authorization (username=foo, password=bar) |
| 5705 | MockWrite data_writes2[] = { |
| 5706 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5707 | "Host: www.google.com\r\n" |
| 5708 | "Connection: keep-alive\r\n" |
| 5709 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5710 | }; |
| 5711 | |
| 5712 | // Sever accepts the authorization. |
| 5713 | MockRead data_reads2[] = { |
| 5714 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5715 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5716 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5717 | }; |
| 5718 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5719 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5720 | data_writes1, arraysize(data_writes1)); |
| 5721 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5722 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5723 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5724 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5726 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5728 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5729 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5730 | |
| 5731 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5732 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5733 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5734 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5735 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5736 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5738 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5740 | rv = trans->RestartWithAuth( |
| 5741 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5743 | |
| 5744 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5745 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5746 | |
| 5747 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5748 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5749 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5750 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5751 | } |
| 5752 | |
| 5753 | // ------------------------------------------------------------------------ |
| 5754 | |
| 5755 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5756 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5757 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5758 | request.method = "GET"; |
| 5759 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5760 | // protection space as MyRealm1. |
| 5761 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5762 | request.load_flags = 0; |
| 5763 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5764 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5766 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5767 | MockWrite data_writes1[] = { |
| 5768 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5769 | "Host: www.google.com\r\n" |
| 5770 | "Connection: keep-alive\r\n" |
| 5771 | // Send preemptive authorization for MyRealm1 |
| 5772 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5773 | }; |
| 5774 | |
| 5775 | // The server didn't like the preemptive authorization, and |
| 5776 | // challenges us for a different realm (MyRealm2). |
| 5777 | MockRead data_reads1[] = { |
| 5778 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5779 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5780 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5781 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5782 | }; |
| 5783 | |
| 5784 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5785 | MockWrite data_writes2[] = { |
| 5786 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5787 | "Host: www.google.com\r\n" |
| 5788 | "Connection: keep-alive\r\n" |
| 5789 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 5790 | }; |
| 5791 | |
| 5792 | // Sever accepts the authorization. |
| 5793 | MockRead data_reads2[] = { |
| 5794 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5795 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5796 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5797 | }; |
| 5798 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5799 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5800 | data_writes1, arraysize(data_writes1)); |
| 5801 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5802 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5804 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5806 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5808 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5809 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5810 | |
| 5811 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5812 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5813 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5814 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5815 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5816 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5817 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 5818 | EXPECT_EQ("www.google.com:80", |
| 5819 | response->auth_challenge->challenger.ToString()); |
| 5820 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5821 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5823 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5825 | rv = trans->RestartWithAuth( |
| 5826 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5827 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5828 | |
| 5829 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5830 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5831 | |
| 5832 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5833 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5834 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5835 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5836 | } |
| 5837 | |
| 5838 | // ------------------------------------------------------------------------ |
| 5839 | |
| 5840 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5841 | // succeed with preemptive authorization. |
| 5842 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5843 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5844 | request.method = "GET"; |
| 5845 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 5846 | request.load_flags = 0; |
| 5847 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5850 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5851 | MockWrite data_writes1[] = { |
| 5852 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 5853 | "Host: www.google.com\r\n" |
| 5854 | "Connection: keep-alive\r\n" |
| 5855 | // The authorization for MyRealm1 gets sent preemptively |
| 5856 | // (since the url is in the same protection space) |
| 5857 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5858 | }; |
| 5859 | |
| 5860 | // Sever accepts the preemptive authorization |
| 5861 | MockRead data_reads1[] = { |
| 5862 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5863 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5864 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5865 | }; |
| 5866 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5867 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5868 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5871 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5873 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5875 | |
| 5876 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5877 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5878 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5879 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5880 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5881 | |
| 5882 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5883 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5884 | } |
| 5885 | |
| 5886 | // ------------------------------------------------------------------------ |
| 5887 | |
| 5888 | // Transaction 4: request another URL in MyRealm (however the |
| 5889 | // url is not known to belong to the protection space, so no pre-auth). |
| 5890 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5891 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5892 | request.method = "GET"; |
| 5893 | request.url = GURL("http://www.google.com/x/1"); |
| 5894 | request.load_flags = 0; |
| 5895 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5896 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5898 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5899 | MockWrite data_writes1[] = { |
| 5900 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5901 | "Host: www.google.com\r\n" |
| 5902 | "Connection: keep-alive\r\n\r\n"), |
| 5903 | }; |
| 5904 | |
| 5905 | MockRead data_reads1[] = { |
| 5906 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5907 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5908 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5909 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5910 | }; |
| 5911 | |
| 5912 | // Resend with authorization from MyRealm's cache. |
| 5913 | MockWrite data_writes2[] = { |
| 5914 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5915 | "Host: www.google.com\r\n" |
| 5916 | "Connection: keep-alive\r\n" |
| 5917 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5918 | }; |
| 5919 | |
| 5920 | // Sever accepts the authorization. |
| 5921 | MockRead data_reads2[] = { |
| 5922 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5923 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5925 | }; |
| 5926 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5927 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5928 | data_writes1, arraysize(data_writes1)); |
| 5929 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5930 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5932 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5934 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5936 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5937 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5938 | |
| 5939 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5940 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5941 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5942 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5943 | TestCompletionCallback callback2; |
| 5944 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5945 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5946 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5947 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5948 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5949 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5950 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5951 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5952 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5953 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5954 | } |
| 5955 | |
| 5956 | // ------------------------------------------------------------------------ |
| 5957 | |
| 5958 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5959 | // cached identity. Should invalidate and re-prompt. |
| 5960 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5961 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5962 | request.method = "GET"; |
| 5963 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5964 | request.load_flags = 0; |
| 5965 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5966 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5967 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5968 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5969 | MockWrite data_writes1[] = { |
| 5970 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5971 | "Host: www.google.com\r\n" |
| 5972 | "Connection: keep-alive\r\n\r\n"), |
| 5973 | }; |
| 5974 | |
| 5975 | MockRead data_reads1[] = { |
| 5976 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5977 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5978 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5979 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5980 | }; |
| 5981 | |
| 5982 | // Resend with authorization from cache for MyRealm. |
| 5983 | MockWrite data_writes2[] = { |
| 5984 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5985 | "Host: www.google.com\r\n" |
| 5986 | "Connection: keep-alive\r\n" |
| 5987 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5988 | }; |
| 5989 | |
| 5990 | // Sever rejects the authorization. |
| 5991 | MockRead data_reads2[] = { |
| 5992 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5993 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5994 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5995 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5996 | }; |
| 5997 | |
| 5998 | // At this point we should prompt for new credentials for MyRealm. |
| 5999 | // Restart with username=foo3, password=foo4. |
| 6000 | MockWrite data_writes3[] = { |
| 6001 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 6002 | "Host: www.google.com\r\n" |
| 6003 | "Connection: keep-alive\r\n" |
| 6004 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 6005 | }; |
| 6006 | |
| 6007 | // Sever accepts the authorization. |
| 6008 | MockRead data_reads3[] = { |
| 6009 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6010 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6011 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6012 | }; |
| 6013 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6014 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6015 | data_writes1, arraysize(data_writes1)); |
| 6016 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6017 | data_writes2, arraysize(data_writes2)); |
| 6018 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6019 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6020 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6021 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6022 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6024 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6026 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6027 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6028 | |
| 6029 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6030 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6031 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6032 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6033 | TestCompletionCallback callback2; |
| 6034 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6036 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6037 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6038 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6039 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6040 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6041 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6042 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6044 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6046 | rv = trans->RestartWithAuth( |
| 6047 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6048 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6049 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6050 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6051 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6052 | |
| 6053 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6054 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6055 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6056 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6057 | } |
| 6058 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6059 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6060 | // Tests that nonce count increments when multiple auth attempts |
| 6061 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6062 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6063 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6064 | new HttpAuthHandlerDigest::Factory(); |
| 6065 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6066 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6067 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6068 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 6069 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6070 | |
| 6071 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6072 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6073 | HttpRequestInfo request; |
| 6074 | request.method = "GET"; |
| 6075 | request.url = GURL("http://www.google.com/x/y/z"); |
| 6076 | request.load_flags = 0; |
| 6077 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6078 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6080 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6081 | MockWrite data_writes1[] = { |
| 6082 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 6083 | "Host: www.google.com\r\n" |
| 6084 | "Connection: keep-alive\r\n\r\n"), |
| 6085 | }; |
| 6086 | |
| 6087 | MockRead data_reads1[] = { |
| 6088 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6089 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6090 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6091 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6092 | }; |
| 6093 | |
| 6094 | // Resend with authorization (username=foo, password=bar) |
| 6095 | MockWrite data_writes2[] = { |
| 6096 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 6097 | "Host: www.google.com\r\n" |
| 6098 | "Connection: keep-alive\r\n" |
| 6099 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6100 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6101 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6102 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 6103 | }; |
| 6104 | |
| 6105 | // Sever accepts the authorization. |
| 6106 | MockRead data_reads2[] = { |
| 6107 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6108 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6109 | }; |
| 6110 | |
| 6111 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6112 | data_writes1, arraysize(data_writes1)); |
| 6113 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6114 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6115 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6116 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6118 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6120 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6121 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6122 | |
| 6123 | rv = callback1.WaitForResult(); |
| 6124 | EXPECT_EQ(OK, rv); |
| 6125 | |
| 6126 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6127 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6128 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6129 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6130 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6132 | rv = trans->RestartWithAuth( |
| 6133 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6134 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6135 | |
| 6136 | rv = callback2.WaitForResult(); |
| 6137 | EXPECT_EQ(OK, rv); |
| 6138 | |
| 6139 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6140 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6141 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6142 | } |
| 6143 | |
| 6144 | // ------------------------------------------------------------------------ |
| 6145 | |
| 6146 | // Transaction 2: Request another resource in digestive's protection space. |
| 6147 | // This will preemptively add an Authorization header which should have an |
| 6148 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6149 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6150 | HttpRequestInfo request; |
| 6151 | request.method = "GET"; |
| 6152 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6153 | // protection space as digest. |
| 6154 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 6155 | request.load_flags = 0; |
| 6156 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6157 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6158 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6159 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6160 | MockWrite data_writes1[] = { |
| 6161 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 6162 | "Host: www.google.com\r\n" |
| 6163 | "Connection: keep-alive\r\n" |
| 6164 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6165 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6166 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6167 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 6168 | }; |
| 6169 | |
| 6170 | // Sever accepts the authorization. |
| 6171 | MockRead data_reads1[] = { |
| 6172 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6173 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6174 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6175 | }; |
| 6176 | |
| 6177 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6178 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6179 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6181 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6182 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6183 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6184 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6185 | |
| 6186 | rv = callback1.WaitForResult(); |
| 6187 | EXPECT_EQ(OK, rv); |
| 6188 | |
| 6189 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6190 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6191 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6192 | } |
| 6193 | } |
| 6194 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6195 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6196 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6197 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6198 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6199 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6200 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6201 | |
| 6202 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6203 | trans->read_buf_ = new IOBuffer(15); |
| 6204 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6205 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6206 | |
| 6207 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6208 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6209 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6210 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6211 | response->response_time = base::Time::Now(); |
| 6212 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6213 | |
| 6214 | { // Setup state for response_.vary_data |
| 6215 | HttpRequestInfo request; |
| 6216 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6217 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6218 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6219 | request.extra_headers.SetHeader("Foo", "1"); |
| 6220 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6221 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | // Cause the above state to be reset. |
| 6225 | trans->ResetStateForRestart(); |
| 6226 | |
| 6227 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6228 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6229 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6230 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6231 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6232 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6233 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6234 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6235 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6236 | } |
| 6237 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6238 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6239 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6240 | HttpRequestInfo request; |
| 6241 | request.method = "GET"; |
| 6242 | request.url = GURL("https://www.google.com/"); |
| 6243 | request.load_flags = 0; |
| 6244 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6245 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6246 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6247 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6248 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6249 | MockWrite data_writes[] = { |
| 6250 | MockWrite("GET / HTTP/1.1\r\n" |
| 6251 | "Host: www.google.com\r\n" |
| 6252 | "Connection: keep-alive\r\n\r\n"), |
| 6253 | }; |
| 6254 | |
| 6255 | MockRead data_reads[] = { |
| 6256 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6257 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6258 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6259 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6260 | }; |
| 6261 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6262 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6264 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6265 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6266 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6267 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6268 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6273 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6275 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6276 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6277 | |
| 6278 | rv = callback.WaitForResult(); |
| 6279 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6281 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6282 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6283 | |
| 6284 | rv = callback.WaitForResult(); |
| 6285 | EXPECT_EQ(OK, rv); |
| 6286 | |
| 6287 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6288 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6289 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6290 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6291 | } |
| 6292 | |
| 6293 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6294 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6295 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6296 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6297 | |
| 6298 | HttpRequestInfo request; |
| 6299 | request.method = "GET"; |
| 6300 | request.url = GURL("https://www.google.com/"); |
| 6301 | request.load_flags = 0; |
| 6302 | |
| 6303 | MockWrite proxy_writes[] = { |
| 6304 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6305 | "Host: www.google.com\r\n" |
| 6306 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6307 | }; |
| 6308 | |
| 6309 | MockRead proxy_reads[] = { |
| 6310 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6311 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6312 | }; |
| 6313 | |
| 6314 | MockWrite data_writes[] = { |
| 6315 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6316 | "Host: www.google.com\r\n" |
| 6317 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6318 | MockWrite("GET / HTTP/1.1\r\n" |
| 6319 | "Host: www.google.com\r\n" |
| 6320 | "Connection: keep-alive\r\n\r\n"), |
| 6321 | }; |
| 6322 | |
| 6323 | MockRead data_reads[] = { |
| 6324 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6325 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6326 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6327 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6328 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6329 | }; |
| 6330 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6331 | StaticSocketDataProvider ssl_bad_certificate( |
| 6332 | proxy_reads, arraysize(proxy_reads), |
| 6333 | proxy_writes, arraysize(proxy_writes)); |
| 6334 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6335 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6336 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6337 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6338 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6339 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6340 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6342 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6344 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6345 | |
| 6346 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6347 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6348 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6349 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6350 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6351 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6353 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6354 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6355 | |
| 6356 | rv = callback.WaitForResult(); |
| 6357 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6358 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6359 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6360 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6361 | |
| 6362 | rv = callback.WaitForResult(); |
| 6363 | EXPECT_EQ(OK, rv); |
| 6364 | |
| 6365 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6366 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6367 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6368 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6369 | } |
| 6370 | } |
| 6371 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6372 | |
| 6373 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6374 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6375 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6376 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 6377 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6378 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6379 | |
| 6380 | HttpRequestInfo request; |
| 6381 | request.method = "GET"; |
| 6382 | request.url = GURL("https://www.google.com/"); |
| 6383 | request.load_flags = 0; |
| 6384 | |
| 6385 | MockWrite data_writes[] = { |
| 6386 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6387 | "Host: www.google.com\r\n" |
| 6388 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6389 | MockWrite("GET / HTTP/1.1\r\n" |
| 6390 | "Host: www.google.com\r\n" |
| 6391 | "Connection: keep-alive\r\n\r\n"), |
| 6392 | }; |
| 6393 | |
| 6394 | MockRead data_reads[] = { |
| 6395 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6396 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6397 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6398 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6399 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6400 | }; |
| 6401 | |
| 6402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6403 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6404 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6405 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6406 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6407 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6410 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6411 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6412 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6413 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6414 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6415 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6417 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6418 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6419 | |
| 6420 | rv = callback.WaitForResult(); |
| 6421 | EXPECT_EQ(OK, rv); |
| 6422 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6423 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6424 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6425 | |
| 6426 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6427 | EXPECT_EQ(200, response->headers->response_code()); |
| 6428 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6429 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6430 | |
| 6431 | LoadTimingInfo load_timing_info; |
| 6432 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6433 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6434 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6435 | } |
| 6436 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6437 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6438 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6439 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6440 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 6441 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6442 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6443 | |
| 6444 | HttpRequestInfo request; |
| 6445 | request.method = "GET"; |
| 6446 | request.url = GURL("https://www.google.com/"); |
| 6447 | request.load_flags = 0; |
| 6448 | |
| 6449 | MockWrite data_writes[] = { |
| 6450 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6451 | "Host: www.google.com\r\n" |
| 6452 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6453 | }; |
| 6454 | |
| 6455 | MockRead data_reads[] = { |
| 6456 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6457 | MockRead("Location: http://login.example.com/\r\n"), |
| 6458 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6459 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6460 | }; |
| 6461 | |
| 6462 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6463 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6464 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6465 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6469 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6470 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6471 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6472 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6473 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6475 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6476 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6477 | |
| 6478 | rv = callback.WaitForResult(); |
| 6479 | EXPECT_EQ(OK, rv); |
| 6480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6481 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6482 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6483 | |
| 6484 | EXPECT_EQ(302, response->headers->response_code()); |
| 6485 | std::string url; |
| 6486 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6487 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6488 | |
| 6489 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6490 | // timing for the proxy connection instead of the connection to the host, |
| 6491 | // and no send / receive times. |
| 6492 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6493 | LoadTimingInfo load_timing_info; |
| 6494 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6495 | |
| 6496 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 6497 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 6498 | |
| 6499 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6500 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6501 | load_timing_info.proxy_resolve_end); |
| 6502 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6503 | load_timing_info.connect_timing.connect_start); |
| 6504 | ExpectConnectTimingHasTimes( |
| 6505 | load_timing_info.connect_timing, |
| 6506 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6507 | |
| 6508 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6509 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6510 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6511 | } |
| 6512 | |
| 6513 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6514 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6515 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6516 | ProxyService::CreateFixed("https://proxy:70")); |
| 6517 | |
| 6518 | HttpRequestInfo request; |
| 6519 | request.method = "GET"; |
| 6520 | request.url = GURL("https://www.google.com/"); |
| 6521 | request.load_flags = 0; |
| 6522 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6523 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6524 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6525 | scoped_ptr<SpdyFrame> goaway( |
| 6526 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6527 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6528 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 6529 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6530 | }; |
| 6531 | |
| 6532 | static const char* const kExtraHeaders[] = { |
| 6533 | "location", |
| 6534 | "http://login.example.com/", |
| 6535 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6536 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6537 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6538 | arraysize(kExtraHeaders)/2, 1)); |
| 6539 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6540 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6541 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6542 | }; |
| 6543 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6544 | DelayedSocketData data( |
| 6545 | 1, // wait for one write to finish before reading. |
| 6546 | data_reads, arraysize(data_reads), |
| 6547 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6548 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6549 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6550 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6554 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6555 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6556 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6557 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6558 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6560 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6561 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6562 | |
| 6563 | rv = callback.WaitForResult(); |
| 6564 | EXPECT_EQ(OK, rv); |
| 6565 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6566 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6567 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6568 | |
| 6569 | EXPECT_EQ(302, response->headers->response_code()); |
| 6570 | std::string url; |
| 6571 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6572 | EXPECT_EQ("http://login.example.com/", url); |
| 6573 | } |
| 6574 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6575 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6576 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6577 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6578 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6579 | ProxyService::CreateFixed("https://proxy:70")); |
| 6580 | |
| 6581 | HttpRequestInfo request; |
| 6582 | request.method = "GET"; |
| 6583 | request.url = GURL("https://www.google.com/"); |
| 6584 | request.load_flags = 0; |
| 6585 | |
| 6586 | MockWrite data_writes[] = { |
| 6587 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6588 | "Host: www.google.com\r\n" |
| 6589 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6590 | }; |
| 6591 | |
| 6592 | MockRead data_reads[] = { |
| 6593 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6594 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6595 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6596 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6597 | }; |
| 6598 | |
| 6599 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6600 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6601 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6602 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6603 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6606 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6607 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6608 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6609 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6610 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6612 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6613 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6614 | |
| 6615 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6616 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6617 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6618 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6619 | } |
| 6620 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6621 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6622 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6623 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6624 | session_deps_.proxy_service.reset( |
| 6625 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6626 | |
| 6627 | HttpRequestInfo request; |
| 6628 | request.method = "GET"; |
| 6629 | request.url = GURL("https://www.google.com/"); |
| 6630 | request.load_flags = 0; |
| 6631 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6632 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6633 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6634 | scoped_ptr<SpdyFrame> rst( |
| 6635 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6636 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6637 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6638 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6639 | }; |
| 6640 | |
| 6641 | static const char* const kExtraHeaders[] = { |
| 6642 | "location", |
| 6643 | "http://login.example.com/", |
| 6644 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6645 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6646 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6647 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6648 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6649 | spdy_util_.ConstructSpdyBodyFrame( |
| 6650 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6651 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6652 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6653 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6654 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6655 | }; |
| 6656 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6657 | DelayedSocketData data( |
| 6658 | 1, // wait for one write to finish before reading. |
| 6659 | data_reads, arraysize(data_reads), |
| 6660 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6661 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6662 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6663 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6665 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6667 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6668 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6669 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6670 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6671 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6673 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6675 | |
| 6676 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6677 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6678 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6679 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6680 | } |
| 6681 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6682 | // Test the request-challenge-retry sequence for basic auth, through |
| 6683 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6684 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6685 | HttpRequestInfo request; |
| 6686 | request.method = "GET"; |
| 6687 | request.url = GURL("https://www.google.com/"); |
| 6688 | // when the no authentication data flag is set. |
| 6689 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 6690 | |
| 6691 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6692 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6693 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 6694 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6695 | session_deps_.net_log = log.bound().net_log(); |
| 6696 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6697 | |
| 6698 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6699 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
| 6700 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6701 | scoped_ptr<SpdyFrame> rst( |
| 6702 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6703 | |
| 6704 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6705 | // be issuing -- the final header line contains the credentials. |
| 6706 | const char* const kAuthCredentials[] = { |
| 6707 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6708 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6709 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6710 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
| 6711 | HostPortPair("www.google.com", 443))); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6712 | // fetch https://www.google.com/ via HTTP |
| 6713 | const char get[] = "GET / HTTP/1.1\r\n" |
| 6714 | "Host: www.google.com\r\n" |
| 6715 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6716 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6717 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6718 | |
| 6719 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6720 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 6721 | CreateMockWrite(*rst, 4, ASYNC), |
| 6722 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6723 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6724 | }; |
| 6725 | |
| 6726 | // The proxy responds to the connect with a 407, using a persistent |
| 6727 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6728 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6729 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6730 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6731 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6732 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6733 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6734 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6735 | scoped_ptr<SpdyFrame> conn_resp( |
| 6736 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6737 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6738 | "Content-Length: 5\r\n\r\n"; |
| 6739 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6740 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6741 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6742 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6743 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6744 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6745 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 6746 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 6747 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 6748 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 6749 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6750 | }; |
| 6751 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6752 | OrderedSocketData spdy_data( |
| 6753 | spdy_reads, arraysize(spdy_reads), |
| 6754 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6755 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6756 | // Negotiate SPDY to the proxy |
| 6757 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6758 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6760 | // Vanilla SSL to the server |
| 6761 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6763 | |
| 6764 | TestCompletionCallback callback1; |
| 6765 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6766 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6767 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6768 | |
| 6769 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6770 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6771 | |
| 6772 | rv = callback1.WaitForResult(); |
| 6773 | EXPECT_EQ(OK, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 6774 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6775 | log.GetEntries(&entries); |
| 6776 | size_t pos = ExpectLogContainsSomewhere( |
| 6777 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6778 | NetLog::PHASE_NONE); |
| 6779 | ExpectLogContainsSomewhere( |
| 6780 | entries, pos, |
| 6781 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6782 | NetLog::PHASE_NONE); |
| 6783 | |
| 6784 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6785 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6786 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6787 | EXPECT_EQ(407, response->headers->response_code()); |
| 6788 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6789 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6790 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6791 | |
| 6792 | TestCompletionCallback callback2; |
| 6793 | |
| 6794 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6795 | callback2.callback()); |
| 6796 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6797 | |
| 6798 | rv = callback2.WaitForResult(); |
| 6799 | EXPECT_EQ(OK, rv); |
| 6800 | |
| 6801 | response = trans->GetResponseInfo(); |
| 6802 | ASSERT_TRUE(response != NULL); |
| 6803 | |
| 6804 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6805 | EXPECT_EQ(200, response->headers->response_code()); |
| 6806 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6807 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6808 | |
| 6809 | // The password prompt info should not be set. |
| 6810 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6811 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6812 | LoadTimingInfo load_timing_info; |
| 6813 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6814 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6815 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6816 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6817 | trans.reset(); |
| 6818 | session->CloseAllConnections(); |
| 6819 | } |
| 6820 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6821 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6822 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6823 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6824 | HttpRequestInfo request; |
| 6825 | HttpRequestInfo push_request; |
| 6826 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6827 | request.method = "GET"; |
| 6828 | request.url = GURL("http://www.google.com/"); |
| 6829 | push_request.method = "GET"; |
| 6830 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6831 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6832 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6833 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6834 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 6835 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6836 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6837 | |
| 6838 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6839 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6840 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6841 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6842 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6843 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6844 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6845 | |
| 6846 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6847 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6848 | }; |
| 6849 | |
| 6850 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6851 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6852 | |
| 6853 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6854 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6855 | |
| 6856 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6857 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6858 | 0, |
| 6859 | 2, |
| 6860 | 1, |
| 6861 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6862 | const char kPushedData[] = "pushed"; |
| 6863 | scoped_ptr<SpdyFrame> stream2_body( |
| 6864 | spdy_util_.ConstructSpdyBodyFrame( |
| 6865 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6866 | |
| 6867 | MockRead spdy_reads[] = { |
| 6868 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6869 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6870 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6871 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6872 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6873 | }; |
| 6874 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6875 | OrderedSocketData spdy_data( |
| 6876 | spdy_reads, arraysize(spdy_reads), |
| 6877 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6878 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6879 | // Negotiate SPDY to the proxy |
| 6880 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6881 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6883 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6884 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6885 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6886 | TestCompletionCallback callback; |
| 6887 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6889 | |
| 6890 | rv = callback.WaitForResult(); |
| 6891 | EXPECT_EQ(OK, rv); |
| 6892 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6893 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6894 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6896 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6897 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6898 | |
| 6899 | rv = callback.WaitForResult(); |
| 6900 | EXPECT_EQ(OK, rv); |
| 6901 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6902 | |
| 6903 | ASSERT_TRUE(response != NULL); |
| 6904 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6905 | |
| 6906 | EXPECT_EQ(200, response->headers->response_code()); |
| 6907 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6908 | |
| 6909 | std::string response_data; |
| 6910 | rv = ReadTransaction(trans.get(), &response_data); |
| 6911 | EXPECT_EQ(OK, rv); |
| 6912 | EXPECT_EQ("hello!", response_data); |
| 6913 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6914 | LoadTimingInfo load_timing_info; |
| 6915 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6916 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6917 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6918 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6919 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6920 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6921 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6922 | |
| 6923 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6924 | EXPECT_EQ(OK, rv); |
| 6925 | EXPECT_EQ("pushed", response_data); |
| 6926 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6927 | LoadTimingInfo push_load_timing_info; |
| 6928 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6929 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6930 | // The transactions should share a socket ID, despite being for different |
| 6931 | // origins. |
| 6932 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6933 | push_load_timing_info.socket_log_id); |
| 6934 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6935 | trans.reset(); |
| 6936 | push_trans.reset(); |
| 6937 | session->CloseAllConnections(); |
| 6938 | } |
| 6939 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6940 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6941 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6942 | HttpRequestInfo request; |
| 6943 | |
| 6944 | request.method = "GET"; |
| 6945 | request.url = GURL("http://www.google.com/"); |
| 6946 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6947 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6948 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6949 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 6950 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6951 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6952 | |
| 6953 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6954 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6955 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6956 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6957 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6958 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6959 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6960 | |
| 6961 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6962 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6963 | |
| 6964 | MockWrite spdy_writes[] = { |
| 6965 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6966 | CreateMockWrite(*push_rst, 4), |
| 6967 | }; |
| 6968 | |
| 6969 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6970 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6971 | |
| 6972 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6973 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6974 | |
| 6975 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6976 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6977 | 0, |
| 6978 | 2, |
| 6979 | 1, |
| 6980 | "https://www.another-origin.com/foo.dat")); |
| 6981 | |
| 6982 | MockRead spdy_reads[] = { |
| 6983 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6984 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6985 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6986 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6987 | }; |
| 6988 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6989 | OrderedSocketData spdy_data( |
| 6990 | spdy_reads, arraysize(spdy_reads), |
| 6991 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6992 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6993 | // Negotiate SPDY to the proxy |
| 6994 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6995 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6997 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6998 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6999 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7000 | TestCompletionCallback callback; |
| 7001 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7002 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7003 | |
| 7004 | rv = callback.WaitForResult(); |
| 7005 | EXPECT_EQ(OK, rv); |
| 7006 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7007 | |
| 7008 | ASSERT_TRUE(response != NULL); |
| 7009 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7010 | |
| 7011 | EXPECT_EQ(200, response->headers->response_code()); |
| 7012 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7013 | |
| 7014 | std::string response_data; |
| 7015 | rv = ReadTransaction(trans.get(), &response_data); |
| 7016 | EXPECT_EQ(OK, rv); |
| 7017 | EXPECT_EQ("hello!", response_data); |
| 7018 | |
| 7019 | trans.reset(); |
| 7020 | session->CloseAllConnections(); |
| 7021 | } |
| 7022 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7023 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7024 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7025 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7026 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7027 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7028 | |
| 7029 | HttpRequestInfo request; |
| 7030 | request.method = "GET"; |
| 7031 | request.url = GURL("https://www.google.com/"); |
| 7032 | request.load_flags = 0; |
| 7033 | |
| 7034 | // Attempt to fetch the URL from a server with a bad cert |
| 7035 | MockWrite bad_cert_writes[] = { |
| 7036 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 7037 | "Host: www.google.com\r\n" |
| 7038 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7039 | }; |
| 7040 | |
| 7041 | MockRead bad_cert_reads[] = { |
| 7042 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7043 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7044 | }; |
| 7045 | |
| 7046 | // Attempt to fetch the URL with a good cert |
| 7047 | MockWrite good_data_writes[] = { |
| 7048 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 7049 | "Host: www.google.com\r\n" |
| 7050 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7051 | MockWrite("GET / HTTP/1.1\r\n" |
| 7052 | "Host: www.google.com\r\n" |
| 7053 | "Connection: keep-alive\r\n\r\n"), |
| 7054 | }; |
| 7055 | |
| 7056 | MockRead good_cert_reads[] = { |
| 7057 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7058 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7059 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7060 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7062 | }; |
| 7063 | |
| 7064 | StaticSocketDataProvider ssl_bad_certificate( |
| 7065 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7066 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7067 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7068 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7069 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7070 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7071 | |
| 7072 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7073 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7074 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7075 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7076 | |
| 7077 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7079 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7082 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7083 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7084 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7085 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7086 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7088 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7090 | |
| 7091 | rv = callback.WaitForResult(); |
| 7092 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7094 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7096 | |
| 7097 | rv = callback.WaitForResult(); |
| 7098 | EXPECT_EQ(OK, rv); |
| 7099 | |
| 7100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7101 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7102 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7103 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7104 | } |
| 7105 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7106 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7107 | HttpRequestInfo request; |
| 7108 | request.method = "GET"; |
| 7109 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7110 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7111 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7112 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7113 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7114 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7115 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7116 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7117 | MockWrite data_writes[] = { |
| 7118 | MockWrite("GET / HTTP/1.1\r\n" |
| 7119 | "Host: www.google.com\r\n" |
| 7120 | "Connection: keep-alive\r\n" |
| 7121 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 7122 | }; |
| 7123 | |
| 7124 | // Lastly, the server responds with the actual content. |
| 7125 | MockRead data_reads[] = { |
| 7126 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7127 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7128 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7129 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7130 | }; |
| 7131 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7132 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7133 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7136 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7138 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7139 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7140 | |
| 7141 | rv = callback.WaitForResult(); |
| 7142 | EXPECT_EQ(OK, rv); |
| 7143 | } |
| 7144 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7145 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7146 | HttpRequestInfo request; |
| 7147 | request.method = "GET"; |
| 7148 | request.url = GURL("https://www.google.com/"); |
| 7149 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7150 | "Chromium Ultra Awesome X Edition"); |
| 7151 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7152 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7153 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7154 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7156 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7157 | MockWrite data_writes[] = { |
| 7158 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 7159 | "Host: www.google.com\r\n" |
| 7160 | "Proxy-Connection: keep-alive\r\n" |
| 7161 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 7162 | }; |
| 7163 | MockRead data_reads[] = { |
| 7164 | // Return an error, so the transaction stops here (this test isn't |
| 7165 | // interested in the rest). |
| 7166 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7167 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7168 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7169 | }; |
| 7170 | |
| 7171 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7172 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7175 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7177 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7178 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7179 | |
| 7180 | rv = callback.WaitForResult(); |
| 7181 | EXPECT_EQ(OK, rv); |
| 7182 | } |
| 7183 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7184 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7185 | HttpRequestInfo request; |
| 7186 | request.method = "GET"; |
| 7187 | request.url = GURL("http://www.google.com/"); |
| 7188 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7189 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7190 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7191 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7192 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7193 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7195 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7196 | MockWrite data_writes[] = { |
| 7197 | MockWrite("GET / HTTP/1.1\r\n" |
| 7198 | "Host: www.google.com\r\n" |
| 7199 | "Connection: keep-alive\r\n" |
| 7200 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 7201 | }; |
| 7202 | |
| 7203 | // Lastly, the server responds with the actual content. |
| 7204 | MockRead data_reads[] = { |
| 7205 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7206 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7207 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7208 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7209 | }; |
| 7210 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7211 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7212 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7215 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7217 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7218 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7219 | |
| 7220 | rv = callback.WaitForResult(); |
| 7221 | EXPECT_EQ(OK, rv); |
| 7222 | } |
| 7223 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7224 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7225 | HttpRequestInfo request; |
| 7226 | request.method = "POST"; |
| 7227 | request.url = GURL("http://www.google.com/"); |
| 7228 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7229 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7230 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7231 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7232 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7233 | MockWrite data_writes[] = { |
| 7234 | MockWrite("POST / HTTP/1.1\r\n" |
| 7235 | "Host: www.google.com\r\n" |
| 7236 | "Connection: keep-alive\r\n" |
| 7237 | "Content-Length: 0\r\n\r\n"), |
| 7238 | }; |
| 7239 | |
| 7240 | // Lastly, the server responds with the actual content. |
| 7241 | MockRead data_reads[] = { |
| 7242 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7243 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7244 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7245 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7246 | }; |
| 7247 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7248 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7249 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7250 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7252 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7254 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7255 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7256 | |
| 7257 | rv = callback.WaitForResult(); |
| 7258 | EXPECT_EQ(OK, rv); |
| 7259 | } |
| 7260 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7261 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7262 | HttpRequestInfo request; |
| 7263 | request.method = "PUT"; |
| 7264 | request.url = GURL("http://www.google.com/"); |
| 7265 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7266 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7267 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7268 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7269 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7270 | MockWrite data_writes[] = { |
| 7271 | MockWrite("PUT / HTTP/1.1\r\n" |
| 7272 | "Host: www.google.com\r\n" |
| 7273 | "Connection: keep-alive\r\n" |
| 7274 | "Content-Length: 0\r\n\r\n"), |
| 7275 | }; |
| 7276 | |
| 7277 | // Lastly, the server responds with the actual content. |
| 7278 | MockRead data_reads[] = { |
| 7279 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7281 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7282 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7289 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7291 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7293 | |
| 7294 | rv = callback.WaitForResult(); |
| 7295 | EXPECT_EQ(OK, rv); |
| 7296 | } |
| 7297 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7298 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7299 | HttpRequestInfo request; |
| 7300 | request.method = "HEAD"; |
| 7301 | request.url = GURL("http://www.google.com/"); |
| 7302 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7303 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7304 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7306 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7307 | MockWrite data_writes[] = { |
| 7308 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7309 | "Host: www.google.com\r\n" |
| 7310 | "Connection: keep-alive\r\n" |
| 7311 | "Content-Length: 0\r\n\r\n"), |
| 7312 | }; |
| 7313 | |
| 7314 | // Lastly, the server responds with the actual content. |
| 7315 | MockRead data_reads[] = { |
| 7316 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7317 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7318 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7319 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7320 | }; |
| 7321 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7323 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7326 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7328 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7329 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7330 | |
| 7331 | rv = callback.WaitForResult(); |
| 7332 | EXPECT_EQ(OK, rv); |
| 7333 | } |
| 7334 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7335 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7336 | HttpRequestInfo request; |
| 7337 | request.method = "GET"; |
| 7338 | request.url = GURL("http://www.google.com/"); |
| 7339 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7340 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7341 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7342 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7343 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7344 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7345 | MockWrite data_writes[] = { |
| 7346 | MockWrite("GET / HTTP/1.1\r\n" |
| 7347 | "Host: www.google.com\r\n" |
| 7348 | "Connection: keep-alive\r\n" |
| 7349 | "Pragma: no-cache\r\n" |
| 7350 | "Cache-Control: no-cache\r\n\r\n"), |
| 7351 | }; |
| 7352 | |
| 7353 | // Lastly, the server responds with the actual content. |
| 7354 | MockRead data_reads[] = { |
| 7355 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7356 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7357 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7358 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7359 | }; |
| 7360 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7361 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7362 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7365 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7367 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7369 | |
| 7370 | rv = callback.WaitForResult(); |
| 7371 | EXPECT_EQ(OK, rv); |
| 7372 | } |
| 7373 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7374 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7375 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7376 | HttpRequestInfo request; |
| 7377 | request.method = "GET"; |
| 7378 | request.url = GURL("http://www.google.com/"); |
| 7379 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7380 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7381 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7382 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7384 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7385 | MockWrite data_writes[] = { |
| 7386 | MockWrite("GET / HTTP/1.1\r\n" |
| 7387 | "Host: www.google.com\r\n" |
| 7388 | "Connection: keep-alive\r\n" |
| 7389 | "Cache-Control: max-age=0\r\n\r\n"), |
| 7390 | }; |
| 7391 | |
| 7392 | // Lastly, the server responds with the actual content. |
| 7393 | MockRead data_reads[] = { |
| 7394 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7395 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7396 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7397 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7398 | }; |
| 7399 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7400 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7401 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7402 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7404 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7405 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7406 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7407 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7408 | |
| 7409 | rv = callback.WaitForResult(); |
| 7410 | EXPECT_EQ(OK, rv); |
| 7411 | } |
| 7412 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7413 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7414 | HttpRequestInfo request; |
| 7415 | request.method = "GET"; |
| 7416 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7417 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7418 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7419 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7420 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7421 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7422 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7423 | MockWrite data_writes[] = { |
| 7424 | MockWrite("GET / HTTP/1.1\r\n" |
| 7425 | "Host: www.google.com\r\n" |
| 7426 | "Connection: keep-alive\r\n" |
| 7427 | "FooHeader: Bar\r\n\r\n"), |
| 7428 | }; |
| 7429 | |
| 7430 | // Lastly, the server responds with the actual content. |
| 7431 | MockRead data_reads[] = { |
| 7432 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7433 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7434 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7435 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7436 | }; |
| 7437 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7438 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7439 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7440 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7442 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7444 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7446 | |
| 7447 | rv = callback.WaitForResult(); |
| 7448 | EXPECT_EQ(OK, rv); |
| 7449 | } |
| 7450 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7451 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7452 | HttpRequestInfo request; |
| 7453 | request.method = "GET"; |
| 7454 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7455 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7456 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7457 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7458 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7459 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7460 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7461 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7462 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7463 | MockWrite data_writes[] = { |
| 7464 | MockWrite("GET / HTTP/1.1\r\n" |
| 7465 | "Host: www.google.com\r\n" |
| 7466 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7467 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7468 | "hEllo: Kitty\r\n" |
| 7469 | "FoO: bar\r\n\r\n"), |
| 7470 | }; |
| 7471 | |
| 7472 | // Lastly, the server responds with the actual content. |
| 7473 | MockRead data_reads[] = { |
| 7474 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7475 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7476 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7477 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7478 | }; |
| 7479 | |
| 7480 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7481 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7482 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7484 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7486 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7487 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7488 | |
| 7489 | rv = callback.WaitForResult(); |
| 7490 | EXPECT_EQ(OK, rv); |
| 7491 | } |
| 7492 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7493 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7494 | HttpRequestInfo request; |
| 7495 | request.method = "GET"; |
| 7496 | request.url = GURL("http://www.google.com/"); |
| 7497 | request.load_flags = 0; |
| 7498 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7499 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7500 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 7501 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7502 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7503 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7504 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7505 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7506 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7507 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7508 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7509 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7510 | |
| 7511 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7512 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7513 | MockWrite("GET / HTTP/1.1\r\n" |
| 7514 | "Host: www.google.com\r\n" |
| 7515 | "Connection: keep-alive\r\n\r\n") |
| 7516 | }; |
| 7517 | |
| 7518 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7519 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7520 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7521 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7522 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7523 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7524 | }; |
| 7525 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7526 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7527 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7528 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7530 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7532 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7533 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7534 | |
| 7535 | rv = callback.WaitForResult(); |
| 7536 | EXPECT_EQ(OK, rv); |
| 7537 | |
| 7538 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7539 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7540 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7541 | LoadTimingInfo load_timing_info; |
| 7542 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7543 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7544 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7545 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7546 | std::string response_text; |
| 7547 | rv = ReadTransaction(trans.get(), &response_text); |
| 7548 | EXPECT_EQ(OK, rv); |
| 7549 | EXPECT_EQ("Payload", response_text); |
| 7550 | } |
| 7551 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7552 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7553 | HttpRequestInfo request; |
| 7554 | request.method = "GET"; |
| 7555 | request.url = GURL("https://www.google.com/"); |
| 7556 | request.load_flags = 0; |
| 7557 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7558 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7559 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 7560 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7561 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7562 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7563 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7564 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7565 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7566 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7567 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7568 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7569 | |
| 7570 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7571 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7572 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7573 | MockWrite("GET / HTTP/1.1\r\n" |
| 7574 | "Host: www.google.com\r\n" |
| 7575 | "Connection: keep-alive\r\n\r\n") |
| 7576 | }; |
| 7577 | |
| 7578 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7579 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7580 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7581 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7582 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7583 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7584 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7585 | }; |
| 7586 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7587 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7588 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7589 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7590 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7591 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7594 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7596 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7597 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7598 | |
| 7599 | rv = callback.WaitForResult(); |
| 7600 | EXPECT_EQ(OK, rv); |
| 7601 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7602 | LoadTimingInfo load_timing_info; |
| 7603 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7604 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7605 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7606 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7607 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7608 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7609 | |
| 7610 | std::string response_text; |
| 7611 | rv = ReadTransaction(trans.get(), &response_text); |
| 7612 | EXPECT_EQ(OK, rv); |
| 7613 | EXPECT_EQ("Payload", response_text); |
| 7614 | } |
| 7615 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7616 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7617 | HttpRequestInfo request; |
| 7618 | request.method = "GET"; |
| 7619 | request.url = GURL("http://www.google.com/"); |
| 7620 | request.load_flags = 0; |
| 7621 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7622 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7623 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 7624 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7625 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7626 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7627 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7628 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7629 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7630 | |
| 7631 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7632 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7633 | |
| 7634 | MockWrite data_writes[] = { |
| 7635 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7636 | MockWrite("GET / HTTP/1.1\r\n" |
| 7637 | "Host: www.google.com\r\n" |
| 7638 | "Connection: keep-alive\r\n\r\n") |
| 7639 | }; |
| 7640 | |
| 7641 | MockRead data_reads[] = { |
| 7642 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7643 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7644 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7645 | MockRead("Payload"), |
| 7646 | MockRead(SYNCHRONOUS, OK) |
| 7647 | }; |
| 7648 | |
| 7649 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7650 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7652 | |
| 7653 | TestCompletionCallback callback; |
| 7654 | |
| 7655 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7656 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7657 | |
| 7658 | rv = callback.WaitForResult(); |
| 7659 | EXPECT_EQ(OK, rv); |
| 7660 | |
| 7661 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7662 | ASSERT_TRUE(response != NULL); |
| 7663 | |
| 7664 | LoadTimingInfo load_timing_info; |
| 7665 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7666 | TestLoadTimingNotReused(load_timing_info, |
| 7667 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7668 | |
| 7669 | std::string response_text; |
| 7670 | rv = ReadTransaction(trans.get(), &response_text); |
| 7671 | EXPECT_EQ(OK, rv); |
| 7672 | EXPECT_EQ("Payload", response_text); |
| 7673 | } |
| 7674 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7675 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7676 | HttpRequestInfo request; |
| 7677 | request.method = "GET"; |
| 7678 | request.url = GURL("http://www.google.com/"); |
| 7679 | request.load_flags = 0; |
| 7680 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7681 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7682 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 7683 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7684 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7685 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7686 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7687 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7688 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7689 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7690 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7691 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7692 | const char kSOCKS5OkRequest[] = { |
| 7693 | 0x05, // Version |
| 7694 | 0x01, // Command (CONNECT) |
| 7695 | 0x00, // Reserved. |
| 7696 | 0x03, // Address type (DOMAINNAME). |
| 7697 | 0x0E, // Length of domain (14) |
| 7698 | // Domain string: |
| 7699 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7700 | 0x00, 0x50, // 16-bit port (80) |
| 7701 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7702 | const char kSOCKS5OkResponse[] = |
| 7703 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7704 | |
| 7705 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7706 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7707 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7708 | MockWrite("GET / HTTP/1.1\r\n" |
| 7709 | "Host: www.google.com\r\n" |
| 7710 | "Connection: keep-alive\r\n\r\n") |
| 7711 | }; |
| 7712 | |
| 7713 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7714 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7715 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7716 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7717 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7718 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7719 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7720 | }; |
| 7721 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7722 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7723 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7724 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7726 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7728 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7729 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7730 | |
| 7731 | rv = callback.WaitForResult(); |
| 7732 | EXPECT_EQ(OK, rv); |
| 7733 | |
| 7734 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7735 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7736 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7737 | LoadTimingInfo load_timing_info; |
| 7738 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7739 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7740 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7741 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7742 | std::string response_text; |
| 7743 | rv = ReadTransaction(trans.get(), &response_text); |
| 7744 | EXPECT_EQ(OK, rv); |
| 7745 | EXPECT_EQ("Payload", response_text); |
| 7746 | } |
| 7747 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7748 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7749 | HttpRequestInfo request; |
| 7750 | request.method = "GET"; |
| 7751 | request.url = GURL("https://www.google.com/"); |
| 7752 | request.load_flags = 0; |
| 7753 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7754 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7755 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 7756 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7757 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7758 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7759 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7760 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7761 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7762 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7763 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7764 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7765 | const unsigned char kSOCKS5OkRequest[] = { |
| 7766 | 0x05, // Version |
| 7767 | 0x01, // Command (CONNECT) |
| 7768 | 0x00, // Reserved. |
| 7769 | 0x03, // Address type (DOMAINNAME). |
| 7770 | 0x0E, // Length of domain (14) |
| 7771 | // Domain string: |
| 7772 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7773 | 0x01, 0xBB, // 16-bit port (443) |
| 7774 | }; |
| 7775 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7776 | const char kSOCKS5OkResponse[] = |
| 7777 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7778 | |
| 7779 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7780 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7781 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7782 | arraysize(kSOCKS5OkRequest)), |
| 7783 | MockWrite("GET / HTTP/1.1\r\n" |
| 7784 | "Host: www.google.com\r\n" |
| 7785 | "Connection: keep-alive\r\n\r\n") |
| 7786 | }; |
| 7787 | |
| 7788 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7789 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7790 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7791 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7792 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7793 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7794 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7795 | }; |
| 7796 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7797 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7798 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7799 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7800 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7801 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7802 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7804 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7806 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7808 | |
| 7809 | rv = callback.WaitForResult(); |
| 7810 | EXPECT_EQ(OK, rv); |
| 7811 | |
| 7812 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7813 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7814 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7815 | LoadTimingInfo load_timing_info; |
| 7816 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7817 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7818 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7819 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7820 | std::string response_text; |
| 7821 | rv = ReadTransaction(trans.get(), &response_text); |
| 7822 | EXPECT_EQ(OK, rv); |
| 7823 | EXPECT_EQ("Payload", response_text); |
| 7824 | } |
| 7825 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7826 | namespace { |
| 7827 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7828 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7829 | |
| 7830 | struct GroupNameTest { |
| 7831 | std::string proxy_server; |
| 7832 | std::string url; |
| 7833 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7834 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7835 | }; |
| 7836 | |
| 7837 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7838 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7839 | SpdySessionDependencies* session_deps_) { |
| 7840 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7841 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7842 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7843 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7844 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 7845 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7846 | http_server_properties->SetAlternativeService( |
| 7847 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7848 | |
| 7849 | return session; |
| 7850 | } |
| 7851 | |
| 7852 | int GroupNameTransactionHelper( |
| 7853 | const std::string& url, |
| 7854 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7855 | HttpRequestInfo request; |
| 7856 | request.method = "GET"; |
| 7857 | request.url = GURL(url); |
| 7858 | request.load_flags = 0; |
| 7859 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7863 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7864 | |
| 7865 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7866 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7867 | } |
| 7868 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7869 | } // namespace |
| 7870 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7871 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7872 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7873 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7874 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7875 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7876 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7877 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7878 | }, |
| 7879 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7880 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7881 | "http://[2001:1418:13:1::25]/direct", |
| 7882 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7883 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7884 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7885 | |
| 7886 | // SSL Tests |
| 7887 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7888 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7889 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7890 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7891 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7892 | }, |
| 7893 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7894 | "", // unused |
| 7895 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7896 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7897 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7898 | }, |
| 7899 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7900 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7901 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7902 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7903 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7904 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7905 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7906 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7907 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7908 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7909 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7910 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7911 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7912 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7913 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7914 | |
| 7915 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7916 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7917 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7918 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7919 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7920 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7921 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7922 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7923 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7924 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7925 | |
| 7926 | EXPECT_EQ(ERR_IO_PENDING, |
| 7927 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7928 | if (tests[i].ssl) |
| 7929 | EXPECT_EQ(tests[i].expected_group_name, |
| 7930 | ssl_conn_pool->last_group_name_received()); |
| 7931 | else |
| 7932 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7933 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7934 | } |
| 7935 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7936 | } |
| 7937 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7938 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7939 | const GroupNameTest tests[] = { |
| 7940 | { |
| 7941 | "http_proxy", |
| 7942 | "http://www.google.com/http_proxy_normal", |
| 7943 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7944 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7945 | }, |
| 7946 | |
| 7947 | // SSL Tests |
| 7948 | { |
| 7949 | "http_proxy", |
| 7950 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7951 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7952 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7953 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7954 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7955 | { |
| 7956 | "http_proxy", |
| 7957 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7958 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7959 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7960 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7961 | |
| 7962 | { |
| 7963 | "http_proxy", |
| 7964 | "ftp://ftp.google.com/http_proxy_normal", |
| 7965 | "ftp/ftp.google.com:21", |
| 7966 | false, |
| 7967 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7968 | }; |
| 7969 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7970 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7971 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7972 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7973 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7974 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7975 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7976 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7977 | |
| 7978 | HttpNetworkSessionPeer peer(session); |
| 7979 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7980 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7981 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7982 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7983 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7984 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7985 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7986 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7987 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7988 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7989 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7990 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7991 | |
| 7992 | EXPECT_EQ(ERR_IO_PENDING, |
| 7993 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7994 | if (tests[i].ssl) |
| 7995 | EXPECT_EQ(tests[i].expected_group_name, |
| 7996 | ssl_conn_pool->last_group_name_received()); |
| 7997 | else |
| 7998 | EXPECT_EQ(tests[i].expected_group_name, |
| 7999 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8000 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8001 | } |
| 8002 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8003 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8004 | const GroupNameTest tests[] = { |
| 8005 | { |
| 8006 | "socks4://socks_proxy:1080", |
| 8007 | "http://www.google.com/socks4_direct", |
| 8008 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8009 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8010 | }, |
| 8011 | { |
| 8012 | "socks5://socks_proxy:1080", |
| 8013 | "http://www.google.com/socks5_direct", |
| 8014 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8015 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8016 | }, |
| 8017 | |
| 8018 | // SSL Tests |
| 8019 | { |
| 8020 | "socks4://socks_proxy:1080", |
| 8021 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 8022 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8023 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8024 | }, |
| 8025 | { |
| 8026 | "socks5://socks_proxy:1080", |
| 8027 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 8028 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8029 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8030 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8031 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 8032 | { |
| 8033 | "socks4://socks_proxy:1080", |
| 8034 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 8035 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8036 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 8037 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8038 | }; |
| 8039 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8040 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8041 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8042 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8043 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8044 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8045 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8046 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8047 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8048 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8049 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8050 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8051 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8052 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8053 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8054 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8055 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8056 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8057 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8058 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8059 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8060 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8061 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8062 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8064 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8065 | EXPECT_EQ(ERR_IO_PENDING, |
| 8066 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8067 | if (tests[i].ssl) |
| 8068 | EXPECT_EQ(tests[i].expected_group_name, |
| 8069 | ssl_conn_pool->last_group_name_received()); |
| 8070 | else |
| 8071 | EXPECT_EQ(tests[i].expected_group_name, |
| 8072 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8073 | } |
| 8074 | } |
| 8075 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8076 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8077 | HttpRequestInfo request; |
| 8078 | request.method = "GET"; |
| 8079 | request.url = GURL("http://www.google.com/"); |
| 8080 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8081 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8082 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8083 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8084 | // This simulates failure resolving all hostnames; that means we will fail |
| 8085 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8086 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8087 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8088 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8089 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8090 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8092 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8094 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8096 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8097 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8098 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8099 | } |
| 8100 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8101 | // Base test to make sure that when the load flags for a request specify to |
| 8102 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8103 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8104 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8105 | // Issue a request, asking to bypass the cache(s). |
| 8106 | HttpRequestInfo request; |
| 8107 | request.method = "GET"; |
| 8108 | request.load_flags = load_flags; |
| 8109 | request.url = GURL("http://www.google.com/"); |
| 8110 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8111 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8112 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8113 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8114 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8115 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8116 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8117 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8118 | // 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] | 8119 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8120 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8121 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 8122 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 8123 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 8124 | &addrlist, |
| 8125 | callback.callback(), |
| 8126 | NULL, |
| 8127 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8129 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8130 | EXPECT_EQ(OK, rv); |
| 8131 | |
| 8132 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8133 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8134 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 8135 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 8136 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 8137 | &addrlist, |
| 8138 | callback.callback(), |
| 8139 | NULL, |
| 8140 | BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8141 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8142 | |
| 8143 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 8144 | // we can tell if the next lookup hit the cache, or the "network". |
| 8145 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8146 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8147 | |
| 8148 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8149 | // 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] | 8150 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8152 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8153 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8154 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8155 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8156 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8157 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8158 | |
| 8159 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 8160 | // "www.google.com". |
| 8161 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8162 | } |
| 8163 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8164 | // There are multiple load flags that should trigger the host cache bypass. |
| 8165 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8166 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8167 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8168 | } |
| 8169 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8170 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8171 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8172 | } |
| 8173 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8174 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8175 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8176 | } |
| 8177 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8178 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8179 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8180 | HttpRequestInfo request; |
| 8181 | request.method = "GET"; |
| 8182 | request.url = GURL("http://www.foo.com/"); |
| 8183 | request.load_flags = 0; |
| 8184 | |
| 8185 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8186 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8187 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8188 | StaticSocketDataProvider data(NULL, 0, |
| 8189 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8190 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8191 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8193 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8194 | |
| 8195 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8196 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8198 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8199 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8200 | |
| 8201 | rv = callback.WaitForResult(); |
| 8202 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8203 | } |
| 8204 | |
| 8205 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8206 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8207 | HttpRequestInfo request; |
| 8208 | request.method = "GET"; |
| 8209 | request.url = GURL("http://www.foo.com/"); |
| 8210 | request.load_flags = 0; |
| 8211 | |
| 8212 | MockRead data_reads[] = { |
| 8213 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8214 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8215 | }; |
| 8216 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8217 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8219 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8221 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8222 | |
| 8223 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8224 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8226 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8227 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8228 | |
| 8229 | rv = callback.WaitForResult(); |
| 8230 | EXPECT_EQ(OK, rv); |
| 8231 | |
| 8232 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8233 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8234 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8235 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8236 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8237 | |
| 8238 | std::string response_data; |
| 8239 | rv = ReadTransaction(trans.get(), &response_data); |
| 8240 | EXPECT_EQ(OK, rv); |
| 8241 | EXPECT_EQ("", response_data); |
| 8242 | } |
| 8243 | |
| 8244 | // Make sure that a dropped connection while draining the body for auth |
| 8245 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8246 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8247 | HttpRequestInfo request; |
| 8248 | request.method = "GET"; |
| 8249 | request.url = GURL("http://www.google.com/"); |
| 8250 | request.load_flags = 0; |
| 8251 | |
| 8252 | MockWrite data_writes1[] = { |
| 8253 | MockWrite("GET / HTTP/1.1\r\n" |
| 8254 | "Host: www.google.com\r\n" |
| 8255 | "Connection: keep-alive\r\n\r\n"), |
| 8256 | }; |
| 8257 | |
| 8258 | MockRead data_reads1[] = { |
| 8259 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8260 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8261 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8262 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8263 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8264 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8265 | }; |
| 8266 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8268 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8270 | |
| 8271 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8272 | // be issuing -- the final header line contains the credentials. |
| 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 Zm9vOmJhcg==\r\n\r\n"), |
| 8278 | }; |
| 8279 | |
| 8280 | // Lastly, the server responds with the actual content. |
| 8281 | MockRead data_reads2[] = { |
| 8282 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8283 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8284 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8285 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8286 | }; |
| 8287 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8288 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8289 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8290 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8291 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8293 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8294 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8295 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8296 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8297 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8298 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8299 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8300 | |
| 8301 | rv = callback1.WaitForResult(); |
| 8302 | EXPECT_EQ(OK, rv); |
| 8303 | |
| 8304 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8305 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8306 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8308 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8310 | rv = trans->RestartWithAuth( |
| 8311 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8312 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8313 | |
| 8314 | rv = callback2.WaitForResult(); |
| 8315 | EXPECT_EQ(OK, rv); |
| 8316 | |
| 8317 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8318 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8319 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8320 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8321 | } |
| 8322 | |
| 8323 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8324 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8325 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8326 | |
| 8327 | HttpRequestInfo request; |
| 8328 | request.method = "GET"; |
| 8329 | request.url = GURL("https://www.google.com/"); |
| 8330 | request.load_flags = 0; |
| 8331 | |
| 8332 | MockRead proxy_reads[] = { |
| 8333 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8334 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8335 | }; |
| 8336 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8337 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8338 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8339 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8340 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8343 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8344 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8345 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8346 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8347 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8348 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8349 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8351 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8352 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8353 | |
| 8354 | rv = callback.WaitForResult(); |
| 8355 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8356 | } |
| 8357 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8358 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8359 | HttpRequestInfo request; |
| 8360 | request.method = "GET"; |
| 8361 | request.url = GURL("http://www.google.com/"); |
| 8362 | request.load_flags = 0; |
| 8363 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8364 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8365 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8366 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8367 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8368 | MockRead data_reads[] = { |
| 8369 | 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] | 8370 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8371 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8372 | |
| 8373 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8376 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8378 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8380 | |
| 8381 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8382 | |
| 8383 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8384 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8385 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8386 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8387 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8388 | |
| 8389 | std::string response_data; |
| 8390 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8391 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8392 | } |
| 8393 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8394 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8395 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8396 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8397 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8398 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8399 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8400 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8401 | ScopedVector<UploadElementReader> element_readers; |
| 8402 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8403 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8404 | temp_file_path, |
| 8405 | 0, |
| 8406 | kuint64max, |
| 8407 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8408 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8409 | |
| 8410 | HttpRequestInfo request; |
| 8411 | request.method = "POST"; |
| 8412 | request.url = GURL("http://www.google.com/upload"); |
| 8413 | request.upload_data_stream = &upload_data_stream; |
| 8414 | request.load_flags = 0; |
| 8415 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8416 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8417 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8418 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8419 | |
| 8420 | MockRead data_reads[] = { |
| 8421 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8422 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8423 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8424 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8425 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8428 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [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] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8431 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8432 | |
| 8433 | rv = callback.WaitForResult(); |
| 8434 | EXPECT_EQ(OK, rv); |
| 8435 | |
| 8436 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8437 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8438 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8439 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8440 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8441 | |
| 8442 | std::string response_data; |
| 8443 | rv = ReadTransaction(trans.get(), &response_data); |
| 8444 | EXPECT_EQ(OK, rv); |
| 8445 | EXPECT_EQ("hello world", response_data); |
| 8446 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8447 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8448 | } |
| 8449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8450 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8451 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8452 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8453 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8454 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8455 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8456 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8457 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8458 | ScopedVector<UploadElementReader> element_readers; |
| 8459 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8460 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8461 | temp_file, |
| 8462 | 0, |
| 8463 | kuint64max, |
| 8464 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8465 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8466 | |
| 8467 | HttpRequestInfo request; |
| 8468 | request.method = "POST"; |
| 8469 | request.url = GURL("http://www.google.com/upload"); |
| 8470 | request.upload_data_stream = &upload_data_stream; |
| 8471 | request.load_flags = 0; |
| 8472 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8473 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8474 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8475 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8477 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8478 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8481 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8483 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8484 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8485 | |
| 8486 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8487 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8488 | |
| 8489 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8490 | EXPECT_FALSE(response); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8491 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8492 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8493 | } |
| 8494 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8495 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8496 | class FakeUploadElementReader : public UploadElementReader { |
| 8497 | public: |
| 8498 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8499 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8500 | |
| 8501 | const CompletionCallback& callback() const { return callback_; } |
| 8502 | |
| 8503 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8504 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8505 | callback_ = callback; |
| 8506 | return ERR_IO_PENDING; |
| 8507 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8508 | uint64 GetContentLength() const override { return 0; } |
| 8509 | uint64 BytesRemaining() const override { return 0; } |
| 8510 | int Read(IOBuffer* buf, |
| 8511 | int buf_length, |
| 8512 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8513 | return ERR_FAILED; |
| 8514 | } |
| 8515 | |
| 8516 | private: |
| 8517 | CompletionCallback callback_; |
| 8518 | }; |
| 8519 | |
| 8520 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8521 | ScopedVector<UploadElementReader> element_readers; |
| 8522 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8523 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8524 | |
| 8525 | HttpRequestInfo request; |
| 8526 | request.method = "POST"; |
| 8527 | request.url = GURL("http://www.google.com/upload"); |
| 8528 | request.upload_data_stream = &upload_data_stream; |
| 8529 | request.load_flags = 0; |
| 8530 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8531 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8532 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8533 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8534 | |
| 8535 | StaticSocketDataProvider data; |
| 8536 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8537 | |
| 8538 | TestCompletionCallback callback; |
| 8539 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8540 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8541 | base::MessageLoop::current()->RunUntilIdle(); |
| 8542 | |
| 8543 | // Transaction is pending on request body initialization. |
| 8544 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8545 | |
| 8546 | // Return Init()'s result after the transaction gets destroyed. |
| 8547 | trans.reset(); |
| 8548 | fake_reader->callback().Run(OK); // Should not crash. |
| 8549 | } |
| 8550 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8551 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8552 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8553 | |
| 8554 | HttpRequestInfo request; |
| 8555 | request.method = "GET"; |
| 8556 | request.url = GURL("http://www.google.com/"); |
| 8557 | request.load_flags = 0; |
| 8558 | |
| 8559 | // First transaction will request a resource and receive a Basic challenge |
| 8560 | // with realm="first_realm". |
| 8561 | MockWrite data_writes1[] = { |
| 8562 | MockWrite("GET / HTTP/1.1\r\n" |
| 8563 | "Host: www.google.com\r\n" |
| 8564 | "Connection: keep-alive\r\n" |
| 8565 | "\r\n"), |
| 8566 | }; |
| 8567 | MockRead data_reads1[] = { |
| 8568 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8569 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8570 | "\r\n"), |
| 8571 | }; |
| 8572 | |
| 8573 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8574 | // for first_realm. The server will reject and provide a challenge with |
| 8575 | // second_realm. |
| 8576 | MockWrite data_writes2[] = { |
| 8577 | MockWrite("GET / HTTP/1.1\r\n" |
| 8578 | "Host: www.google.com\r\n" |
| 8579 | "Connection: keep-alive\r\n" |
| 8580 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8581 | "\r\n"), |
| 8582 | }; |
| 8583 | MockRead data_reads2[] = { |
| 8584 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8585 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8586 | "\r\n"), |
| 8587 | }; |
| 8588 | |
| 8589 | // This again fails, and goes back to first_realm. Make sure that the |
| 8590 | // entry is removed from cache. |
| 8591 | MockWrite data_writes3[] = { |
| 8592 | MockWrite("GET / HTTP/1.1\r\n" |
| 8593 | "Host: www.google.com\r\n" |
| 8594 | "Connection: keep-alive\r\n" |
| 8595 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8596 | "\r\n"), |
| 8597 | }; |
| 8598 | MockRead data_reads3[] = { |
| 8599 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8600 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8601 | "\r\n"), |
| 8602 | }; |
| 8603 | |
| 8604 | // Try one last time (with the correct password) and get the resource. |
| 8605 | MockWrite data_writes4[] = { |
| 8606 | MockWrite("GET / HTTP/1.1\r\n" |
| 8607 | "Host: www.google.com\r\n" |
| 8608 | "Connection: keep-alive\r\n" |
| 8609 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8610 | "\r\n"), |
| 8611 | }; |
| 8612 | MockRead data_reads4[] = { |
| 8613 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8614 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8615 | "Content-Length: 5\r\n" |
| 8616 | "\r\n" |
| 8617 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8618 | }; |
| 8619 | |
| 8620 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8621 | data_writes1, arraysize(data_writes1)); |
| 8622 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8623 | data_writes2, arraysize(data_writes2)); |
| 8624 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8625 | data_writes3, arraysize(data_writes3)); |
| 8626 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8627 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8628 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8629 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8630 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8631 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8633 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8634 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8635 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8636 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8637 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8638 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8639 | // Issue the first request with Authorize headers. There should be a |
| 8640 | // password prompt for first_realm waiting to be filled in after the |
| 8641 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8642 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8643 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8644 | rv = callback1.WaitForResult(); |
| 8645 | EXPECT_EQ(OK, rv); |
| 8646 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8647 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8648 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8649 | ASSERT_FALSE(challenge == NULL); |
| 8650 | EXPECT_FALSE(challenge->is_proxy); |
| 8651 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8652 | EXPECT_EQ("first_realm", challenge->realm); |
| 8653 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8654 | |
| 8655 | // Issue the second request with an incorrect password. There should be a |
| 8656 | // password prompt for second_realm waiting to be filled in after the |
| 8657 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8658 | TestCompletionCallback callback2; |
| 8659 | rv = trans->RestartWithAuth( |
| 8660 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8662 | rv = callback2.WaitForResult(); |
| 8663 | EXPECT_EQ(OK, rv); |
| 8664 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8665 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8666 | challenge = response->auth_challenge.get(); |
| 8667 | ASSERT_FALSE(challenge == NULL); |
| 8668 | EXPECT_FALSE(challenge->is_proxy); |
| 8669 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8670 | EXPECT_EQ("second_realm", challenge->realm); |
| 8671 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8672 | |
| 8673 | // Issue the third request with another incorrect password. There should be |
| 8674 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8675 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8676 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8677 | TestCompletionCallback callback3; |
| 8678 | rv = trans->RestartWithAuth( |
| 8679 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8680 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8681 | rv = callback3.WaitForResult(); |
| 8682 | EXPECT_EQ(OK, rv); |
| 8683 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8684 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8685 | challenge = response->auth_challenge.get(); |
| 8686 | ASSERT_FALSE(challenge == NULL); |
| 8687 | EXPECT_FALSE(challenge->is_proxy); |
| 8688 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8689 | EXPECT_EQ("first_realm", challenge->realm); |
| 8690 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8691 | |
| 8692 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8693 | TestCompletionCallback callback4; |
| 8694 | rv = trans->RestartWithAuth( |
| 8695 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8696 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8697 | rv = callback4.WaitForResult(); |
| 8698 | EXPECT_EQ(OK, rv); |
| 8699 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8700 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8701 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8702 | } |
| 8703 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8704 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8705 | session_deps_.next_protos = SpdyNextProtos(); |
| 8706 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8707 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8708 | std::string alternate_protocol_http_header = |
| 8709 | GetAlternateProtocolHttpHeader(); |
| 8710 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8711 | MockRead data_reads[] = { |
| 8712 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8713 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8714 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8716 | }; |
| 8717 | |
| 8718 | HttpRequestInfo request; |
| 8719 | request.method = "GET"; |
| 8720 | request.url = GURL("http://www.google.com/"); |
| 8721 | request.load_flags = 0; |
| 8722 | |
| 8723 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8724 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8725 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8727 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8728 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8729 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8730 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8731 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8733 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8734 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8735 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 8736 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8737 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8738 | *session->http_server_properties(); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8739 | AlternativeService alternative_service = |
| 8740 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8741 | EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8742 | |
| 8743 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8744 | |
| 8745 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8746 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8747 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8748 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8749 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8750 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8751 | |
| 8752 | std::string response_data; |
| 8753 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8754 | EXPECT_EQ("hello world", response_data); |
| 8755 | |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8756 | alternative_service = |
| 8757 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8758 | EXPECT_EQ(443, alternative_service.port); |
| 8759 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8760 | alternative_service.protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8761 | } |
| 8762 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8763 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 8764 | session_deps_.next_protos = SpdyNextProtos(); |
| 8765 | session_deps_.use_alternate_protocols = true; |
| 8766 | |
| 8767 | MockRead data_reads[] = { |
| 8768 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8769 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 8770 | MockRead("hello world"), |
| 8771 | MockRead(SYNCHRONOUS, OK), |
| 8772 | }; |
| 8773 | |
| 8774 | HttpRequestInfo request; |
| 8775 | request.method = "GET"; |
| 8776 | request.url = GURL("http://www.google.com/"); |
| 8777 | request.load_flags = 0; |
| 8778 | |
| 8779 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8780 | |
| 8781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8782 | |
| 8783 | TestCompletionCallback callback; |
| 8784 | |
| 8785 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8786 | |
| 8787 | HostPortPair http_host_port_pair("www.google.com", 80); |
| 8788 | HttpServerProperties& http_server_properties = |
| 8789 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8790 | AlternativeService alternative_service(QUIC, "", 80); |
| 8791 | http_server_properties.SetAlternativeService(http_host_port_pair, |
| 8792 | alternative_service, 1.0); |
| 8793 | |
| 8794 | alternative_service = |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8795 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8796 | EXPECT_EQ(alternative_service.protocol, QUIC); |
| 8797 | |
| 8798 | scoped_ptr<HttpTransaction> trans( |
| 8799 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8800 | |
| 8801 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8803 | |
| 8804 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8805 | |
| 8806 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8807 | ASSERT_TRUE(response != NULL); |
| 8808 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8809 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8810 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8811 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8812 | |
| 8813 | std::string response_data; |
| 8814 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8815 | EXPECT_EQ("hello world", response_data); |
| 8816 | |
| 8817 | alternative_service = |
| 8818 | http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8819 | EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
| 8820 | } |
| 8821 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8822 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8823 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8824 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8825 | |
| 8826 | HttpRequestInfo request; |
| 8827 | request.method = "GET"; |
| 8828 | request.url = GURL("http://www.google.com/"); |
| 8829 | request.load_flags = 0; |
| 8830 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8831 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8832 | StaticSocketDataProvider first_data; |
| 8833 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8834 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8835 | |
| 8836 | MockRead data_reads[] = { |
| 8837 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8838 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8839 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8840 | }; |
| 8841 | StaticSocketDataProvider second_data( |
| 8842 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8843 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8844 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8845 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8846 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8847 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8848 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 8849 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8850 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8851 | // port 80 (another restricted port). |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8852 | AlternativeService alternative_service( |
| 8853 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8854 | 666); /* port is ignored by MockConnect anyway */ |
| 8855 | http_server_properties->SetAlternativeService(host_port_pair, |
| 8856 | alternative_service, 1.0); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8857 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8858 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8859 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8860 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8862 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8863 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8864 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8865 | |
| 8866 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8867 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8868 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8869 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8870 | |
| 8871 | std::string response_data; |
| 8872 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8873 | EXPECT_EQ("hello world", response_data); |
| 8874 | |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8875 | alternative_service = |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8876 | http_server_properties->GetAlternativeService(host_port_pair); |
| 8877 | EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 8878 | EXPECT_TRUE( |
| 8879 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8880 | } |
| 8881 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8882 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8883 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8884 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8885 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8886 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8887 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8888 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8889 | |
| 8890 | HttpRequestInfo restricted_port_request; |
| 8891 | restricted_port_request.method = "GET"; |
| 8892 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8893 | restricted_port_request.load_flags = 0; |
| 8894 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8895 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8896 | StaticSocketDataProvider first_data; |
| 8897 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8898 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8899 | |
| 8900 | MockRead data_reads[] = { |
| 8901 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8902 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8903 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8904 | }; |
| 8905 | StaticSocketDataProvider second_data( |
| 8906 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8907 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8908 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8909 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8910 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8911 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8912 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8913 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8914 | AlternativeService alternative_service( |
| 8915 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8916 | kUnrestrictedAlternatePort); |
| 8917 | http_server_properties->SetAlternativeService( |
| 8918 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8919 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8920 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8921 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8922 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8923 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8925 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8926 | &restricted_port_request, |
| 8927 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8928 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8929 | // Invalid change to unrestricted port should fail. |
| 8930 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8931 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8932 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8933 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8934 | AlternateProtocolPortRestrictedPermitted) { |
| 8935 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8936 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8937 | // on a restricted port (port < 1024) if we set |
| 8938 | // enable_user_alternate_protocol_ports. |
| 8939 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8940 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8941 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8942 | |
| 8943 | HttpRequestInfo restricted_port_request; |
| 8944 | restricted_port_request.method = "GET"; |
| 8945 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8946 | restricted_port_request.load_flags = 0; |
| 8947 | |
| 8948 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8949 | StaticSocketDataProvider first_data; |
| 8950 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8951 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8952 | |
| 8953 | MockRead data_reads[] = { |
| 8954 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8955 | MockRead("hello world"), |
| 8956 | MockRead(ASYNC, OK), |
| 8957 | }; |
| 8958 | StaticSocketDataProvider second_data( |
| 8959 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8960 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8961 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8963 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8964 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8965 | session->http_server_properties(); |
| 8966 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8967 | AlternativeService alternative_service( |
| 8968 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 8969 | kUnrestrictedAlternatePort); |
| 8970 | http_server_properties->SetAlternativeService( |
| 8971 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8972 | 1.0); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8973 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8974 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8975 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8976 | TestCompletionCallback callback; |
| 8977 | |
| 8978 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8979 | &restricted_port_request, |
| 8980 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8981 | // Change to unrestricted port should succeed. |
| 8982 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8983 | } |
| 8984 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8985 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8986 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8987 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8988 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8989 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8990 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8991 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8992 | |
| 8993 | HttpRequestInfo restricted_port_request; |
| 8994 | restricted_port_request.method = "GET"; |
| 8995 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8996 | restricted_port_request.load_flags = 0; |
| 8997 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8998 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8999 | StaticSocketDataProvider first_data; |
| 9000 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9001 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9002 | |
| 9003 | MockRead data_reads[] = { |
| 9004 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9005 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9006 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9007 | }; |
| 9008 | StaticSocketDataProvider second_data( |
| 9009 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9010 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9011 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9012 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9013 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9014 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9015 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9016 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9017 | AlternativeService alternative_service( |
| 9018 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9019 | kRestrictedAlternatePort); |
| 9020 | http_server_properties->SetAlternativeService( |
| 9021 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9022 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9023 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9024 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9025 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9026 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9028 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9029 | &restricted_port_request, |
| 9030 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9032 | // Valid change to restricted port should pass. |
| 9033 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9034 | } |
| 9035 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9036 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9037 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9038 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9039 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9040 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9041 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9042 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9043 | |
| 9044 | HttpRequestInfo unrestricted_port_request; |
| 9045 | unrestricted_port_request.method = "GET"; |
| 9046 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 9047 | unrestricted_port_request.load_flags = 0; |
| 9048 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9049 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9050 | StaticSocketDataProvider first_data; |
| 9051 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9052 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9053 | |
| 9054 | MockRead data_reads[] = { |
| 9055 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9056 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9057 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9058 | }; |
| 9059 | StaticSocketDataProvider second_data( |
| 9060 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9061 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9062 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9063 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9064 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9065 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9066 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9067 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9068 | AlternativeService alternative_service( |
| 9069 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9070 | kRestrictedAlternatePort); |
| 9071 | http_server_properties->SetAlternativeService( |
| 9072 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9073 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9074 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9075 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9077 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9079 | int rv = trans->Start( |
| 9080 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9082 | // Valid change to restricted port should pass. |
| 9083 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9084 | } |
| 9085 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9086 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9087 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9088 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9089 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9090 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9091 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9092 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9093 | |
| 9094 | HttpRequestInfo unrestricted_port_request; |
| 9095 | unrestricted_port_request.method = "GET"; |
| 9096 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 9097 | unrestricted_port_request.load_flags = 0; |
| 9098 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9099 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9100 | StaticSocketDataProvider first_data; |
| 9101 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9102 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9103 | |
| 9104 | MockRead data_reads[] = { |
| 9105 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9106 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9107 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9108 | }; |
| 9109 | StaticSocketDataProvider second_data( |
| 9110 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9111 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9112 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9113 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9114 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9115 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9116 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9117 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9118 | AlternativeService alternative_service( |
| 9119 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9120 | kUnrestrictedAlternatePort); |
| 9121 | http_server_properties->SetAlternativeService( |
| 9122 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9123 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9124 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9125 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9126 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9127 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9129 | int rv = trans->Start( |
| 9130 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9131 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9132 | // Valid change to an unrestricted port should pass. |
| 9133 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9134 | } |
| 9135 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9136 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9137 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9138 | // protocol to an unsafe port, and that we resume the second |
| 9139 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9140 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9141 | |
| 9142 | HttpRequestInfo request; |
| 9143 | request.method = "GET"; |
| 9144 | request.url = GURL("http://www.google.com/"); |
| 9145 | request.load_flags = 0; |
| 9146 | |
| 9147 | // The alternate protocol request will error out before we attempt to connect, |
| 9148 | // so only the standard HTTP request will try to connect. |
| 9149 | MockRead data_reads[] = { |
| 9150 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9151 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9152 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9153 | }; |
| 9154 | StaticSocketDataProvider data( |
| 9155 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9156 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9157 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9158 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9159 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9160 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9161 | session->http_server_properties(); |
| 9162 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9163 | AlternativeService alternative_service( |
| 9164 | AlternateProtocolFromNextProto(GetParam()), "www.google.com", |
| 9165 | kUnsafePort); |
| 9166 | http_server_properties->SetAlternativeService( |
| 9167 | HostPortPair::FromURL(request.url), alternative_service, 1.0); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9168 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9169 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9170 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9171 | TestCompletionCallback callback; |
| 9172 | |
| 9173 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9174 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9175 | // The HTTP request should succeed. |
| 9176 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9177 | |
| 9178 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9179 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9180 | |
| 9181 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9182 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9183 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9184 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9185 | |
| 9186 | std::string response_data; |
| 9187 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9188 | EXPECT_EQ("hello world", response_data); |
| 9189 | } |
| 9190 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9191 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9192 | session_deps_.use_alternate_protocols = true; |
| 9193 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9194 | |
| 9195 | HttpRequestInfo request; |
| 9196 | request.method = "GET"; |
| 9197 | request.url = GURL("http://www.google.com/"); |
| 9198 | request.load_flags = 0; |
| 9199 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9200 | std::string alternate_protocol_http_header = |
| 9201 | GetAlternateProtocolHttpHeader(); |
| 9202 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9203 | MockRead data_reads[] = { |
| 9204 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9205 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9206 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9207 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9208 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9209 | }; |
| 9210 | |
| 9211 | StaticSocketDataProvider first_transaction( |
| 9212 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9213 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9214 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9215 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9216 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9217 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9218 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9219 | scoped_ptr<SpdyFrame> req( |
| 9220 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9221 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9222 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9223 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9224 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9225 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9226 | CreateMockRead(*resp), |
| 9227 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9228 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9229 | }; |
| 9230 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9231 | DelayedSocketData spdy_data( |
| 9232 | 1, // wait for one write to finish before reading. |
| 9233 | spdy_reads, arraysize(spdy_reads), |
| 9234 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9235 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9236 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9237 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9238 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9239 | NULL, 0, NULL, 0); |
| 9240 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9241 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9242 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9243 | &hanging_non_alternate_protocol_socket); |
| 9244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9245 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9246 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9247 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9248 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9251 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9253 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9254 | |
| 9255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9256 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9257 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9258 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9259 | |
| 9260 | std::string response_data; |
| 9261 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9262 | EXPECT_EQ("hello world", response_data); |
| 9263 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9264 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9266 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9267 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9268 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9269 | |
| 9270 | response = trans->GetResponseInfo(); |
| 9271 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9272 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9273 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9274 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9275 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9276 | |
| 9277 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9278 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9279 | } |
| 9280 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9281 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9282 | session_deps_.use_alternate_protocols = true; |
| 9283 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9284 | |
| 9285 | HttpRequestInfo request; |
| 9286 | request.method = "GET"; |
| 9287 | request.url = GURL("http://www.google.com/"); |
| 9288 | request.load_flags = 0; |
| 9289 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9290 | std::string alternate_protocol_http_header = |
| 9291 | GetAlternateProtocolHttpHeader(); |
| 9292 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9293 | MockRead data_reads[] = { |
| 9294 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9295 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9296 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9297 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9298 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9299 | }; |
| 9300 | |
| 9301 | StaticSocketDataProvider first_transaction( |
| 9302 | data_reads, arraysize(data_reads), NULL, 0); |
| 9303 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9304 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9305 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9306 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9307 | StaticSocketDataProvider hanging_socket( |
| 9308 | NULL, 0, NULL, 0); |
| 9309 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9310 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9311 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9312 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9313 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9314 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9315 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9316 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9318 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9319 | scoped_ptr<SpdyFrame> req1( |
| 9320 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9321 | scoped_ptr<SpdyFrame> req2( |
| 9322 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9323 | MockWrite spdy_writes[] = { |
| 9324 | CreateMockWrite(*req1), |
| 9325 | CreateMockWrite(*req2), |
| 9326 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9327 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9328 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9329 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9330 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9331 | MockRead spdy_reads[] = { |
| 9332 | CreateMockRead(*resp1), |
| 9333 | CreateMockRead(*data1), |
| 9334 | CreateMockRead(*resp2), |
| 9335 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9336 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9337 | }; |
| 9338 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9339 | DelayedSocketData spdy_data( |
| 9340 | 2, // wait for writes to finish before reading. |
| 9341 | spdy_reads, arraysize(spdy_reads), |
| 9342 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9343 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9344 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9345 | |
| 9346 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9347 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9348 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9349 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9350 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9351 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9353 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9354 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9355 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9356 | |
| 9357 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9358 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9359 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9360 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9361 | |
| 9362 | std::string response_data; |
| 9363 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9364 | EXPECT_EQ("hello world", response_data); |
| 9365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9366 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9367 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9368 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9371 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9372 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9373 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9374 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9375 | |
| 9376 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9377 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9378 | |
| 9379 | response = trans2.GetResponseInfo(); |
| 9380 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9381 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9382 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9383 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9384 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9385 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9386 | EXPECT_EQ("hello!", response_data); |
| 9387 | |
| 9388 | response = trans3.GetResponseInfo(); |
| 9389 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9390 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9391 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9392 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9393 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9394 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9395 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9396 | } |
| 9397 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9398 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9399 | session_deps_.use_alternate_protocols = true; |
| 9400 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9401 | |
| 9402 | HttpRequestInfo request; |
| 9403 | request.method = "GET"; |
| 9404 | request.url = GURL("http://www.google.com/"); |
| 9405 | request.load_flags = 0; |
| 9406 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9407 | std::string alternate_protocol_http_header = |
| 9408 | GetAlternateProtocolHttpHeader(); |
| 9409 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9410 | MockRead data_reads[] = { |
| 9411 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9412 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9413 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9414 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9415 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9416 | }; |
| 9417 | |
| 9418 | StaticSocketDataProvider first_transaction( |
| 9419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9420 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9421 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9422 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9423 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9424 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9425 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9426 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9427 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9428 | NULL, 0, NULL, 0); |
| 9429 | hanging_alternate_protocol_socket.set_connect_data( |
| 9430 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9431 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9432 | &hanging_alternate_protocol_socket); |
| 9433 | |
| 9434 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9435 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9437 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9438 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9439 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9440 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9445 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9446 | |
| 9447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9448 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9449 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9450 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9451 | |
| 9452 | std::string response_data; |
| 9453 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9454 | EXPECT_EQ("hello world", response_data); |
| 9455 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9456 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9458 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9459 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9460 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9461 | |
| 9462 | response = trans->GetResponseInfo(); |
| 9463 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9464 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9465 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9466 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9467 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9468 | |
| 9469 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9470 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9471 | } |
| 9472 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9473 | class CapturingProxyResolver : public ProxyResolver { |
| 9474 | public: |
| 9475 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9476 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9477 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9478 | int GetProxyForURL(const GURL& url, |
| 9479 | ProxyInfo* results, |
| 9480 | const CompletionCallback& callback, |
| 9481 | RequestHandle* request, |
| 9482 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9483 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9484 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9485 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9486 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9487 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9488 | } |
| 9489 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9490 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9491 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9492 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9493 | NOTREACHED(); |
| 9494 | return LOAD_STATE_IDLE; |
| 9495 | } |
| 9496 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9497 | void CancelSetPacScript() override { NOTREACHED(); } |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 9498 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9499 | int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
| 9500 | const CompletionCallback& /*callback*/) override { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9501 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9502 | } |
| 9503 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9504 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9505 | |
| 9506 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9507 | std::vector<GURL> resolved_; |
| 9508 | |
| 9509 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9510 | }; |
| 9511 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9512 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9513 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9514 | session_deps_.use_alternate_protocols = true; |
| 9515 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9516 | |
| 9517 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9518 | proxy_config.set_auto_detect(true); |
| 9519 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9520 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9521 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9522 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9523 | new ProxyConfigServiceFixed(proxy_config), |
| 9524 | make_scoped_ptr( |
| 9525 | new ForwardingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9526 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 9527 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9528 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9529 | |
| 9530 | HttpRequestInfo request; |
| 9531 | request.method = "GET"; |
| 9532 | request.url = GURL("http://www.google.com/"); |
| 9533 | request.load_flags = 0; |
| 9534 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9535 | std::string alternate_protocol_http_header = |
| 9536 | GetAlternateProtocolHttpHeader(); |
| 9537 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9538 | MockRead data_reads[] = { |
| 9539 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9540 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9541 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9542 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9543 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9544 | }; |
| 9545 | |
| 9546 | StaticSocketDataProvider first_transaction( |
| 9547 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9548 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9549 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9550 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9551 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9553 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9554 | scoped_ptr<SpdyFrame> req( |
| 9555 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9556 | MockWrite spdy_writes[] = { |
| 9557 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9558 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9559 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9560 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9561 | }; |
| 9562 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9563 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9564 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9565 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9566 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9567 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9568 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9569 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 9570 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9571 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9572 | }; |
| 9573 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9574 | OrderedSocketData spdy_data( |
| 9575 | spdy_reads, arraysize(spdy_reads), |
| 9576 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9577 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9578 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9579 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9580 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9581 | NULL, 0, NULL, 0); |
| 9582 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9583 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9584 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9585 | &hanging_non_alternate_protocol_socket); |
| 9586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9587 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9588 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9589 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9590 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9593 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9594 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9595 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9596 | |
| 9597 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9598 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9599 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9600 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9601 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9602 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9603 | |
| 9604 | std::string response_data; |
| 9605 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9606 | EXPECT_EQ("hello world", response_data); |
| 9607 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9608 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9610 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9612 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9613 | |
| 9614 | response = trans->GetResponseInfo(); |
| 9615 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9616 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9617 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9618 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9619 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9620 | |
| 9621 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9622 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9623 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9624 | EXPECT_EQ("http://www.google.com/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9625 | capturing_proxy_resolver.resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9626 | EXPECT_EQ("https://www.google.com/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9627 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9628 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9629 | LoadTimingInfo load_timing_info; |
| 9630 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9631 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9632 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9633 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9634 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9635 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9636 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9637 | session_deps_.use_alternate_protocols = true; |
| 9638 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9639 | |
| 9640 | HttpRequestInfo request; |
| 9641 | request.method = "GET"; |
| 9642 | request.url = GURL("http://www.google.com/"); |
| 9643 | request.load_flags = 0; |
| 9644 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9645 | std::string alternate_protocol_http_header = |
| 9646 | GetAlternateProtocolHttpHeader(); |
| 9647 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9648 | MockRead data_reads[] = { |
| 9649 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9650 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9651 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9652 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9653 | }; |
| 9654 | |
| 9655 | StaticSocketDataProvider first_transaction( |
| 9656 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9657 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9658 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9659 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9660 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9662 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9663 | scoped_ptr<SpdyFrame> req( |
| 9664 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9665 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9666 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9667 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9668 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9669 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9670 | CreateMockRead(*resp), |
| 9671 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9672 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9673 | }; |
| 9674 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9675 | DelayedSocketData spdy_data( |
| 9676 | 1, // wait for one write to finish before reading. |
| 9677 | spdy_reads, arraysize(spdy_reads), |
| 9678 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9679 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9680 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9681 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9682 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9683 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9684 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9685 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9686 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9688 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9689 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9690 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9691 | |
| 9692 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9693 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9694 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9695 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9696 | |
| 9697 | std::string response_data; |
| 9698 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9699 | EXPECT_EQ("hello world", response_data); |
| 9700 | |
| 9701 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9702 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9703 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9704 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9705 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9706 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9707 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9708 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9710 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9712 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9713 | |
| 9714 | response = trans->GetResponseInfo(); |
| 9715 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9716 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9717 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9718 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9719 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9720 | |
| 9721 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9722 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9723 | } |
| 9724 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9725 | // GenerateAuthToken is a mighty big test. |
| 9726 | // It tests all permutation of GenerateAuthToken behavior: |
| 9727 | // - Synchronous and Asynchronous completion. |
| 9728 | // - OK or error on completion. |
| 9729 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9730 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9731 | // - Non-authenticating and authenticating backend. |
| 9732 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9733 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9734 | // problems generating an auth token for an authenticating proxy, we don't |
| 9735 | // need to test all permutations of the backend server). |
| 9736 | // |
| 9737 | // The test proceeds by going over each of the configuration cases, and |
| 9738 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9739 | // specifies both the configuration for the test as well as the expectations |
| 9740 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9741 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9742 | static const char kServer[] = "http://www.example.com"; |
| 9743 | static const char kSecureServer[] = "https://www.example.com"; |
| 9744 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9745 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9746 | |
| 9747 | enum AuthTiming { |
| 9748 | AUTH_NONE, |
| 9749 | AUTH_SYNC, |
| 9750 | AUTH_ASYNC, |
| 9751 | }; |
| 9752 | |
| 9753 | const MockWrite kGet( |
| 9754 | "GET / HTTP/1.1\r\n" |
| 9755 | "Host: www.example.com\r\n" |
| 9756 | "Connection: keep-alive\r\n\r\n"); |
| 9757 | const MockWrite kGetProxy( |
| 9758 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9759 | "Host: www.example.com\r\n" |
| 9760 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9761 | const MockWrite kGetAuth( |
| 9762 | "GET / HTTP/1.1\r\n" |
| 9763 | "Host: www.example.com\r\n" |
| 9764 | "Connection: keep-alive\r\n" |
| 9765 | "Authorization: auth_token\r\n\r\n"); |
| 9766 | const MockWrite kGetProxyAuth( |
| 9767 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9768 | "Host: www.example.com\r\n" |
| 9769 | "Proxy-Connection: keep-alive\r\n" |
| 9770 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9771 | const MockWrite kGetAuthThroughProxy( |
| 9772 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9773 | "Host: www.example.com\r\n" |
| 9774 | "Proxy-Connection: keep-alive\r\n" |
| 9775 | "Authorization: auth_token\r\n\r\n"); |
| 9776 | const MockWrite kGetAuthWithProxyAuth( |
| 9777 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9778 | "Host: www.example.com\r\n" |
| 9779 | "Proxy-Connection: keep-alive\r\n" |
| 9780 | "Proxy-Authorization: auth_token\r\n" |
| 9781 | "Authorization: auth_token\r\n\r\n"); |
| 9782 | const MockWrite kConnect( |
| 9783 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9784 | "Host: www.example.com\r\n" |
| 9785 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9786 | const MockWrite kConnectProxyAuth( |
| 9787 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9788 | "Host: www.example.com\r\n" |
| 9789 | "Proxy-Connection: keep-alive\r\n" |
| 9790 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9791 | |
| 9792 | const MockRead kSuccess( |
| 9793 | "HTTP/1.1 200 OK\r\n" |
| 9794 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9795 | "Content-Length: 3\r\n\r\n" |
| 9796 | "Yes"); |
| 9797 | const MockRead kFailure( |
| 9798 | "Should not be called."); |
| 9799 | const MockRead kServerChallenge( |
| 9800 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9801 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9802 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9803 | "Content-Length: 14\r\n\r\n" |
| 9804 | "Unauthorized\r\n"); |
| 9805 | const MockRead kProxyChallenge( |
| 9806 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9807 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9808 | "Proxy-Connection: close\r\n" |
| 9809 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9810 | "Content-Length: 14\r\n\r\n" |
| 9811 | "Unauthorized\r\n"); |
| 9812 | const MockRead kProxyConnected( |
| 9813 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9814 | |
| 9815 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9816 | // no constructors, but the C++ compiler on Windows warns about |
| 9817 | // unspecified data in compound literals. So, moved to using constructors, |
| 9818 | // and TestRound's created with the default constructor should not be used. |
| 9819 | struct TestRound { |
| 9820 | TestRound() |
| 9821 | : expected_rv(ERR_UNEXPECTED), |
| 9822 | extra_write(NULL), |
| 9823 | extra_read(NULL) { |
| 9824 | } |
| 9825 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9826 | int expected_rv_arg) |
| 9827 | : write(write_arg), |
| 9828 | read(read_arg), |
| 9829 | expected_rv(expected_rv_arg), |
| 9830 | extra_write(NULL), |
| 9831 | extra_read(NULL) { |
| 9832 | } |
| 9833 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9834 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9835 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9836 | : write(write_arg), |
| 9837 | read(read_arg), |
| 9838 | expected_rv(expected_rv_arg), |
| 9839 | extra_write(extra_write_arg), |
| 9840 | extra_read(extra_read_arg) { |
| 9841 | } |
| 9842 | MockWrite write; |
| 9843 | MockRead read; |
| 9844 | int expected_rv; |
| 9845 | const MockWrite* extra_write; |
| 9846 | const MockRead* extra_read; |
| 9847 | }; |
| 9848 | |
| 9849 | static const int kNoSSL = 500; |
| 9850 | |
| 9851 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9852 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9853 | AuthTiming proxy_auth_timing; |
| 9854 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9855 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9856 | AuthTiming server_auth_timing; |
| 9857 | int server_auth_rv; |
| 9858 | int num_auth_rounds; |
| 9859 | int first_ssl_round; |
| 9860 | TestRound rounds[3]; |
| 9861 | } test_configs[] = { |
| 9862 | // Non-authenticating HTTP server with a direct connection. |
| 9863 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9864 | { TestRound(kGet, kSuccess, OK)}}, |
| 9865 | // Authenticating HTTP server with a direct connection. |
| 9866 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9867 | { TestRound(kGet, kServerChallenge, OK), |
| 9868 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9869 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9870 | { TestRound(kGet, kServerChallenge, OK), |
| 9871 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9872 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9873 | { TestRound(kGet, kServerChallenge, OK), |
| 9874 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9875 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9876 | { TestRound(kGet, kServerChallenge, OK), |
| 9877 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9878 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9879 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9880 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9881 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9882 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9883 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9884 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9885 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9886 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9887 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9888 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9889 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9890 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9891 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9892 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9893 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9894 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9895 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9896 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9897 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9898 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9899 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9900 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9901 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9902 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9903 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9904 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9905 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9906 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9907 | // Authenticating HTTP server through an authenticating proxy. |
| 9908 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9909 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9910 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9911 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9912 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9913 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9914 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9915 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9916 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9917 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9918 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9919 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9920 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9921 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9922 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9923 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9924 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9925 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9926 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9927 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9928 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9929 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9930 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9931 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9932 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9933 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9934 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9935 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9936 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9937 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9938 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9939 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9940 | // Non-authenticating HTTPS server with a direct connection. |
| 9941 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9942 | { TestRound(kGet, kSuccess, OK)}}, |
| 9943 | // Authenticating HTTPS server with a direct connection. |
| 9944 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9945 | { TestRound(kGet, kServerChallenge, OK), |
| 9946 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9947 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9948 | { TestRound(kGet, kServerChallenge, OK), |
| 9949 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9950 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9951 | { TestRound(kGet, kServerChallenge, OK), |
| 9952 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9953 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9954 | { TestRound(kGet, kServerChallenge, OK), |
| 9955 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9956 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9957 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9958 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9959 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9960 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9961 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9962 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9963 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9964 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9965 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9966 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9967 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9968 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9969 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9970 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9971 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9972 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9973 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9974 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9975 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9976 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9977 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9978 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9979 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9980 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9981 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9982 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9983 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9984 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9985 | // Authenticating HTTPS server through an authenticating proxy. |
| 9986 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9987 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9988 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9989 | &kGet, &kServerChallenge), |
| 9990 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9991 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9992 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9993 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9994 | &kGet, &kServerChallenge), |
| 9995 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9996 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9997 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9998 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9999 | &kGet, &kServerChallenge), |
| 10000 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10001 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10002 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10003 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10004 | &kGet, &kServerChallenge), |
| 10005 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10006 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10007 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10008 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10009 | &kGet, &kServerChallenge), |
| 10010 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10011 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10012 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10013 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10014 | &kGet, &kServerChallenge), |
| 10015 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10016 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10017 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10018 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10019 | &kGet, &kServerChallenge), |
| 10020 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10021 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10022 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10023 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10024 | &kGet, &kServerChallenge), |
| 10025 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10026 | }; |
| 10027 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10028 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10029 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10030 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10031 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10032 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10033 | |
| 10034 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10035 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10036 | for (int n = 0; n < 2; n++) { |
| 10037 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10038 | std::string auth_challenge = "Mock realm=proxy"; |
| 10039 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10040 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10041 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10042 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10043 | origin, BoundNetLog()); |
| 10044 | auth_handler->SetGenerateExpectation( |
| 10045 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10046 | test_config.proxy_auth_rv); |
| 10047 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10048 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10049 | } |
| 10050 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10051 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10052 | std::string auth_challenge = "Mock realm=server"; |
| 10053 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10054 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10055 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10056 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10057 | origin, BoundNetLog()); |
| 10058 | auth_handler->SetGenerateExpectation( |
| 10059 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10060 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10061 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10062 | } |
| 10063 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10064 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 10065 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10066 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10067 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10068 | } |
| 10069 | |
| 10070 | HttpRequestInfo request; |
| 10071 | request.method = "GET"; |
| 10072 | request.url = GURL(test_config.server_url); |
| 10073 | request.load_flags = 0; |
| 10074 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10075 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10076 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10077 | |
| 10078 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10079 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10080 | |
| 10081 | // Set up expected reads and writes. |
| 10082 | MockRead reads[2]; |
| 10083 | reads[0] = read_write_round.read; |
| 10084 | size_t length_reads = 1; |
| 10085 | if (read_write_round.extra_read) { |
| 10086 | reads[1] = *read_write_round.extra_read; |
| 10087 | length_reads = 2; |
| 10088 | } |
| 10089 | |
| 10090 | MockWrite writes[2]; |
| 10091 | writes[0] = read_write_round.write; |
| 10092 | size_t length_writes = 1; |
| 10093 | if (read_write_round.extra_write) { |
| 10094 | writes[1] = *read_write_round.extra_write; |
| 10095 | length_writes = 2; |
| 10096 | } |
| 10097 | StaticSocketDataProvider data_provider( |
| 10098 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10099 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10100 | |
| 10101 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10102 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10103 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10104 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10105 | &ssl_socket_data_provider); |
| 10106 | |
| 10107 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10108 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10109 | int rv; |
| 10110 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10111 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10112 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10113 | rv = trans.RestartWithAuth( |
| 10114 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10115 | } |
| 10116 | if (rv == ERR_IO_PENDING) |
| 10117 | rv = callback.WaitForResult(); |
| 10118 | |
| 10119 | // Compare results with expected data. |
| 10120 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10121 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10122 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10123 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10124 | } else { |
| 10125 | EXPECT_TRUE(response == NULL); |
| 10126 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10127 | continue; |
| 10128 | } |
| 10129 | if (round + 1 < test_config.num_auth_rounds) { |
| 10130 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10131 | } else { |
| 10132 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10133 | } |
| 10134 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10135 | } |
| 10136 | } |
| 10137 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10138 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10139 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10140 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10141 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10142 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10143 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10144 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10145 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10146 | |
| 10147 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10148 | auth_handler->set_connection_based(true); |
| 10149 | std::string auth_challenge = "Mock realm=server"; |
| 10150 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10151 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10152 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10153 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10154 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10155 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10156 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10157 | int rv = OK; |
| 10158 | const HttpResponseInfo* response = NULL; |
| 10159 | HttpRequestInfo request; |
| 10160 | request.method = "GET"; |
| 10161 | request.url = origin; |
| 10162 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10163 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10164 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10165 | |
| 10166 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10167 | // to validate that the TCP socket is not released to the pool between |
| 10168 | // each round of multi-round authentication. |
| 10169 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10170 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10171 | 50, // Max sockets for pool |
| 10172 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10173 | session_deps_.host_resolver.get(), |
| 10174 | session_deps_.socket_factory.get(), |
| 10175 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10176 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10177 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10178 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10179 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10180 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10181 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10182 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10183 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10184 | |
| 10185 | const MockWrite kGet( |
| 10186 | "GET / HTTP/1.1\r\n" |
| 10187 | "Host: www.example.com\r\n" |
| 10188 | "Connection: keep-alive\r\n\r\n"); |
| 10189 | const MockWrite kGetAuth( |
| 10190 | "GET / HTTP/1.1\r\n" |
| 10191 | "Host: www.example.com\r\n" |
| 10192 | "Connection: keep-alive\r\n" |
| 10193 | "Authorization: auth_token\r\n\r\n"); |
| 10194 | |
| 10195 | const MockRead kServerChallenge( |
| 10196 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10197 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10198 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10199 | "Content-Length: 14\r\n\r\n" |
| 10200 | "Unauthorized\r\n"); |
| 10201 | const MockRead kSuccess( |
| 10202 | "HTTP/1.1 200 OK\r\n" |
| 10203 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10204 | "Content-Length: 3\r\n\r\n" |
| 10205 | "Yes"); |
| 10206 | |
| 10207 | MockWrite writes[] = { |
| 10208 | // First round |
| 10209 | kGet, |
| 10210 | // Second round |
| 10211 | kGetAuth, |
| 10212 | // Third round |
| 10213 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10214 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10215 | kGetAuth, |
| 10216 | // Competing request |
| 10217 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10218 | }; |
| 10219 | MockRead reads[] = { |
| 10220 | // First round |
| 10221 | kServerChallenge, |
| 10222 | // Second round |
| 10223 | kServerChallenge, |
| 10224 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10225 | kServerChallenge, |
| 10226 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10227 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10228 | // Competing response |
| 10229 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10230 | }; |
| 10231 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10232 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10233 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10234 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10235 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10236 | |
| 10237 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10238 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10239 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10240 | if (rv == ERR_IO_PENDING) |
| 10241 | rv = callback.WaitForResult(); |
| 10242 | EXPECT_EQ(OK, rv); |
| 10243 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10244 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10245 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10246 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10247 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10248 | // In between rounds, another request comes in for the same domain. |
| 10249 | // It should not be able to grab the TCP socket that trans has already |
| 10250 | // claimed. |
| 10251 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10252 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10253 | TestCompletionCallback callback_compete; |
| 10254 | rv = trans_compete->Start( |
| 10255 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10257 | // callback_compete.WaitForResult at this point would stall forever, |
| 10258 | // since the HttpNetworkTransaction does not release the request back to |
| 10259 | // the pool until after authentication completes. |
| 10260 | |
| 10261 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10262 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10263 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10264 | if (rv == ERR_IO_PENDING) |
| 10265 | rv = callback.WaitForResult(); |
| 10266 | EXPECT_EQ(OK, rv); |
| 10267 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10268 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10269 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10270 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10271 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10272 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10273 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10274 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10275 | if (rv == ERR_IO_PENDING) |
| 10276 | rv = callback.WaitForResult(); |
| 10277 | EXPECT_EQ(OK, rv); |
| 10278 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10279 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10280 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10281 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10282 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10283 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10284 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10285 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10286 | if (rv == ERR_IO_PENDING) |
| 10287 | rv = callback.WaitForResult(); |
| 10288 | EXPECT_EQ(OK, rv); |
| 10289 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10290 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10291 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10292 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10293 | |
| 10294 | // Read the body since the fourth round was successful. This will also |
| 10295 | // release the socket back to the pool. |
| 10296 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10297 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10298 | if (rv == ERR_IO_PENDING) |
| 10299 | rv = callback.WaitForResult(); |
| 10300 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10301 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10302 | EXPECT_EQ(0, rv); |
| 10303 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10304 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10305 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10306 | |
| 10307 | // The competing request can now finish. Wait for the headers and then |
| 10308 | // read the body. |
| 10309 | rv = callback_compete.WaitForResult(); |
| 10310 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10311 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10312 | if (rv == ERR_IO_PENDING) |
| 10313 | rv = callback.WaitForResult(); |
| 10314 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10315 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10316 | EXPECT_EQ(0, rv); |
| 10317 | |
| 10318 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10319 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10320 | } |
| 10321 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10322 | // This tests the case that a request is issued via http instead of spdy after |
| 10323 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10324 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10325 | session_deps_.use_alternate_protocols = true; |
| 10326 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10327 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10328 | session_deps_.next_protos = next_protos; |
| 10329 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10330 | HttpRequestInfo request; |
| 10331 | request.method = "GET"; |
| 10332 | request.url = GURL("https://www.google.com/"); |
| 10333 | request.load_flags = 0; |
| 10334 | |
| 10335 | MockWrite data_writes[] = { |
| 10336 | MockWrite("GET / HTTP/1.1\r\n" |
| 10337 | "Host: www.google.com\r\n" |
| 10338 | "Connection: keep-alive\r\n\r\n"), |
| 10339 | }; |
| 10340 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10341 | std::string alternate_protocol_http_header = |
| 10342 | GetAlternateProtocolHttpHeader(); |
| 10343 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10344 | MockRead data_reads[] = { |
| 10345 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10346 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10347 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10349 | }; |
| 10350 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10351 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10352 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 10353 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 10354 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10355 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10356 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10357 | |
| 10358 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10359 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10362 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10363 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10364 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10365 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10366 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10368 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10369 | |
| 10370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10371 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10372 | |
| 10373 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10374 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10375 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10376 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10377 | |
| 10378 | std::string response_data; |
| 10379 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10380 | EXPECT_EQ("hello world", response_data); |
| 10381 | |
| 10382 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10383 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10384 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10385 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10386 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10387 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10388 | // followed by an immediate server closing of the socket. |
| 10389 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10390 | session_deps_.use_alternate_protocols = true; |
| 10391 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10392 | |
| 10393 | HttpRequestInfo request; |
| 10394 | request.method = "GET"; |
| 10395 | request.url = GURL("https://www.google.com/"); |
| 10396 | request.load_flags = 0; |
| 10397 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10398 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10399 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10400 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10401 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10402 | scoped_ptr<SpdyFrame> req( |
| 10403 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 10404 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10405 | |
| 10406 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10407 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10408 | }; |
| 10409 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10410 | DelayedSocketData spdy_data( |
| 10411 | 0, // don't wait in this case, immediate hangup. |
| 10412 | spdy_reads, arraysize(spdy_reads), |
| 10413 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10414 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10416 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10417 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10418 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10419 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10422 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10423 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10424 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10425 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10426 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10427 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10428 | // it gets it. This is needed since the auth handler may get destroyed |
| 10429 | // before we get a chance to query it. |
| 10430 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10431 | public: |
| 10432 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10433 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10434 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10435 | |
| 10436 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10437 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10438 | const HttpRequestInfo* request, |
| 10439 | const CompletionCallback& callback, |
| 10440 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10441 | *url_ = request->url; |
| 10442 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10443 | credentials, request, callback, auth_token); |
| 10444 | } |
| 10445 | |
| 10446 | private: |
| 10447 | GURL* url_; |
| 10448 | }; |
| 10449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10450 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10451 | // This test ensures that the URL passed into the proxy is upgraded |
| 10452 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10453 | session_deps_.use_alternate_protocols = true; |
| 10454 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10455 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10456 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10457 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10458 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10459 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10460 | GURL request_url; |
| 10461 | { |
| 10462 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10463 | new HttpAuthHandlerMock::Factory(); |
| 10464 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10465 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10466 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10467 | auth_factory->set_do_init_from_challenge(true); |
| 10468 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10469 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10470 | |
| 10471 | HttpRequestInfo request; |
| 10472 | request.method = "GET"; |
| 10473 | request.url = GURL("http://www.google.com"); |
| 10474 | request.load_flags = 0; |
| 10475 | |
| 10476 | // First round goes unauthenticated through the proxy. |
| 10477 | MockWrite data_writes_1[] = { |
| 10478 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10479 | "Host: www.google.com\r\n" |
| 10480 | "Proxy-Connection: keep-alive\r\n" |
| 10481 | "\r\n"), |
| 10482 | }; |
| 10483 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10484 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10485 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10486 | MockRead("Alternate-Protocol: 443:"), |
| 10487 | MockRead(GetAlternateProtocolFromParam()), |
| 10488 | MockRead("\r\n"), |
| 10489 | MockRead("Proxy-Connection: close\r\n"), |
| 10490 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10491 | }; |
| 10492 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10493 | data_writes_1, arraysize(data_writes_1)); |
| 10494 | |
| 10495 | // Second round tries to tunnel to www.google.com due to the |
| 10496 | // Alternate-Protocol announcement in the first round. It fails due |
| 10497 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10498 | // After the failure, a tunnel is established to www.google.com using |
| 10499 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10500 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10501 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10502 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10503 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10504 | // to obtain a new one. |
| 10505 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10506 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10507 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10508 | // establishment and SPDY framing issues. Alas, the |
| 10509 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10510 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10511 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10512 | scoped_ptr<SpdyFrame> req( |
| 10513 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10514 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10515 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10516 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10517 | MockWrite data_writes_2[] = { |
| 10518 | // First connection attempt without Proxy-Authorization. |
| 10519 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10520 | "Host: www.google.com\r\n" |
| 10521 | "Proxy-Connection: keep-alive\r\n" |
| 10522 | "\r\n"), |
| 10523 | |
| 10524 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10525 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10526 | "Host: www.google.com\r\n" |
| 10527 | "Proxy-Connection: keep-alive\r\n" |
| 10528 | "Proxy-Authorization: auth_token\r\n" |
| 10529 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10530 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10531 | // SPDY request |
| 10532 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10533 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10534 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10535 | "Proxy-Authenticate: Mock\r\n" |
| 10536 | "Proxy-Connection: close\r\n" |
| 10537 | "\r\n"); |
| 10538 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10539 | MockRead data_reads_2[] = { |
| 10540 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10541 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 10542 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10543 | arraysize(kRejectConnectResponse) - 1, 1), |
| 10544 | |
| 10545 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10546 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10547 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10548 | |
| 10549 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10550 | CreateMockRead(*resp.get(), 6), |
| 10551 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10552 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10553 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10554 | OrderedSocketData data_2( |
| 10555 | data_reads_2, arraysize(data_reads_2), |
| 10556 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10557 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10558 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10559 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10560 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10561 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10562 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10563 | NULL, 0, NULL, 0); |
| 10564 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10565 | never_finishing_connect); |
| 10566 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10567 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10568 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10570 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10571 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10572 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10573 | |
| 10574 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10575 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10576 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10577 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10578 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10579 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10580 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10581 | |
| 10582 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10583 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10584 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10585 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10586 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10587 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10588 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10589 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10590 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10591 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10592 | |
| 10593 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10594 | TestCompletionCallback callback_3; |
| 10595 | rv = trans_2->RestartWithAuth( |
| 10596 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10597 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10598 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10599 | |
| 10600 | // After all that work, these two lines (or actually, just the scheme) are |
| 10601 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10602 | EXPECT_EQ("https", request_url.scheme()); |
| 10603 | EXPECT_EQ("www.google.com", request_url.host()); |
| 10604 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10605 | LoadTimingInfo load_timing_info; |
| 10606 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10607 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10608 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10609 | } |
| 10610 | |
| 10611 | // Test that if we cancel the transaction as the connection is completing, that |
| 10612 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10613 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10614 | // Setup everything about the connection to complete synchronously, so that |
| 10615 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10616 | // for is the callback from the HttpStreamRequest. |
| 10617 | // Then cancel the transaction. |
| 10618 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10619 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10620 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10621 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10622 | MockRead(SYNCHRONOUS, "hello world"), |
| 10623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10624 | }; |
| 10625 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10626 | HttpRequestInfo request; |
| 10627 | request.method = "GET"; |
| 10628 | request.url = GURL("http://www.google.com/"); |
| 10629 | request.load_flags = 0; |
| 10630 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10631 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10632 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10633 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10634 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10635 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10636 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10637 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10638 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10640 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10641 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10642 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10643 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10644 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10645 | trans.reset(); // Cancel the transaction here. |
| 10646 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10647 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10648 | } |
| 10649 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10650 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10651 | // stream is drained properly and added back to the socket pool. The main |
| 10652 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10653 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10654 | // deleted. |
| 10655 | // See http://crbug.com/368418 |
| 10656 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10657 | MockRead data_reads[] = { |
| 10658 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10659 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10660 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10661 | MockRead(ASYNC, "1"), |
| 10662 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10663 | // HttpNetworkTransaction has been deleted. |
| 10664 | MockRead(ASYNC, "2"), |
| 10665 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10666 | }; |
| 10667 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10668 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10669 | |
| 10670 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10671 | |
| 10672 | { |
| 10673 | HttpRequestInfo request; |
| 10674 | request.method = "GET"; |
| 10675 | request.url = GURL("http://www.google.com/"); |
| 10676 | request.load_flags = 0; |
| 10677 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10679 | TestCompletionCallback callback; |
| 10680 | |
| 10681 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10682 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10683 | callback.WaitForResult(); |
| 10684 | |
| 10685 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10686 | ASSERT_TRUE(response != NULL); |
| 10687 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10688 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10689 | |
| 10690 | // The transaction and HttpRequestInfo are deleted. |
| 10691 | } |
| 10692 | |
| 10693 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10694 | base::MessageLoop::current()->RunUntilIdle(); |
| 10695 | |
| 10696 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10697 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10698 | } |
| 10699 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10700 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10701 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10702 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10703 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10704 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10705 | session_deps_.net_log = log.bound().net_log(); |
| 10706 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10707 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10708 | HttpRequestInfo request; |
| 10709 | request.method = "GET"; |
| 10710 | request.url = GURL("http://www.google.com/"); |
| 10711 | |
| 10712 | MockWrite data_writes1[] = { |
| 10713 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10714 | "Host: www.google.com\r\n" |
| 10715 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10716 | }; |
| 10717 | |
| 10718 | MockRead data_reads1[] = { |
| 10719 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10720 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10721 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10722 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10723 | }; |
| 10724 | |
| 10725 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10726 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10727 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10729 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10730 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10731 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10732 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10733 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10734 | trans->SetBeforeProxyHeadersSentCallback( |
| 10735 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10736 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10738 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10739 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10740 | |
| 10741 | rv = callback1.WaitForResult(); |
| 10742 | EXPECT_EQ(OK, rv); |
| 10743 | |
| 10744 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10745 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10746 | |
| 10747 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10748 | EXPECT_EQ(200, response->headers->response_code()); |
| 10749 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10750 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10751 | EXPECT_TRUE( |
| 10752 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10753 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10754 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10755 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10756 | |
| 10757 | LoadTimingInfo load_timing_info; |
| 10758 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10759 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10760 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10761 | } |
| 10762 | |
| 10763 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10764 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10765 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10766 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10767 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10768 | session_deps_.net_log = log.bound().net_log(); |
| 10769 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10770 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10771 | HttpRequestInfo request; |
| 10772 | request.method = "GET"; |
| 10773 | request.url = GURL("https://www.google.com/"); |
| 10774 | |
| 10775 | // Since we have proxy, should try to establish tunnel. |
| 10776 | MockWrite data_writes1[] = { |
| 10777 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10778 | "Host: www.google.com\r\n" |
| 10779 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10780 | |
| 10781 | MockWrite("GET / HTTP/1.1\r\n" |
| 10782 | "Host: www.google.com\r\n" |
| 10783 | "Connection: keep-alive\r\n\r\n"), |
| 10784 | }; |
| 10785 | |
| 10786 | MockRead data_reads1[] = { |
| 10787 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 10788 | |
| 10789 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10790 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10791 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10792 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10793 | }; |
| 10794 | |
| 10795 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10796 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10797 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10798 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10799 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10800 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10801 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10802 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10803 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10804 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10806 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10808 | |
| 10809 | rv = callback1.WaitForResult(); |
| 10810 | EXPECT_EQ(OK, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10811 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10812 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10813 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10814 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10815 | NetLog::PHASE_NONE); |
| 10816 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10817 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10818 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10819 | NetLog::PHASE_NONE); |
| 10820 | |
| 10821 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10822 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10823 | |
| 10824 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10825 | EXPECT_EQ(200, response->headers->response_code()); |
| 10826 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10827 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10828 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10829 | EXPECT_TRUE( |
| 10830 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10831 | |
| 10832 | LoadTimingInfo load_timing_info; |
| 10833 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10834 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10835 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10836 | } |
| 10837 | |
| 10838 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 10839 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10840 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10841 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10842 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | session_deps_.net_log = log.bound().net_log(); |
| 10844 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10845 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10846 | HttpRequestInfo request; |
| 10847 | request.method = "GET"; |
| 10848 | request.url = GURL("https://www.google.com/"); |
| 10849 | |
| 10850 | // Since we have proxy, should try to establish tunnel. |
| 10851 | MockWrite data_writes1[] = { |
| 10852 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10853 | "Host: www.google.com\r\n" |
| 10854 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10855 | |
| 10856 | MockWrite("GET / HTTP/1.1\r\n" |
| 10857 | "Host: www.google.com\r\n" |
| 10858 | "Connection: keep-alive\r\n\r\n"), |
| 10859 | }; |
| 10860 | |
| 10861 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10862 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10863 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10864 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10865 | }; |
| 10866 | |
| 10867 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10868 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10870 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10872 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10873 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10874 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10875 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10876 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10878 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10879 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10880 | |
| 10881 | rv = callback1.WaitForResult(); |
| 10882 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 10883 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10884 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10885 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10886 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10887 | NetLog::PHASE_NONE); |
| 10888 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10889 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10890 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10891 | NetLog::PHASE_NONE); |
| 10892 | } |
| 10893 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10894 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10895 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10896 | scoped_ptr<SpdyFrame> req( |
| 10897 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10898 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 10899 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10900 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10901 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10902 | MockRead spdy_reads[] = { |
| 10903 | CreateMockRead(*resp), |
| 10904 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10905 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10906 | }; |
| 10907 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10908 | DelayedSocketData spdy_data( |
| 10909 | 1, // wait for one write to finish before reading. |
| 10910 | spdy_reads, arraysize(spdy_reads), |
| 10911 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10912 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10913 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10914 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10915 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10916 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10917 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10918 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10919 | |
| 10920 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10921 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10922 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10923 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10924 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10925 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10926 | |
| 10927 | HttpRequestInfo request; |
| 10928 | request.method = "GET"; |
| 10929 | request.url = GURL("https://www.google.com/"); |
| 10930 | request.load_flags = 0; |
| 10931 | |
| 10932 | // This is the important line that marks this as a preconnect. |
| 10933 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10934 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10935 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10936 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10937 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10938 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10939 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10941 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10942 | } |
| 10943 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10944 | // Given a net error, cause that error to be returned from the first Write() |
| 10945 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10946 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10947 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10948 | net::HttpRequestInfo request_info; |
| 10949 | request_info.url = GURL("https://www.example.com/"); |
| 10950 | request_info.method = "GET"; |
| 10951 | request_info.load_flags = net::LOAD_NORMAL; |
| 10952 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10953 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10954 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10955 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10956 | }; |
| 10957 | net::StaticSocketDataProvider data(NULL, 0, |
| 10958 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10960 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10961 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10963 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10964 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10966 | TestCompletionCallback callback; |
| 10967 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10968 | if (rv == net::ERR_IO_PENDING) |
| 10969 | rv = callback.WaitForResult(); |
| 10970 | ASSERT_EQ(error, rv); |
| 10971 | } |
| 10972 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10973 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10974 | // Just check a grab bag of cert errors. |
| 10975 | static const int kErrors[] = { |
| 10976 | ERR_CERT_COMMON_NAME_INVALID, |
| 10977 | ERR_CERT_AUTHORITY_INVALID, |
| 10978 | ERR_CERT_DATE_INVALID, |
| 10979 | }; |
| 10980 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10981 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10982 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10983 | } |
| 10984 | } |
| 10985 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10986 | // Ensure that a client certificate is removed from the SSL client auth |
| 10987 | // cache when: |
| 10988 | // 1) No proxy is involved. |
| 10989 | // 2) TLS False Start is disabled. |
| 10990 | // 3) The initial TLS handshake requests a client certificate. |
| 10991 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10992 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10993 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10994 | net::HttpRequestInfo request_info; |
| 10995 | request_info.url = GURL("https://www.example.com/"); |
| 10996 | request_info.method = "GET"; |
| 10997 | request_info.load_flags = net::LOAD_NORMAL; |
| 10998 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10999 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11000 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11001 | |
| 11002 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11003 | // CertificateRequest is received for the first time, the handshake will |
| 11004 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11005 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11006 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11007 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11008 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11009 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11010 | |
| 11011 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11012 | // False Start is not being used, the result of the SSL handshake will be |
| 11013 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11014 | // matches the result of a server sending a handshake_failure alert, |
| 11015 | // rather than a Finished message, because it requires a client |
| 11016 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11017 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11018 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11019 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11020 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11021 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11022 | |
| 11023 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11024 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11025 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11026 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11027 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11028 | // requiring a client certificate, this fallback handshake should also |
| 11029 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11030 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11031 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11033 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11034 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11035 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11036 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11037 | // connection to a server fails during an SSL handshake, |
| 11038 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 11039 | // connection was attempted with TLSv1. This is transparent to the caller |
| 11040 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11041 | // requiring a client certificate, this fallback handshake should also |
| 11042 | // fail. |
| 11043 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 11044 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11046 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11047 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11048 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11049 | // Need one more if TLSv1.2 is enabled. |
| 11050 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 11051 | ssl_data5.cert_request_info = cert_request.get(); |
| 11052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 11053 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 11054 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11055 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11056 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11057 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11058 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11059 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11060 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11061 | TestCompletionCallback callback; |
| 11062 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11063 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11064 | |
| 11065 | // Complete the SSL handshake, which should abort due to requiring a |
| 11066 | // client certificate. |
| 11067 | rv = callback.WaitForResult(); |
| 11068 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 11069 | |
| 11070 | // Indicate that no certificate should be supplied. From the perspective |
| 11071 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11072 | // certificate, so this is the same as supply a |
| 11073 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11074 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11075 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11076 | |
| 11077 | // Ensure the certificate was added to the client auth cache before |
| 11078 | // allowing the connection to continue restarting. |
| 11079 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11080 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11081 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11082 | ASSERT_EQ(NULL, client_cert.get()); |
| 11083 | |
| 11084 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11085 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11086 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11087 | rv = callback.WaitForResult(); |
| 11088 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 11089 | |
| 11090 | // Ensure that the client certificate is removed from the cache on a |
| 11091 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11092 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11093 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11094 | } |
| 11095 | |
| 11096 | // Ensure that a client certificate is removed from the SSL client auth |
| 11097 | // cache when: |
| 11098 | // 1) No proxy is involved. |
| 11099 | // 2) TLS False Start is enabled. |
| 11100 | // 3) The initial TLS handshake requests a client certificate. |
| 11101 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11102 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11103 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11104 | net::HttpRequestInfo request_info; |
| 11105 | request_info.url = GURL("https://www.example.com/"); |
| 11106 | request_info.method = "GET"; |
| 11107 | request_info.load_flags = net::LOAD_NORMAL; |
| 11108 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11109 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11110 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11111 | |
| 11112 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11113 | // return successfully after reading up to the peer's Certificate message. |
| 11114 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11115 | // enqueue application data to be sent in the same packet as the |
| 11116 | // ChangeCipherSpec and Finished messages. |
| 11117 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11118 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11119 | // Finished messages. If there was an error negotiating with the peer, |
| 11120 | // such as due to the peer requiring a client certificate when none was |
| 11121 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11122 | // called. |
| 11123 | |
| 11124 | // Like the non-False Start case, when a client certificate is requested by |
| 11125 | // the peer, the handshake is aborted during the Connect() call. |
| 11126 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11127 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11128 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11130 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11131 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11132 | |
| 11133 | // When a client certificate is supplied, Connect() will not be aborted |
| 11134 | // when the peer requests the certificate. Instead, the handshake will |
| 11135 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11136 | // the socket. The handshake messages are not processed until Read() is |
| 11137 | // called, which then detects that the handshake was aborted, due to the |
| 11138 | // peer sending a handshake_failure because it requires a client |
| 11139 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11140 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11141 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11143 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11144 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11145 | }; |
| 11146 | net::StaticSocketDataProvider data2( |
| 11147 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11148 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11149 | |
| 11150 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11151 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11152 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11153 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11154 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11156 | net::StaticSocketDataProvider data3( |
| 11157 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11158 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11159 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11160 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11161 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 11162 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 11163 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11165 | net::StaticSocketDataProvider data4( |
| 11166 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11167 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11168 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11169 | // Need one more if TLSv1.2 is enabled. |
| 11170 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 11171 | ssl_data5.cert_request_info = cert_request.get(); |
| 11172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 11173 | net::StaticSocketDataProvider data5( |
| 11174 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 11175 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11176 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11177 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11178 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11179 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11180 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11181 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11182 | TestCompletionCallback callback; |
| 11183 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11184 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11185 | |
| 11186 | // Complete the SSL handshake, which should abort due to requiring a |
| 11187 | // client certificate. |
| 11188 | rv = callback.WaitForResult(); |
| 11189 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 11190 | |
| 11191 | // Indicate that no certificate should be supplied. From the perspective |
| 11192 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11193 | // certificate, so this is the same as supply a |
| 11194 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11195 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11196 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11197 | |
| 11198 | // Ensure the certificate was added to the client auth cache before |
| 11199 | // allowing the connection to continue restarting. |
| 11200 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11201 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11202 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11203 | ASSERT_EQ(NULL, client_cert.get()); |
| 11204 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11205 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11206 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11207 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11208 | rv = callback.WaitForResult(); |
| 11209 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 11210 | |
| 11211 | // Ensure that the client certificate is removed from the cache on a |
| 11212 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11213 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11214 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11215 | } |
| 11216 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11217 | // Ensure that a client certificate is removed from the SSL client auth |
| 11218 | // cache when: |
| 11219 | // 1) An HTTPS proxy is involved. |
| 11220 | // 3) The HTTPS proxy requests a client certificate. |
| 11221 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11222 | // proxy. |
| 11223 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11224 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11225 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11226 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11227 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 11228 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11229 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11230 | |
| 11231 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11232 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11233 | |
| 11234 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11235 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11236 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11237 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11238 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11239 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11241 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11243 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11244 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11245 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11247 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11248 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11249 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11250 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11251 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11252 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11253 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11255 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11256 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11257 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11258 | |
| 11259 | net::HttpRequestInfo requests[2]; |
| 11260 | requests[0].url = GURL("https://www.example.com/"); |
| 11261 | requests[0].method = "GET"; |
| 11262 | requests[0].load_flags = net::LOAD_NORMAL; |
| 11263 | |
| 11264 | requests[1].url = GURL("http://www.example.com/"); |
| 11265 | requests[1].method = "GET"; |
| 11266 | requests[1].load_flags = net::LOAD_NORMAL; |
| 11267 | |
| 11268 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11269 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 11270 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11271 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11272 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11273 | |
| 11274 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11275 | TestCompletionCallback callback; |
| 11276 | int rv = trans->Start( |
| 11277 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11278 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11279 | |
| 11280 | // Complete the SSL handshake, which should abort due to requiring a |
| 11281 | // client certificate. |
| 11282 | rv = callback.WaitForResult(); |
| 11283 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 11284 | |
| 11285 | // Indicate that no certificate should be supplied. From the perspective |
| 11286 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11287 | // certificate, so this is the same as supply a |
| 11288 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11289 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11290 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11291 | |
| 11292 | // Ensure the certificate was added to the client auth cache before |
| 11293 | // allowing the connection to continue restarting. |
| 11294 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11295 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11296 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11297 | ASSERT_EQ(NULL, client_cert.get()); |
| 11298 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11299 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11300 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11301 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11302 | |
| 11303 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11304 | // then consume ssl_data3, which should also fail. The result code is |
| 11305 | // checked against what ssl_data3 should return. |
| 11306 | rv = callback.WaitForResult(); |
| 11307 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 11308 | |
| 11309 | // Now that the new handshake has failed, ensure that the client |
| 11310 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11311 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11312 | HostPortPair("proxy", 70), &client_cert)); |
| 11313 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11314 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11315 | } |
| 11316 | } |
| 11317 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11318 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 11319 | // TEST_P is a macro that expands directly to code that stringizes the |
| 11320 | // arguments. As a result, macros passed as parameters (such as prefix |
| 11321 | // or test_case_name) will not be expanded by the preprocessor. To |
| 11322 | // work around this, indirect the macro for TEST_P, so that the |
| 11323 | // pre-processor will expand macros such as MAYBE_test_name before |
| 11324 | // instantiating the test. |
| 11325 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 11326 | TEST_P(test_case_name, test_name) |
| 11327 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11328 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11329 | #if defined(OS_WIN) |
| 11330 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 11331 | #else |
| 11332 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 11333 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11334 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11335 | session_deps_.use_alternate_protocols = true; |
| 11336 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11337 | |
| 11338 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11339 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11340 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11341 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11342 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11343 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11344 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11345 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11347 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11348 | scoped_ptr<SpdyFrame> host1_req( |
| 11349 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11350 | scoped_ptr<SpdyFrame> host2_req( |
| 11351 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11352 | MockWrite spdy_writes[] = { |
| 11353 | CreateMockWrite(*host1_req, 1), |
| 11354 | CreateMockWrite(*host2_req, 4), |
| 11355 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11356 | scoped_ptr<SpdyFrame> host1_resp( |
| 11357 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11358 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11359 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11360 | scoped_ptr<SpdyFrame> host2_resp( |
| 11361 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11362 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11363 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11364 | MockRead spdy_reads[] = { |
| 11365 | CreateMockRead(*host1_resp, 2), |
| 11366 | CreateMockRead(*host1_resp_body, 3), |
| 11367 | CreateMockRead(*host2_resp, 5), |
| 11368 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11369 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11370 | }; |
| 11371 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11372 | IPAddressNumber ip; |
| 11373 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11374 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11375 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11376 | OrderedSocketData spdy_data( |
| 11377 | connect, |
| 11378 | spdy_reads, arraysize(spdy_reads), |
| 11379 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11380 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11381 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11382 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11383 | HttpRequestInfo request1; |
| 11384 | request1.method = "GET"; |
| 11385 | request1.url = GURL("https://www.google.com/"); |
| 11386 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11387 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11389 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11390 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11391 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11392 | |
| 11393 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11394 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11395 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11396 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11397 | |
| 11398 | std::string response_data; |
| 11399 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11400 | EXPECT_EQ("hello!", response_data); |
| 11401 | |
| 11402 | // Preload www.gmail.com into HostCache. |
| 11403 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11404 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11405 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11406 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11407 | DEFAULT_PRIORITY, |
| 11408 | &ignored, |
| 11409 | callback.callback(), |
| 11410 | NULL, |
| 11411 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11412 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11413 | rv = callback.WaitForResult(); |
| 11414 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11415 | |
| 11416 | HttpRequestInfo request2; |
| 11417 | request2.method = "GET"; |
| 11418 | request2.url = GURL("https://www.gmail.com/"); |
| 11419 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11420 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11422 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11423 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11424 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11425 | |
| 11426 | response = trans2.GetResponseInfo(); |
| 11427 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11428 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11429 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11430 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11431 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11432 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11433 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11434 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11435 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11436 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11437 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11438 | session_deps_.use_alternate_protocols = true; |
| 11439 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11440 | |
| 11441 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11442 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11443 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11444 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11445 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11446 | |
| 11447 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11448 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11450 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11451 | scoped_ptr<SpdyFrame> host1_req( |
| 11452 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11453 | scoped_ptr<SpdyFrame> host2_req( |
| 11454 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11455 | MockWrite spdy_writes[] = { |
| 11456 | CreateMockWrite(*host1_req, 1), |
| 11457 | CreateMockWrite(*host2_req, 4), |
| 11458 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11459 | scoped_ptr<SpdyFrame> host1_resp( |
| 11460 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11461 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11462 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11463 | scoped_ptr<SpdyFrame> host2_resp( |
| 11464 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11465 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11466 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11467 | MockRead spdy_reads[] = { |
| 11468 | CreateMockRead(*host1_resp, 2), |
| 11469 | CreateMockRead(*host1_resp_body, 3), |
| 11470 | CreateMockRead(*host2_resp, 5), |
| 11471 | CreateMockRead(*host2_resp_body, 6), |
| 11472 | MockRead(ASYNC, 0, 7), |
| 11473 | }; |
| 11474 | |
| 11475 | IPAddressNumber ip; |
| 11476 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11477 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11478 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11479 | OrderedSocketData spdy_data( |
| 11480 | connect, |
| 11481 | spdy_reads, arraysize(spdy_reads), |
| 11482 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11483 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11484 | |
| 11485 | TestCompletionCallback callback; |
| 11486 | HttpRequestInfo request1; |
| 11487 | request1.method = "GET"; |
| 11488 | request1.url = GURL("https://www.google.com/"); |
| 11489 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11490 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11491 | |
| 11492 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11493 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11494 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11495 | |
| 11496 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11497 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11498 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11499 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11500 | |
| 11501 | std::string response_data; |
| 11502 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11503 | EXPECT_EQ("hello!", response_data); |
| 11504 | |
| 11505 | HttpRequestInfo request2; |
| 11506 | request2.method = "GET"; |
| 11507 | request2.url = GURL("https://www.gmail.com/"); |
| 11508 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11509 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11510 | |
| 11511 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11512 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11513 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11514 | |
| 11515 | response = trans2.GetResponseInfo(); |
| 11516 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11517 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11518 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11519 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11520 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11521 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11522 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11523 | } |
| 11524 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11525 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 11526 | public: |
| 11527 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11528 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11529 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11530 | |
| 11531 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11532 | |
| 11533 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11534 | int Resolve(const RequestInfo& info, |
| 11535 | RequestPriority priority, |
| 11536 | AddressList* addresses, |
| 11537 | const CompletionCallback& callback, |
| 11538 | RequestHandle* out_req, |
| 11539 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11540 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11541 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11542 | } |
| 11543 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11544 | int ResolveFromCache(const RequestInfo& info, |
| 11545 | AddressList* addresses, |
| 11546 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11547 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11548 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11549 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11550 | return rv; |
| 11551 | } |
| 11552 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11553 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11554 | host_resolver_.CancelRequest(req); |
| 11555 | } |
| 11556 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11557 | MockCachingHostResolver* GetMockHostResolver() { |
| 11558 | return &host_resolver_; |
| 11559 | } |
| 11560 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11561 | private: |
| 11562 | MockCachingHostResolver host_resolver_; |
| 11563 | const HostPortPair host_port_; |
| 11564 | }; |
| 11565 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11566 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11567 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11568 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11569 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11570 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11571 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11572 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11573 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11574 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 11575 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11576 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 11577 | // prefix doesn't work with parametrized tests). |
| 11578 | #if defined(OS_WIN) |
| 11579 | return; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11580 | #else |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11581 | session_deps_.use_alternate_protocols = true; |
| 11582 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11583 | |
| 11584 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11585 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11586 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11587 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11588 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11589 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11590 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11591 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11592 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11593 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11594 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11596 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11597 | scoped_ptr<SpdyFrame> host1_req( |
| 11598 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11599 | scoped_ptr<SpdyFrame> host2_req( |
| 11600 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11601 | MockWrite spdy_writes[] = { |
| 11602 | CreateMockWrite(*host1_req, 1), |
| 11603 | CreateMockWrite(*host2_req, 4), |
| 11604 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11605 | scoped_ptr<SpdyFrame> host1_resp( |
| 11606 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11607 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11608 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11609 | scoped_ptr<SpdyFrame> host2_resp( |
| 11610 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11611 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11612 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11613 | MockRead spdy_reads[] = { |
| 11614 | CreateMockRead(*host1_resp, 2), |
| 11615 | CreateMockRead(*host1_resp_body, 3), |
| 11616 | CreateMockRead(*host2_resp, 5), |
| 11617 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11618 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11619 | }; |
| 11620 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11621 | IPAddressNumber ip; |
| 11622 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11623 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11624 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11625 | OrderedSocketData spdy_data( |
| 11626 | connect, |
| 11627 | spdy_reads, arraysize(spdy_reads), |
| 11628 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11629 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11630 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11631 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11632 | HttpRequestInfo request1; |
| 11633 | request1.method = "GET"; |
| 11634 | request1.url = GURL("https://www.google.com/"); |
| 11635 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11636 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11638 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11640 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11641 | |
| 11642 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11643 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11644 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11645 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11646 | |
| 11647 | std::string response_data; |
| 11648 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11649 | EXPECT_EQ("hello!", response_data); |
| 11650 | |
| 11651 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11652 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11653 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11654 | rv = host_resolver.Resolve(resolve_info, |
| 11655 | DEFAULT_PRIORITY, |
| 11656 | &ignored, |
| 11657 | callback.callback(), |
| 11658 | NULL, |
| 11659 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11660 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11661 | rv = callback.WaitForResult(); |
| 11662 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11663 | |
| 11664 | HttpRequestInfo request2; |
| 11665 | request2.method = "GET"; |
| 11666 | request2.url = GURL("https://www.gmail.com/"); |
| 11667 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11668 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11670 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11671 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11672 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11673 | |
| 11674 | response = trans2.GetResponseInfo(); |
| 11675 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11676 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11677 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11678 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11679 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11680 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11681 | EXPECT_EQ("hello!", response_data); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11682 | #endif |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11683 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11684 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11685 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11686 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11687 | const std::string https_url = "https://www.google.com:8080/"; |
| 11688 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11689 | |
| 11690 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11691 | scoped_ptr<SpdyFrame> req1( |
| 11692 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11693 | |
| 11694 | MockWrite writes1[] = { |
| 11695 | CreateMockWrite(*req1, 0), |
| 11696 | }; |
| 11697 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11698 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11699 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11700 | MockRead reads1[] = { |
| 11701 | CreateMockRead(*resp1, 1), |
| 11702 | CreateMockRead(*body1, 2), |
| 11703 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11704 | }; |
| 11705 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11706 | DelayedSocketData data1( |
| 11707 | 1, reads1, arraysize(reads1), |
| 11708 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11709 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11710 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11711 | |
| 11712 | // HTTP GET for the HTTP URL |
| 11713 | MockWrite writes2[] = { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11714 | MockWrite(ASYNC, 4, |
| 11715 | "GET / HTTP/1.1\r\n" |
| 11716 | "Host: www.google.com:8080\r\n" |
| 11717 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11718 | }; |
| 11719 | |
| 11720 | MockRead reads2[] = { |
| 11721 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11722 | MockRead(ASYNC, 6, "hello"), |
| 11723 | MockRead(ASYNC, 7, OK), |
| 11724 | }; |
| 11725 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11726 | DelayedSocketData data2( |
| 11727 | 1, reads2, arraysize(reads2), |
| 11728 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11729 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11730 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11731 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11732 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11733 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11734 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11735 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11736 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11737 | |
| 11738 | // Start the first transaction to set up the SpdySession |
| 11739 | HttpRequestInfo request1; |
| 11740 | request1.method = "GET"; |
| 11741 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11742 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11743 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11744 | TestCompletionCallback callback1; |
| 11745 | EXPECT_EQ(ERR_IO_PENDING, |
| 11746 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11747 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11748 | |
| 11749 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11750 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11751 | |
| 11752 | // Now, start the HTTP request |
| 11753 | HttpRequestInfo request2; |
| 11754 | request2.method = "GET"; |
| 11755 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11756 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11757 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11758 | TestCompletionCallback callback2; |
| 11759 | EXPECT_EQ(ERR_IO_PENDING, |
| 11760 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11761 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11762 | |
| 11763 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11764 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11765 | } |
| 11766 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11767 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11768 | const std::string https_url = "https://www.google.com:8080/"; |
| 11769 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11770 | |
| 11771 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11772 | const HostPortPair host_port_pair("www.google.com", 8080); |
| 11773 | scoped_ptr<SpdyFrame> connect( |
| 11774 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11775 | scoped_ptr<SpdyFrame> req1( |
| 11776 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11777 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 11778 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11779 | |
| 11780 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11781 | SpdyHeaderBlock req2_block; |
| 11782 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11783 | req2_block[spdy_util_.GetPathKey()] = "/"; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11784 | req2_block[spdy_util_.GetHostKey()] = "www.google.com:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11785 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 11786 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11787 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11788 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11789 | |
| 11790 | MockWrite writes1[] = { |
| 11791 | CreateMockWrite(*connect, 0), |
| 11792 | CreateMockWrite(*wrapped_req1, 2), |
| 11793 | CreateMockWrite(*req2, 5), |
| 11794 | }; |
| 11795 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11796 | scoped_ptr<SpdyFrame> conn_resp( |
| 11797 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11798 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11799 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11800 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 11801 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 11802 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 11803 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 11804 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11805 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11806 | MockRead reads1[] = { |
| 11807 | CreateMockRead(*conn_resp, 1), |
| 11808 | CreateMockRead(*wrapped_resp1, 3), |
| 11809 | CreateMockRead(*wrapped_body1, 4), |
| 11810 | CreateMockRead(*resp2, 6), |
| 11811 | CreateMockRead(*body2, 7), |
| 11812 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 11813 | }; |
| 11814 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11815 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 11816 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11817 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11818 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11819 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11820 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11821 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame^] | 11822 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11823 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11824 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11825 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11826 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11827 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11828 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11829 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11830 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11831 | |
| 11832 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11833 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11834 | |
| 11835 | // Start the first transaction to set up the SpdySession |
| 11836 | HttpRequestInfo request1; |
| 11837 | request1.method = "GET"; |
| 11838 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11839 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11840 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11841 | TestCompletionCallback callback1; |
| 11842 | EXPECT_EQ(ERR_IO_PENDING, |
| 11843 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11844 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11845 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11846 | |
| 11847 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11848 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11849 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11850 | LoadTimingInfo load_timing_info1; |
| 11851 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 11852 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 11853 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11854 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11855 | // Now, start the HTTP request |
| 11856 | HttpRequestInfo request2; |
| 11857 | request2.method = "GET"; |
| 11858 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11859 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11860 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11861 | TestCompletionCallback callback2; |
| 11862 | EXPECT_EQ(ERR_IO_PENDING, |
| 11863 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11864 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11865 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11866 | |
| 11867 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11868 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11869 | |
| 11870 | LoadTimingInfo load_timing_info2; |
| 11871 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 11872 | // The established SPDY sessions is considered reused by the HTTP request. |
| 11873 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 11874 | // HTTP requests over a SPDY session should have a different connection |
| 11875 | // socket_log_id than requests over a tunnel. |
| 11876 | 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] | 11877 | } |
| 11878 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11879 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11880 | // that we do not pool other origins that resolve to the same IP when |
| 11881 | // the certificate does not match the new origin. |
| 11882 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11883 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11884 | const std::string url1 = "http://www.google.com/"; |
| 11885 | const std::string url2 = "https://mail.google.com/"; |
| 11886 | const std::string ip_addr = "1.2.3.4"; |
| 11887 | |
| 11888 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11889 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11890 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11891 | scoped_ptr<SpdyFrame> req1( |
| 11892 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11893 | |
| 11894 | MockWrite writes1[] = { |
| 11895 | CreateMockWrite(*req1, 0), |
| 11896 | }; |
| 11897 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11898 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11899 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11900 | MockRead reads1[] = { |
| 11901 | CreateMockRead(*resp1, 1), |
| 11902 | CreateMockRead(*body1, 2), |
| 11903 | MockRead(ASYNC, OK, 3) // EOF |
| 11904 | }; |
| 11905 | |
| 11906 | scoped_ptr<DeterministicSocketData> data1( |
| 11907 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11908 | writes1, arraysize(writes1))); |
| 11909 | IPAddressNumber ip; |
| 11910 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11911 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11912 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11913 | data1->set_connect_data(connect_data1); |
| 11914 | |
| 11915 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11916 | scoped_ptr<SpdyFrame> req2( |
| 11917 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11918 | |
| 11919 | MockWrite writes2[] = { |
| 11920 | CreateMockWrite(*req2, 0), |
| 11921 | }; |
| 11922 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11923 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11924 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11925 | MockRead reads2[] = { |
| 11926 | CreateMockRead(*resp2, 1), |
| 11927 | CreateMockRead(*body2, 2), |
| 11928 | MockRead(ASYNC, OK, 3) // EOF |
| 11929 | }; |
| 11930 | |
| 11931 | scoped_ptr<DeterministicSocketData> data2( |
| 11932 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11933 | writes2, arraysize(writes2))); |
| 11934 | MockConnect connect_data2(ASYNC, OK); |
| 11935 | data2->set_connect_data(connect_data2); |
| 11936 | |
| 11937 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11938 | // all others direct. |
| 11939 | ProxyConfig proxy_config; |
| 11940 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11941 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11942 | new ProxyConfigServiceFixed(proxy_config), nullptr, NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11943 | |
| 11944 | // Load a valid cert. Note, that this does not need to |
| 11945 | // be valid for proxy because the MockSSLClientSocket does |
| 11946 | // not actually verify it. But SpdySession will use this |
| 11947 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11948 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11949 | scoped_refptr<X509Certificate> server_cert( |
| 11950 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11951 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11952 | |
| 11953 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11954 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11955 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11956 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11957 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11958 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11959 | |
| 11960 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11961 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11962 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11963 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11964 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11965 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11966 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11967 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11968 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11969 | |
| 11970 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11971 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11972 | |
| 11973 | // Start the first transaction to set up the SpdySession |
| 11974 | HttpRequestInfo request1; |
| 11975 | request1.method = "GET"; |
| 11976 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11977 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11978 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11979 | TestCompletionCallback callback1; |
| 11980 | ASSERT_EQ(ERR_IO_PENDING, |
| 11981 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11982 | data1->RunFor(3); |
| 11983 | |
| 11984 | ASSERT_TRUE(callback1.have_result()); |
| 11985 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11986 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11987 | |
| 11988 | // Now, start the HTTP request |
| 11989 | HttpRequestInfo request2; |
| 11990 | request2.method = "GET"; |
| 11991 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11992 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11993 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11994 | TestCompletionCallback callback2; |
| 11995 | EXPECT_EQ(ERR_IO_PENDING, |
| 11996 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11997 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11998 | data2->RunFor(3); |
| 11999 | |
| 12000 | ASSERT_TRUE(callback2.have_result()); |
| 12001 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12002 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12003 | } |
| 12004 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12005 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12006 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12007 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12008 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12009 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12010 | const std::string https_url = "https://www.google.com/"; |
| 12011 | |
| 12012 | MockRead reads1[] = { |
| 12013 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12014 | }; |
| 12015 | |
| 12016 | scoped_ptr<DeterministicSocketData> data1( |
| 12017 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 12018 | data1->SetStop(1); |
| 12019 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12020 | scoped_ptr<SpdyFrame> req2( |
| 12021 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12022 | MockWrite writes2[] = { |
| 12023 | CreateMockWrite(*req2, 0), |
| 12024 | }; |
| 12025 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12026 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12027 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12028 | MockRead reads2[] = { |
| 12029 | CreateMockRead(*resp2, 1), |
| 12030 | CreateMockRead(*body2, 2), |
| 12031 | MockRead(ASYNC, OK, 3) // EOF |
| 12032 | }; |
| 12033 | |
| 12034 | scoped_ptr<DeterministicSocketData> data2( |
| 12035 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12036 | writes2, arraysize(writes2))); |
| 12037 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12038 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12039 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12040 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12041 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12042 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12043 | |
| 12044 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12045 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12046 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12047 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12048 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12049 | |
| 12050 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12051 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12052 | |
| 12053 | // Start the first transaction to set up the SpdySession and verify that |
| 12054 | // connection was closed. |
| 12055 | HttpRequestInfo request1; |
| 12056 | request1.method = "GET"; |
| 12057 | request1.url = GURL(https_url); |
| 12058 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12059 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12060 | TestCompletionCallback callback1; |
| 12061 | EXPECT_EQ(ERR_IO_PENDING, |
| 12062 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12063 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12064 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12065 | |
| 12066 | // Now, start the second request and make sure it succeeds. |
| 12067 | HttpRequestInfo request2; |
| 12068 | request2.method = "GET"; |
| 12069 | request2.url = GURL(https_url); |
| 12070 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12071 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12072 | TestCompletionCallback callback2; |
| 12073 | EXPECT_EQ(ERR_IO_PENDING, |
| 12074 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12075 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12076 | data2->RunFor(3); |
| 12077 | |
| 12078 | ASSERT_TRUE(callback2.have_result()); |
| 12079 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12080 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12081 | } |
| 12082 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12083 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12084 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12085 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12086 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12087 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12088 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12089 | |
| 12090 | // Use two different hosts with different IPs so they don't get pooled. |
| 12091 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12092 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 12093 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12094 | |
| 12095 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12096 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12097 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12098 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12101 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12102 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12103 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12104 | MockWrite spdy1_writes[] = { |
| 12105 | CreateMockWrite(*host1_req, 1), |
| 12106 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12107 | scoped_ptr<SpdyFrame> host1_resp( |
| 12108 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12109 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12110 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12111 | MockRead spdy1_reads[] = { |
| 12112 | CreateMockRead(*host1_resp, 2), |
| 12113 | CreateMockRead(*host1_resp_body, 3), |
| 12114 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 12115 | }; |
| 12116 | |
| 12117 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 12118 | new OrderedSocketData( |
| 12119 | spdy1_reads, arraysize(spdy1_reads), |
| 12120 | spdy1_writes, arraysize(spdy1_writes))); |
| 12121 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12122 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12123 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12124 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12125 | MockWrite spdy2_writes[] = { |
| 12126 | CreateMockWrite(*host2_req, 1), |
| 12127 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12128 | scoped_ptr<SpdyFrame> host2_resp( |
| 12129 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12130 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12131 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12132 | MockRead spdy2_reads[] = { |
| 12133 | CreateMockRead(*host2_resp, 2), |
| 12134 | CreateMockRead(*host2_resp_body, 3), |
| 12135 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 12136 | }; |
| 12137 | |
| 12138 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 12139 | new OrderedSocketData( |
| 12140 | spdy2_reads, arraysize(spdy2_reads), |
| 12141 | spdy2_writes, arraysize(spdy2_writes))); |
| 12142 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12143 | |
| 12144 | MockWrite http_write[] = { |
| 12145 | MockWrite("GET / HTTP/1.1\r\n" |
| 12146 | "Host: www.a.com\r\n" |
| 12147 | "Connection: keep-alive\r\n\r\n"), |
| 12148 | }; |
| 12149 | |
| 12150 | MockRead http_read[] = { |
| 12151 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12152 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12153 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12154 | MockRead("hello!"), |
| 12155 | }; |
| 12156 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12157 | http_write, arraysize(http_write)); |
| 12158 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12159 | |
| 12160 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12161 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12162 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12163 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12164 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12165 | |
| 12166 | TestCompletionCallback callback; |
| 12167 | HttpRequestInfo request1; |
| 12168 | request1.method = "GET"; |
| 12169 | request1.url = GURL("https://www.a.com/"); |
| 12170 | request1.load_flags = 0; |
| 12171 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12172 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12173 | |
| 12174 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 12175 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12176 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12177 | |
| 12178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12179 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12180 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12181 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12182 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12183 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12184 | |
| 12185 | std::string response_data; |
| 12186 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12187 | EXPECT_EQ("hello!", response_data); |
| 12188 | trans.reset(); |
| 12189 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12190 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12191 | |
| 12192 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12193 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12194 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12195 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12196 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12197 | HttpRequestInfo request2; |
| 12198 | request2.method = "GET"; |
| 12199 | request2.url = GURL("https://www.b.com/"); |
| 12200 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12201 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12202 | |
| 12203 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 12204 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12205 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12206 | |
| 12207 | response = trans->GetResponseInfo(); |
| 12208 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12209 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12210 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12211 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12212 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12213 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12214 | EXPECT_EQ("hello!", response_data); |
| 12215 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12216 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12217 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12218 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12219 | |
| 12220 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12221 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12222 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12223 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12224 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12225 | HttpRequestInfo request3; |
| 12226 | request3.method = "GET"; |
| 12227 | request3.url = GURL("http://www.a.com/"); |
| 12228 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12229 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12230 | |
| 12231 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 12232 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12233 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12234 | |
| 12235 | response = trans->GetResponseInfo(); |
| 12236 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12237 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12238 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12239 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12240 | EXPECT_FALSE(response->was_npn_negotiated); |
| 12241 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12242 | EXPECT_EQ("hello!", response_data); |
| 12243 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12244 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12245 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12246 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12247 | } |
| 12248 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12249 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 12250 | HttpRequestInfo request; |
| 12251 | request.method = "GET"; |
| 12252 | request.url = GURL("http://www.google.com/"); |
| 12253 | request.load_flags = 0; |
| 12254 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12255 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12256 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12257 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12258 | |
| 12259 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 12260 | StaticSocketDataProvider data; |
| 12261 | data.set_connect_data(mock_connect); |
| 12262 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12263 | |
| 12264 | TestCompletionCallback callback; |
| 12265 | |
| 12266 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12267 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12268 | |
| 12269 | rv = callback.WaitForResult(); |
| 12270 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12271 | |
| 12272 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12273 | |
| 12274 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12275 | HttpRequestHeaders request_headers; |
| 12276 | trans->GetFullRequestHeaders(&request_headers); |
| 12277 | } |
| 12278 | |
| 12279 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 12280 | HttpRequestInfo request; |
| 12281 | request.method = "GET"; |
| 12282 | request.url = GURL("http://www.google.com/"); |
| 12283 | request.load_flags = 0; |
| 12284 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12285 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12286 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12287 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12288 | |
| 12289 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12290 | StaticSocketDataProvider data; |
| 12291 | data.set_connect_data(mock_connect); |
| 12292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12293 | |
| 12294 | TestCompletionCallback callback; |
| 12295 | |
| 12296 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12297 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12298 | |
| 12299 | rv = callback.WaitForResult(); |
| 12300 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12301 | |
| 12302 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12303 | |
| 12304 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12305 | HttpRequestHeaders request_headers; |
| 12306 | trans->GetFullRequestHeaders(&request_headers); |
| 12307 | } |
| 12308 | |
| 12309 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12310 | HttpRequestInfo request; |
| 12311 | request.method = "GET"; |
| 12312 | request.url = GURL("http://www.google.com/"); |
| 12313 | request.load_flags = 0; |
| 12314 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12315 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12316 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12317 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12318 | |
| 12319 | MockWrite data_writes[] = { |
| 12320 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12321 | }; |
| 12322 | MockRead data_reads[] = { |
| 12323 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12324 | }; |
| 12325 | |
| 12326 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12327 | data_writes, arraysize(data_writes)); |
| 12328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12329 | |
| 12330 | TestCompletionCallback callback; |
| 12331 | |
| 12332 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12333 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12334 | |
| 12335 | rv = callback.WaitForResult(); |
| 12336 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12337 | |
| 12338 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12339 | |
| 12340 | HttpRequestHeaders request_headers; |
| 12341 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12342 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12343 | } |
| 12344 | |
| 12345 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12346 | HttpRequestInfo request; |
| 12347 | request.method = "GET"; |
| 12348 | request.url = GURL("http://www.google.com/"); |
| 12349 | request.load_flags = 0; |
| 12350 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12351 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12352 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12353 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12354 | |
| 12355 | MockWrite data_writes[] = { |
| 12356 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12357 | }; |
| 12358 | MockRead data_reads[] = { |
| 12359 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12360 | }; |
| 12361 | |
| 12362 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12363 | data_writes, arraysize(data_writes)); |
| 12364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12365 | |
| 12366 | TestCompletionCallback callback; |
| 12367 | |
| 12368 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12370 | |
| 12371 | rv = callback.WaitForResult(); |
| 12372 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12373 | |
| 12374 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12375 | |
| 12376 | HttpRequestHeaders request_headers; |
| 12377 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12378 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12379 | } |
| 12380 | |
| 12381 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12382 | HttpRequestInfo request; |
| 12383 | request.method = "GET"; |
| 12384 | request.url = GURL("http://www.google.com/"); |
| 12385 | request.load_flags = 0; |
| 12386 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12387 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12388 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12389 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12390 | |
| 12391 | MockWrite data_writes[] = { |
| 12392 | MockWrite("GET / HTTP/1.1\r\n" |
| 12393 | "Host: www.google.com\r\n" |
| 12394 | "Connection: keep-alive\r\n\r\n"), |
| 12395 | }; |
| 12396 | MockRead data_reads[] = { |
| 12397 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12398 | }; |
| 12399 | |
| 12400 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12401 | data_writes, arraysize(data_writes)); |
| 12402 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12403 | |
| 12404 | TestCompletionCallback callback; |
| 12405 | |
| 12406 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12407 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12408 | |
| 12409 | rv = callback.WaitForResult(); |
| 12410 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12411 | |
| 12412 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12413 | |
| 12414 | HttpRequestHeaders request_headers; |
| 12415 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12416 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12417 | } |
| 12418 | |
| 12419 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 12420 | HttpRequestInfo request; |
| 12421 | request.method = "GET"; |
| 12422 | request.url = GURL("http://www.google.com/"); |
| 12423 | request.load_flags = 0; |
| 12424 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12425 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12426 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12427 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12428 | |
| 12429 | MockWrite data_writes[] = { |
| 12430 | MockWrite("GET / HTTP/1.1\r\n" |
| 12431 | "Host: www.google.com\r\n" |
| 12432 | "Connection: keep-alive\r\n\r\n"), |
| 12433 | }; |
| 12434 | MockRead data_reads[] = { |
| 12435 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 12436 | }; |
| 12437 | |
| 12438 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12439 | data_writes, arraysize(data_writes)); |
| 12440 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12441 | |
| 12442 | TestCompletionCallback callback; |
| 12443 | |
| 12444 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12446 | |
| 12447 | rv = callback.WaitForResult(); |
| 12448 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12449 | |
| 12450 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12451 | |
| 12452 | HttpRequestHeaders request_headers; |
| 12453 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12454 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12455 | } |
| 12456 | |
| 12457 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 12458 | HttpRequestInfo request; |
| 12459 | request.method = "GET"; |
| 12460 | request.url = GURL("http://www.google.com/"); |
| 12461 | request.load_flags = 0; |
| 12462 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 12463 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12464 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12465 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12466 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12467 | |
| 12468 | MockWrite data_writes[] = { |
| 12469 | MockWrite("GET / HTTP/1.1\r\n" |
| 12470 | "Host: www.google.com\r\n" |
| 12471 | "Connection: keep-alive\r\n" |
| 12472 | "X-Foo: bar\r\n\r\n"), |
| 12473 | }; |
| 12474 | MockRead data_reads[] = { |
| 12475 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12476 | "Content-Length: 5\r\n\r\n" |
| 12477 | "hello"), |
| 12478 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 12479 | }; |
| 12480 | |
| 12481 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12482 | data_writes, arraysize(data_writes)); |
| 12483 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12484 | |
| 12485 | TestCompletionCallback callback; |
| 12486 | |
| 12487 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12488 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12489 | |
| 12490 | rv = callback.WaitForResult(); |
| 12491 | EXPECT_EQ(OK, rv); |
| 12492 | |
| 12493 | HttpRequestHeaders request_headers; |
| 12494 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12495 | std::string foo; |
| 12496 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 12497 | EXPECT_EQ("bar", foo); |
| 12498 | } |
| 12499 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12500 | namespace { |
| 12501 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12502 | // Fake HttpStream that simply records calls to SetPriority(). |
| 12503 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12504 | public base::SupportsWeakPtr<FakeStream> { |
| 12505 | public: |
| 12506 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12507 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12508 | |
| 12509 | RequestPriority priority() const { return priority_; } |
| 12510 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12511 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12512 | RequestPriority priority, |
| 12513 | const BoundNetLog& net_log, |
| 12514 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12515 | return ERR_IO_PENDING; |
| 12516 | } |
| 12517 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12518 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12519 | HttpResponseInfo* response, |
| 12520 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12521 | ADD_FAILURE(); |
| 12522 | return ERR_UNEXPECTED; |
| 12523 | } |
| 12524 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12525 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12526 | ADD_FAILURE(); |
| 12527 | return ERR_UNEXPECTED; |
| 12528 | } |
| 12529 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12530 | int ReadResponseBody(IOBuffer* buf, |
| 12531 | int buf_len, |
| 12532 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12533 | ADD_FAILURE(); |
| 12534 | return ERR_UNEXPECTED; |
| 12535 | } |
| 12536 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12537 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12538 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12539 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12540 | ADD_FAILURE(); |
| 12541 | return false; |
| 12542 | } |
| 12543 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12544 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12545 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12546 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12547 | ADD_FAILURE(); |
| 12548 | return false; |
| 12549 | } |
| 12550 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12551 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12552 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12553 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12554 | ADD_FAILURE(); |
| 12555 | return false; |
| 12556 | } |
| 12557 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12558 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 12559 | ADD_FAILURE(); |
| 12560 | return 0; |
| 12561 | } |
| 12562 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12563 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12564 | ADD_FAILURE(); |
| 12565 | return false; |
| 12566 | } |
| 12567 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12568 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 12569 | |
| 12570 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12571 | ADD_FAILURE(); |
| 12572 | } |
| 12573 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12574 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12575 | ADD_FAILURE(); |
| 12576 | return false; |
| 12577 | } |
| 12578 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12579 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12580 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12581 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12582 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12583 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 12584 | |
| 12585 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 12586 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12587 | private: |
| 12588 | RequestPriority priority_; |
| 12589 | |
| 12590 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 12591 | }; |
| 12592 | |
| 12593 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 12594 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12595 | class FakeStreamRequest : public HttpStreamRequest, |
| 12596 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 12597 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12598 | FakeStreamRequest(RequestPriority priority, |
| 12599 | HttpStreamRequest::Delegate* delegate) |
| 12600 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12601 | delegate_(delegate), |
| 12602 | websocket_stream_create_helper_(NULL) {} |
| 12603 | |
| 12604 | FakeStreamRequest(RequestPriority priority, |
| 12605 | HttpStreamRequest::Delegate* delegate, |
| 12606 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 12607 | : priority_(priority), |
| 12608 | delegate_(delegate), |
| 12609 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12610 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12611 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12612 | |
| 12613 | RequestPriority priority() const { return priority_; } |
| 12614 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12615 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 12616 | websocket_stream_create_helper() const { |
| 12617 | return websocket_stream_create_helper_; |
| 12618 | } |
| 12619 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12620 | // Create a new FakeStream and pass it to the request's |
| 12621 | // delegate. Returns a weak pointer to the FakeStream. |
| 12622 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 12623 | FakeStream* fake_stream = new FakeStream(priority_); |
| 12624 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 12625 | // immediately delete |fake_stream|. |
| 12626 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 12627 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 12628 | return weak_stream; |
| 12629 | } |
| 12630 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12631 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12632 | ADD_FAILURE(); |
| 12633 | return ERR_UNEXPECTED; |
| 12634 | } |
| 12635 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12636 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12637 | ADD_FAILURE(); |
| 12638 | return LoadState(); |
| 12639 | } |
| 12640 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12641 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12642 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12643 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12644 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12645 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12646 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12647 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12648 | |
| 12649 | private: |
| 12650 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12651 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12652 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12653 | |
| 12654 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 12655 | }; |
| 12656 | |
| 12657 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 12658 | class FakeStreamFactory : public HttpStreamFactory { |
| 12659 | public: |
| 12660 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12661 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12662 | |
| 12663 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 12664 | // RequestStream() (which may be NULL if it was destroyed already). |
| 12665 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 12666 | return last_stream_request_; |
| 12667 | } |
| 12668 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12669 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 12670 | RequestPriority priority, |
| 12671 | const SSLConfig& server_ssl_config, |
| 12672 | const SSLConfig& proxy_ssl_config, |
| 12673 | HttpStreamRequest::Delegate* delegate, |
| 12674 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12675 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12676 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12677 | return fake_request; |
| 12678 | } |
| 12679 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12680 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12681 | const HttpRequestInfo& info, |
| 12682 | RequestPriority priority, |
| 12683 | const SSLConfig& server_ssl_config, |
| 12684 | const SSLConfig& proxy_ssl_config, |
| 12685 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 12686 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12687 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12688 | FakeStreamRequest* fake_request = |
| 12689 | new FakeStreamRequest(priority, delegate, create_helper); |
| 12690 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12691 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12692 | } |
| 12693 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12694 | void PreconnectStreams(int num_streams, |
| 12695 | const HttpRequestInfo& info, |
| 12696 | RequestPriority priority, |
| 12697 | const SSLConfig& server_ssl_config, |
| 12698 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12699 | ADD_FAILURE(); |
| 12700 | } |
| 12701 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12702 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12703 | ADD_FAILURE(); |
| 12704 | return NULL; |
| 12705 | } |
| 12706 | |
| 12707 | private: |
| 12708 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 12709 | |
| 12710 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 12711 | }; |
| 12712 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12713 | // TODO(ricea): Maybe unify this with the one in |
| 12714 | // url_request_http_job_unittest.cc ? |
| 12715 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 12716 | public: |
| 12717 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 12718 | bool using_proxy) |
| 12719 | : state_(connection.release(), using_proxy) {} |
| 12720 | |
| 12721 | // Fake implementation of HttpStreamBase methods. |
| 12722 | // This ends up being quite "real" because this object has to really send data |
| 12723 | // on the mock socket. It might be easier to use the real implementation, but |
| 12724 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 12725 | // difficult. |
| 12726 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12727 | RequestPriority priority, |
| 12728 | const BoundNetLog& net_log, |
| 12729 | const CompletionCallback& callback) override { |
| 12730 | state_.Initialize(request_info, priority, net_log, callback); |
| 12731 | return OK; |
| 12732 | } |
| 12733 | |
| 12734 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12735 | HttpResponseInfo* response, |
| 12736 | const CompletionCallback& callback) override { |
| 12737 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 12738 | response, callback); |
| 12739 | } |
| 12740 | |
| 12741 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 12742 | return parser()->ReadResponseHeaders(callback); |
| 12743 | } |
| 12744 | |
| 12745 | int ReadResponseBody(IOBuffer* buf, |
| 12746 | int buf_len, |
| 12747 | const CompletionCallback& callback) override { |
| 12748 | NOTREACHED(); |
| 12749 | return ERR_IO_PENDING; |
| 12750 | } |
| 12751 | |
| 12752 | void Close(bool not_reusable) override { |
| 12753 | if (parser()) |
| 12754 | parser()->Close(true); |
| 12755 | } |
| 12756 | |
| 12757 | bool IsResponseBodyComplete() const override { |
| 12758 | NOTREACHED(); |
| 12759 | return false; |
| 12760 | } |
| 12761 | |
| 12762 | bool CanFindEndOfResponse() const override { |
| 12763 | return parser()->CanFindEndOfResponse(); |
| 12764 | } |
| 12765 | |
| 12766 | bool IsConnectionReused() const override { |
| 12767 | NOTREACHED(); |
| 12768 | return false; |
| 12769 | } |
| 12770 | void SetConnectionReused() override { NOTREACHED(); } |
| 12771 | |
| 12772 | bool IsConnectionReusable() const override { |
| 12773 | NOTREACHED(); |
| 12774 | return false; |
| 12775 | } |
| 12776 | |
| 12777 | int64 GetTotalReceivedBytes() const override { |
| 12778 | NOTREACHED(); |
| 12779 | return 0; |
| 12780 | } |
| 12781 | |
| 12782 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 12783 | NOTREACHED(); |
| 12784 | return false; |
| 12785 | } |
| 12786 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 12787 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12788 | |
| 12789 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 12790 | NOTREACHED(); |
| 12791 | } |
| 12792 | |
| 12793 | bool IsSpdyHttpStream() const override { |
| 12794 | NOTREACHED(); |
| 12795 | return false; |
| 12796 | } |
| 12797 | |
| 12798 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 12799 | |
| 12800 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 12801 | |
| 12802 | UploadProgress GetUploadProgress() const override { |
| 12803 | NOTREACHED(); |
| 12804 | return UploadProgress(); |
| 12805 | } |
| 12806 | |
| 12807 | HttpStream* RenewStreamForAuth() override { |
| 12808 | NOTREACHED(); |
| 12809 | return nullptr; |
| 12810 | } |
| 12811 | |
| 12812 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 12813 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 12814 | NOTREACHED(); |
| 12815 | return scoped_ptr<WebSocketStream>(); |
| 12816 | } |
| 12817 | |
| 12818 | private: |
| 12819 | HttpStreamParser* parser() const { return state_.parser(); } |
| 12820 | HttpBasicState state_; |
| 12821 | |
| 12822 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 12823 | }; |
| 12824 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12825 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 12826 | // worth doing. |
| 12827 | class FakeWebSocketStreamCreateHelper : |
| 12828 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 12829 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12830 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 12831 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12832 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12833 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 12834 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12835 | } |
| 12836 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12837 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12838 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12839 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12840 | NOTREACHED(); |
| 12841 | return NULL; |
| 12842 | }; |
| 12843 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12844 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12845 | |
| 12846 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 12847 | NOTREACHED(); |
| 12848 | return scoped_ptr<WebSocketStream>(); |
| 12849 | } |
| 12850 | }; |
| 12851 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12852 | } // namespace |
| 12853 | |
| 12854 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 12855 | // stream request on start. |
| 12856 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 12857 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12858 | HttpNetworkSessionPeer peer(session); |
| 12859 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12860 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12861 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12862 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12863 | |
| 12864 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 12865 | |
| 12866 | HttpRequestInfo request; |
| 12867 | TestCompletionCallback callback; |
| 12868 | EXPECT_EQ(ERR_IO_PENDING, |
| 12869 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12870 | |
| 12871 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12872 | fake_factory->last_stream_request(); |
| 12873 | ASSERT_TRUE(fake_request != NULL); |
| 12874 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12875 | } |
| 12876 | |
| 12877 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12878 | // updates to its stream request. |
| 12879 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 12880 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12881 | HttpNetworkSessionPeer peer(session); |
| 12882 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12883 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12884 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12885 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12886 | |
| 12887 | HttpRequestInfo request; |
| 12888 | TestCompletionCallback callback; |
| 12889 | EXPECT_EQ(ERR_IO_PENDING, |
| 12890 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12891 | |
| 12892 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12893 | fake_factory->last_stream_request(); |
| 12894 | ASSERT_TRUE(fake_request != NULL); |
| 12895 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12896 | |
| 12897 | trans.SetPriority(LOWEST); |
| 12898 | ASSERT_TRUE(fake_request != NULL); |
| 12899 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 12900 | } |
| 12901 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12902 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12903 | // updates to its stream. |
| 12904 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 12905 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12906 | HttpNetworkSessionPeer peer(session); |
| 12907 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12908 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12909 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12910 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12911 | |
| 12912 | HttpRequestInfo request; |
| 12913 | TestCompletionCallback callback; |
| 12914 | EXPECT_EQ(ERR_IO_PENDING, |
| 12915 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12916 | |
| 12917 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12918 | fake_factory->last_stream_request(); |
| 12919 | ASSERT_TRUE(fake_request != NULL); |
| 12920 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 12921 | ASSERT_TRUE(fake_stream != NULL); |
| 12922 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 12923 | |
| 12924 | trans.SetPriority(LOWEST); |
| 12925 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 12926 | } |
| 12927 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12928 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 12929 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 12930 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 12931 | // that the different schemes work. |
| 12932 | std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"}; |
| 12933 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 12934 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12935 | HttpNetworkSessionPeer peer(session); |
| 12936 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12937 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 12938 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12939 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 12940 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12941 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12942 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 12943 | &websocket_stream_create_helper); |
| 12944 | |
| 12945 | HttpRequestInfo request; |
| 12946 | TestCompletionCallback callback; |
| 12947 | request.method = "GET"; |
| 12948 | request.url = GURL(test_cases[i]); |
| 12949 | |
| 12950 | EXPECT_EQ(ERR_IO_PENDING, |
| 12951 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12952 | |
| 12953 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12954 | fake_factory->last_stream_request(); |
| 12955 | ASSERT_TRUE(fake_request != NULL); |
| 12956 | EXPECT_EQ(&websocket_stream_create_helper, |
| 12957 | fake_request->websocket_stream_create_helper()); |
| 12958 | } |
| 12959 | } |
| 12960 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12961 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 12962 | // if the transport socket pool is stalled on the global socket limit. |
| 12963 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 12964 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12965 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12966 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12967 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12968 | |
| 12969 | // Set up SSL request. |
| 12970 | |
| 12971 | HttpRequestInfo ssl_request; |
| 12972 | ssl_request.method = "GET"; |
| 12973 | ssl_request.url = GURL("https://www.google.com/"); |
| 12974 | |
| 12975 | MockWrite ssl_writes[] = { |
| 12976 | MockWrite("GET / HTTP/1.1\r\n" |
| 12977 | "Host: www.google.com\r\n" |
| 12978 | "Connection: keep-alive\r\n\r\n"), |
| 12979 | }; |
| 12980 | MockRead ssl_reads[] = { |
| 12981 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12982 | MockRead("Content-Length: 11\r\n\r\n"), |
| 12983 | MockRead("hello world"), |
| 12984 | MockRead(SYNCHRONOUS, OK), |
| 12985 | }; |
| 12986 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 12987 | ssl_writes, arraysize(ssl_writes)); |
| 12988 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12989 | |
| 12990 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12992 | |
| 12993 | // Set up HTTP request. |
| 12994 | |
| 12995 | HttpRequestInfo http_request; |
| 12996 | http_request.method = "GET"; |
| 12997 | http_request.url = GURL("http://www.google.com/"); |
| 12998 | |
| 12999 | MockWrite http_writes[] = { |
| 13000 | MockWrite("GET / HTTP/1.1\r\n" |
| 13001 | "Host: www.google.com\r\n" |
| 13002 | "Connection: keep-alive\r\n\r\n"), |
| 13003 | }; |
| 13004 | MockRead http_reads[] = { |
| 13005 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13006 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13007 | MockRead("falafel"), |
| 13008 | MockRead(SYNCHRONOUS, OK), |
| 13009 | }; |
| 13010 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13011 | http_writes, arraysize(http_writes)); |
| 13012 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13013 | |
| 13014 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13015 | |
| 13016 | // Start the SSL request. |
| 13017 | TestCompletionCallback ssl_callback; |
| 13018 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13020 | ASSERT_EQ(ERR_IO_PENDING, |
| 13021 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13022 | BoundNetLog())); |
| 13023 | |
| 13024 | // Start the HTTP request. Pool should stall. |
| 13025 | TestCompletionCallback http_callback; |
| 13026 | scoped_ptr<HttpTransaction> http_trans( |
| 13027 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13028 | ASSERT_EQ(ERR_IO_PENDING, |
| 13029 | http_trans->Start(&http_request, http_callback.callback(), |
| 13030 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13031 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13032 | |
| 13033 | // Wait for response from SSL request. |
| 13034 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13035 | std::string response_data; |
| 13036 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13037 | EXPECT_EQ("hello world", response_data); |
| 13038 | |
| 13039 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13040 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13041 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13042 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13043 | |
| 13044 | // The HTTP request can now complete. |
| 13045 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13046 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13047 | EXPECT_EQ("falafel", response_data); |
| 13048 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13049 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13050 | } |
| 13051 | |
| 13052 | // Tests that when a SSL connection is established but there's no corresponding |
| 13053 | // request that needs it, the new socket is closed if the transport socket pool |
| 13054 | // is stalled on the global socket limit. |
| 13055 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13056 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13057 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13058 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13059 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13060 | |
| 13061 | // Set up an ssl request. |
| 13062 | |
| 13063 | HttpRequestInfo ssl_request; |
| 13064 | ssl_request.method = "GET"; |
| 13065 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13066 | |
| 13067 | // No data will be sent on the SSL socket. |
| 13068 | StaticSocketDataProvider ssl_data; |
| 13069 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13070 | |
| 13071 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13073 | |
| 13074 | // Set up HTTP request. |
| 13075 | |
| 13076 | HttpRequestInfo http_request; |
| 13077 | http_request.method = "GET"; |
| 13078 | http_request.url = GURL("http://www.google.com/"); |
| 13079 | |
| 13080 | MockWrite http_writes[] = { |
| 13081 | MockWrite("GET / HTTP/1.1\r\n" |
| 13082 | "Host: www.google.com\r\n" |
| 13083 | "Connection: keep-alive\r\n\r\n"), |
| 13084 | }; |
| 13085 | MockRead http_reads[] = { |
| 13086 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13087 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13088 | MockRead("falafel"), |
| 13089 | MockRead(SYNCHRONOUS, OK), |
| 13090 | }; |
| 13091 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13092 | http_writes, arraysize(http_writes)); |
| 13093 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13094 | |
| 13095 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13096 | |
| 13097 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13098 | // cancelled when a normal transaction is cancelled. |
| 13099 | net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13100 | net::SSLConfig ssl_config; |
| 13101 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 13102 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 13103 | ssl_config, ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13104 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13105 | |
| 13106 | // Start the HTTP request. Pool should stall. |
| 13107 | TestCompletionCallback http_callback; |
| 13108 | scoped_ptr<HttpTransaction> http_trans( |
| 13109 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13110 | ASSERT_EQ(ERR_IO_PENDING, |
| 13111 | http_trans->Start(&http_request, http_callback.callback(), |
| 13112 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13113 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13114 | |
| 13115 | // The SSL connection will automatically be closed once the connection is |
| 13116 | // established, to let the HTTP request start. |
| 13117 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13118 | std::string response_data; |
| 13119 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13120 | EXPECT_EQ("falafel", response_data); |
| 13121 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13122 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13123 | } |
| 13124 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13125 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13126 | ScopedVector<UploadElementReader> element_readers; |
| 13127 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13128 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13129 | |
| 13130 | HttpRequestInfo request; |
| 13131 | request.method = "POST"; |
| 13132 | request.url = GURL("http://www.foo.com/"); |
| 13133 | request.upload_data_stream = &upload_data_stream; |
| 13134 | request.load_flags = 0; |
| 13135 | |
| 13136 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13137 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13138 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13139 | // Send headers successfully, but get an error while sending the body. |
| 13140 | MockWrite data_writes[] = { |
| 13141 | MockWrite("POST / HTTP/1.1\r\n" |
| 13142 | "Host: www.foo.com\r\n" |
| 13143 | "Connection: keep-alive\r\n" |
| 13144 | "Content-Length: 3\r\n\r\n"), |
| 13145 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13146 | }; |
| 13147 | |
| 13148 | MockRead data_reads[] = { |
| 13149 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13150 | MockRead("hello world"), |
| 13151 | MockRead(SYNCHRONOUS, OK), |
| 13152 | }; |
| 13153 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13154 | arraysize(data_writes)); |
| 13155 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13156 | |
| 13157 | TestCompletionCallback callback; |
| 13158 | |
| 13159 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13161 | |
| 13162 | rv = callback.WaitForResult(); |
| 13163 | EXPECT_EQ(OK, rv); |
| 13164 | |
| 13165 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13166 | ASSERT_TRUE(response != NULL); |
| 13167 | |
| 13168 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13169 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13170 | |
| 13171 | std::string response_data; |
| 13172 | rv = ReadTransaction(trans.get(), &response_data); |
| 13173 | EXPECT_EQ(OK, rv); |
| 13174 | EXPECT_EQ("hello world", response_data); |
| 13175 | } |
| 13176 | |
| 13177 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 13178 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 13179 | TEST_P(HttpNetworkTransactionTest, |
| 13180 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 13181 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13182 | MockWrite data_writes[] = { |
| 13183 | MockWrite("GET / HTTP/1.1\r\n" |
| 13184 | "Host: www.foo.com\r\n" |
| 13185 | "Connection: keep-alive\r\n\r\n"), |
| 13186 | MockWrite("POST / HTTP/1.1\r\n" |
| 13187 | "Host: www.foo.com\r\n" |
| 13188 | "Connection: keep-alive\r\n" |
| 13189 | "Content-Length: 3\r\n\r\n"), |
| 13190 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13191 | }; |
| 13192 | |
| 13193 | MockRead data_reads[] = { |
| 13194 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 13195 | "Content-Length: 14\r\n\r\n"), |
| 13196 | MockRead("first response"), |
| 13197 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 13198 | "Content-Length: 15\r\n\r\n"), |
| 13199 | MockRead("second response"), |
| 13200 | MockRead(SYNCHRONOUS, OK), |
| 13201 | }; |
| 13202 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13203 | arraysize(data_writes)); |
| 13204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13205 | |
| 13206 | TestCompletionCallback callback; |
| 13207 | HttpRequestInfo request1; |
| 13208 | request1.method = "GET"; |
| 13209 | request1.url = GURL("http://www.foo.com/"); |
| 13210 | request1.load_flags = 0; |
| 13211 | |
| 13212 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13213 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13214 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 13215 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13216 | |
| 13217 | rv = callback.WaitForResult(); |
| 13218 | EXPECT_EQ(OK, rv); |
| 13219 | |
| 13220 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13221 | ASSERT_TRUE(response1 != NULL); |
| 13222 | |
| 13223 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 13224 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 13225 | |
| 13226 | std::string response_data1; |
| 13227 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 13228 | EXPECT_EQ(OK, rv); |
| 13229 | EXPECT_EQ("first response", response_data1); |
| 13230 | // Delete the transaction to release the socket back into the socket pool. |
| 13231 | trans1.reset(); |
| 13232 | |
| 13233 | ScopedVector<UploadElementReader> element_readers; |
| 13234 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13235 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13236 | |
| 13237 | HttpRequestInfo request2; |
| 13238 | request2.method = "POST"; |
| 13239 | request2.url = GURL("http://www.foo.com/"); |
| 13240 | request2.upload_data_stream = &upload_data_stream; |
| 13241 | request2.load_flags = 0; |
| 13242 | |
| 13243 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13244 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13245 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 13246 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13247 | |
| 13248 | rv = callback.WaitForResult(); |
| 13249 | EXPECT_EQ(OK, rv); |
| 13250 | |
| 13251 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 13252 | ASSERT_TRUE(response2 != NULL); |
| 13253 | |
| 13254 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 13255 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 13256 | |
| 13257 | std::string response_data2; |
| 13258 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 13259 | EXPECT_EQ(OK, rv); |
| 13260 | EXPECT_EQ("second response", response_data2); |
| 13261 | } |
| 13262 | |
| 13263 | TEST_P(HttpNetworkTransactionTest, |
| 13264 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 13265 | ScopedVector<UploadElementReader> element_readers; |
| 13266 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13267 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13268 | |
| 13269 | HttpRequestInfo request; |
| 13270 | request.method = "POST"; |
| 13271 | request.url = GURL("http://www.foo.com/"); |
| 13272 | request.upload_data_stream = &upload_data_stream; |
| 13273 | request.load_flags = 0; |
| 13274 | |
| 13275 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13276 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13278 | // Send headers successfully, but get an error while sending the body. |
| 13279 | MockWrite data_writes[] = { |
| 13280 | MockWrite("POST / HTTP/1.1\r\n" |
| 13281 | "Host: www.foo.com\r\n" |
| 13282 | "Connection: keep-alive\r\n" |
| 13283 | "Content-Length: 3\r\n\r\n" |
| 13284 | "fo"), |
| 13285 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13286 | }; |
| 13287 | |
| 13288 | MockRead data_reads[] = { |
| 13289 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13290 | MockRead("hello world"), |
| 13291 | MockRead(SYNCHRONOUS, OK), |
| 13292 | }; |
| 13293 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13294 | arraysize(data_writes)); |
| 13295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13296 | |
| 13297 | TestCompletionCallback callback; |
| 13298 | |
| 13299 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13300 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13301 | |
| 13302 | rv = callback.WaitForResult(); |
| 13303 | EXPECT_EQ(OK, rv); |
| 13304 | |
| 13305 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13306 | ASSERT_TRUE(response != NULL); |
| 13307 | |
| 13308 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13309 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13310 | |
| 13311 | std::string response_data; |
| 13312 | rv = ReadTransaction(trans.get(), &response_data); |
| 13313 | EXPECT_EQ(OK, rv); |
| 13314 | EXPECT_EQ("hello world", response_data); |
| 13315 | } |
| 13316 | |
| 13317 | // This tests the more common case than the previous test, where headers and |
| 13318 | // body are not merged into a single request. |
| 13319 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 13320 | ScopedVector<UploadElementReader> element_readers; |
| 13321 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13322 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13323 | |
| 13324 | HttpRequestInfo request; |
| 13325 | request.method = "POST"; |
| 13326 | request.url = GURL("http://www.foo.com/"); |
| 13327 | request.upload_data_stream = &upload_data_stream; |
| 13328 | request.load_flags = 0; |
| 13329 | |
| 13330 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13331 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13333 | // Send headers successfully, but get an error while sending the body. |
| 13334 | MockWrite data_writes[] = { |
| 13335 | MockWrite("POST / HTTP/1.1\r\n" |
| 13336 | "Host: www.foo.com\r\n" |
| 13337 | "Connection: keep-alive\r\n" |
| 13338 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 13339 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13340 | }; |
| 13341 | |
| 13342 | MockRead data_reads[] = { |
| 13343 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13344 | MockRead("hello world"), |
| 13345 | MockRead(SYNCHRONOUS, OK), |
| 13346 | }; |
| 13347 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13348 | arraysize(data_writes)); |
| 13349 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13350 | |
| 13351 | TestCompletionCallback callback; |
| 13352 | |
| 13353 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13354 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13355 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 13356 | // they can't be merged with the body in a single send. Not currently |
| 13357 | // necessary since a chunked body is never merged with headers, but this makes |
| 13358 | // the test more future proof. |
| 13359 | base::RunLoop().RunUntilIdle(); |
| 13360 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13361 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13362 | |
| 13363 | rv = callback.WaitForResult(); |
| 13364 | EXPECT_EQ(OK, rv); |
| 13365 | |
| 13366 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13367 | ASSERT_TRUE(response != NULL); |
| 13368 | |
| 13369 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13370 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13371 | |
| 13372 | std::string response_data; |
| 13373 | rv = ReadTransaction(trans.get(), &response_data); |
| 13374 | EXPECT_EQ(OK, rv); |
| 13375 | EXPECT_EQ("hello world", response_data); |
| 13376 | } |
| 13377 | |
| 13378 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 13379 | ScopedVector<UploadElementReader> element_readers; |
| 13380 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13381 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13382 | |
| 13383 | HttpRequestInfo request; |
| 13384 | request.method = "POST"; |
| 13385 | request.url = GURL("http://www.foo.com/"); |
| 13386 | request.upload_data_stream = &upload_data_stream; |
| 13387 | request.load_flags = 0; |
| 13388 | |
| 13389 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13390 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13391 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13392 | |
| 13393 | MockWrite data_writes[] = { |
| 13394 | MockWrite("POST / HTTP/1.1\r\n" |
| 13395 | "Host: www.foo.com\r\n" |
| 13396 | "Connection: keep-alive\r\n" |
| 13397 | "Content-Length: 3\r\n\r\n"), |
| 13398 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13399 | }; |
| 13400 | |
| 13401 | MockRead data_reads[] = { |
| 13402 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13403 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13404 | MockRead("hello world"), |
| 13405 | MockRead(SYNCHRONOUS, OK), |
| 13406 | }; |
| 13407 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13408 | arraysize(data_writes)); |
| 13409 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13410 | |
| 13411 | TestCompletionCallback callback; |
| 13412 | |
| 13413 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13414 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13415 | |
| 13416 | rv = callback.WaitForResult(); |
| 13417 | EXPECT_EQ(OK, rv); |
| 13418 | |
| 13419 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13420 | ASSERT_TRUE(response != NULL); |
| 13421 | |
| 13422 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13423 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13424 | |
| 13425 | std::string response_data; |
| 13426 | rv = ReadTransaction(trans.get(), &response_data); |
| 13427 | EXPECT_EQ(OK, rv); |
| 13428 | EXPECT_EQ("hello world", response_data); |
| 13429 | } |
| 13430 | |
| 13431 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 13432 | ScopedVector<UploadElementReader> element_readers; |
| 13433 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13434 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13435 | |
| 13436 | HttpRequestInfo request; |
| 13437 | request.method = "POST"; |
| 13438 | request.url = GURL("http://www.foo.com/"); |
| 13439 | request.upload_data_stream = &upload_data_stream; |
| 13440 | request.load_flags = 0; |
| 13441 | |
| 13442 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13443 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13444 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13445 | // Send headers successfully, but get an error while sending the body. |
| 13446 | MockWrite data_writes[] = { |
| 13447 | MockWrite("POST / HTTP/1.1\r\n" |
| 13448 | "Host: www.foo.com\r\n" |
| 13449 | "Connection: keep-alive\r\n" |
| 13450 | "Content-Length: 3\r\n\r\n"), |
| 13451 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13452 | }; |
| 13453 | |
| 13454 | MockRead data_reads[] = { |
| 13455 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 13456 | MockRead("hello world"), |
| 13457 | MockRead(SYNCHRONOUS, OK), |
| 13458 | }; |
| 13459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13460 | arraysize(data_writes)); |
| 13461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13462 | |
| 13463 | TestCompletionCallback callback; |
| 13464 | |
| 13465 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13466 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13467 | |
| 13468 | rv = callback.WaitForResult(); |
| 13469 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13470 | |
| 13471 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13472 | EXPECT_TRUE(response == NULL); |
| 13473 | } |
| 13474 | |
| 13475 | TEST_P(HttpNetworkTransactionTest, |
| 13476 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 13477 | ScopedVector<UploadElementReader> element_readers; |
| 13478 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13479 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13480 | |
| 13481 | HttpRequestInfo request; |
| 13482 | request.method = "POST"; |
| 13483 | request.url = GURL("http://www.foo.com/"); |
| 13484 | request.upload_data_stream = &upload_data_stream; |
| 13485 | request.load_flags = 0; |
| 13486 | |
| 13487 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13488 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13490 | // Send headers successfully, but get an error while sending the body. |
| 13491 | MockWrite data_writes[] = { |
| 13492 | MockWrite("POST / HTTP/1.1\r\n" |
| 13493 | "Host: www.foo.com\r\n" |
| 13494 | "Connection: keep-alive\r\n" |
| 13495 | "Content-Length: 3\r\n\r\n"), |
| 13496 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13497 | }; |
| 13498 | |
| 13499 | MockRead data_reads[] = { |
| 13500 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13501 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 13502 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 13503 | MockRead("Content-Length: 0\r\n\r\n"), |
| 13504 | MockRead(SYNCHRONOUS, OK), |
| 13505 | }; |
| 13506 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13507 | arraysize(data_writes)); |
| 13508 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13509 | |
| 13510 | TestCompletionCallback callback; |
| 13511 | |
| 13512 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13513 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13514 | |
| 13515 | rv = callback.WaitForResult(); |
| 13516 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13517 | |
| 13518 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13519 | EXPECT_TRUE(response == NULL); |
| 13520 | } |
| 13521 | |
| 13522 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 13523 | ScopedVector<UploadElementReader> element_readers; |
| 13524 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13525 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13526 | |
| 13527 | HttpRequestInfo request; |
| 13528 | request.method = "POST"; |
| 13529 | request.url = GURL("http://www.foo.com/"); |
| 13530 | request.upload_data_stream = &upload_data_stream; |
| 13531 | request.load_flags = 0; |
| 13532 | |
| 13533 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13534 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13535 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13536 | // Send headers successfully, but get an error while sending the body. |
| 13537 | MockWrite data_writes[] = { |
| 13538 | MockWrite("POST / HTTP/1.1\r\n" |
| 13539 | "Host: www.foo.com\r\n" |
| 13540 | "Connection: keep-alive\r\n" |
| 13541 | "Content-Length: 3\r\n\r\n"), |
| 13542 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13543 | }; |
| 13544 | |
| 13545 | MockRead data_reads[] = { |
| 13546 | MockRead("HTTP 0.9 rocks!"), |
| 13547 | MockRead(SYNCHRONOUS, OK), |
| 13548 | }; |
| 13549 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13550 | arraysize(data_writes)); |
| 13551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13552 | |
| 13553 | TestCompletionCallback callback; |
| 13554 | |
| 13555 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13556 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13557 | |
| 13558 | rv = callback.WaitForResult(); |
| 13559 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13560 | |
| 13561 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13562 | EXPECT_TRUE(response == NULL); |
| 13563 | } |
| 13564 | |
| 13565 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 13566 | ScopedVector<UploadElementReader> element_readers; |
| 13567 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13568 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13569 | |
| 13570 | HttpRequestInfo request; |
| 13571 | request.method = "POST"; |
| 13572 | request.url = GURL("http://www.foo.com/"); |
| 13573 | request.upload_data_stream = &upload_data_stream; |
| 13574 | request.load_flags = 0; |
| 13575 | |
| 13576 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13577 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13578 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13579 | // Send headers successfully, but get an error while sending the body. |
| 13580 | MockWrite data_writes[] = { |
| 13581 | MockWrite("POST / HTTP/1.1\r\n" |
| 13582 | "Host: www.foo.com\r\n" |
| 13583 | "Connection: keep-alive\r\n" |
| 13584 | "Content-Length: 3\r\n\r\n"), |
| 13585 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13586 | }; |
| 13587 | |
| 13588 | MockRead data_reads[] = { |
| 13589 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 13590 | MockRead(SYNCHRONOUS, OK), |
| 13591 | }; |
| 13592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13593 | arraysize(data_writes)); |
| 13594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13595 | |
| 13596 | TestCompletionCallback callback; |
| 13597 | |
| 13598 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13599 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13600 | |
| 13601 | rv = callback.WaitForResult(); |
| 13602 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13603 | |
| 13604 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13605 | EXPECT_TRUE(response == NULL); |
| 13606 | } |
| 13607 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13608 | // Verify that proxy headers are not sent to the destination server when |
| 13609 | // establishing a tunnel for a secure WebSocket connection. |
| 13610 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 13611 | HttpRequestInfo request; |
| 13612 | request.method = "GET"; |
| 13613 | request.url = GURL("wss://www.google.com/"); |
| 13614 | AddWebSocketHeaders(&request.extra_headers); |
| 13615 | |
| 13616 | // Configure against proxy server "myproxy:70". |
| 13617 | session_deps_.proxy_service.reset( |
| 13618 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 13619 | |
| 13620 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13621 | |
| 13622 | // Since a proxy is configured, try to establish a tunnel. |
| 13623 | MockWrite data_writes[] = { |
| 13624 | MockWrite( |
| 13625 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 13626 | "Host: www.google.com\r\n" |
| 13627 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13628 | |
| 13629 | // After calling trans->RestartWithAuth(), this is the request we should |
| 13630 | // be issuing -- the final header line contains the credentials. |
| 13631 | MockWrite( |
| 13632 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 13633 | "Host: www.google.com\r\n" |
| 13634 | "Proxy-Connection: keep-alive\r\n" |
| 13635 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 13636 | |
| 13637 | MockWrite( |
| 13638 | "GET / HTTP/1.1\r\n" |
| 13639 | "Host: www.google.com\r\n" |
| 13640 | "Connection: Upgrade\r\n" |
| 13641 | "Upgrade: websocket\r\n" |
| 13642 | "Origin: http://www.google.com\r\n" |
| 13643 | "Sec-WebSocket-Version: 13\r\n" |
| 13644 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 13645 | }; |
| 13646 | |
| 13647 | // The proxy responds to the connect with a 407, using a persistent |
| 13648 | // connection. |
| 13649 | MockRead data_reads[] = { |
| 13650 | // No credentials. |
| 13651 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 13652 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 13653 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 13654 | |
| 13655 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13656 | |
| 13657 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 13658 | MockRead("Upgrade: websocket\r\n"), |
| 13659 | MockRead("Connection: Upgrade\r\n"), |
| 13660 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 13661 | }; |
| 13662 | |
| 13663 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13664 | arraysize(data_writes)); |
| 13665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13666 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13668 | |
| 13669 | scoped_ptr<HttpTransaction> trans( |
| 13670 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13671 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 13672 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 13673 | &websocket_stream_create_helper); |
| 13674 | |
| 13675 | { |
| 13676 | TestCompletionCallback callback; |
| 13677 | |
| 13678 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13679 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13680 | |
| 13681 | rv = callback.WaitForResult(); |
| 13682 | EXPECT_EQ(OK, rv); |
| 13683 | } |
| 13684 | |
| 13685 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13686 | ASSERT_TRUE(response); |
| 13687 | ASSERT_TRUE(response->headers.get()); |
| 13688 | EXPECT_EQ(407, response->headers->response_code()); |
| 13689 | |
| 13690 | { |
| 13691 | TestCompletionCallback callback; |
| 13692 | |
| 13693 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 13694 | callback.callback()); |
| 13695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13696 | |
| 13697 | rv = callback.WaitForResult(); |
| 13698 | EXPECT_EQ(OK, rv); |
| 13699 | } |
| 13700 | |
| 13701 | response = trans->GetResponseInfo(); |
| 13702 | ASSERT_TRUE(response); |
| 13703 | ASSERT_TRUE(response->headers.get()); |
| 13704 | |
| 13705 | EXPECT_EQ(101, response->headers->response_code()); |
| 13706 | |
| 13707 | trans.reset(); |
| 13708 | session->CloseAllConnections(); |
| 13709 | } |
| 13710 | |
| 13711 | // Verify that proxy headers are not sent to the destination server when |
| 13712 | // establishing a tunnel for an insecure WebSocket connection. |
| 13713 | // This requires the authentication info to be injected into the auth cache |
| 13714 | // due to crbug.com/395064 |
| 13715 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 13716 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 13717 | HttpRequestInfo request; |
| 13718 | request.method = "GET"; |
| 13719 | request.url = GURL("ws://www.google.com/"); |
| 13720 | AddWebSocketHeaders(&request.extra_headers); |
| 13721 | |
| 13722 | // Configure against proxy server "myproxy:70". |
| 13723 | session_deps_.proxy_service.reset( |
| 13724 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 13725 | |
| 13726 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13727 | |
| 13728 | MockWrite data_writes[] = { |
| 13729 | // Try to establish a tunnel for the WebSocket connection, with |
| 13730 | // credentials. Because WebSockets have a separate set of socket pools, |
| 13731 | // they cannot and will not use the same TCP/IP connection as the |
| 13732 | // preflight HTTP request. |
| 13733 | MockWrite( |
| 13734 | "CONNECT www.google.com:80 HTTP/1.1\r\n" |
rch | cb934f56 | 2015-04-07 16:25:12 | [diff] [blame] | 13735 | "Host: www.google.com:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13736 | "Proxy-Connection: keep-alive\r\n" |
| 13737 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 13738 | |
| 13739 | MockWrite( |
| 13740 | "GET / HTTP/1.1\r\n" |
| 13741 | "Host: www.google.com\r\n" |
| 13742 | "Connection: Upgrade\r\n" |
| 13743 | "Upgrade: websocket\r\n" |
| 13744 | "Origin: http://www.google.com\r\n" |
| 13745 | "Sec-WebSocket-Version: 13\r\n" |
| 13746 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 13747 | }; |
| 13748 | |
| 13749 | MockRead data_reads[] = { |
| 13750 | // HTTP CONNECT with credentials. |
| 13751 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13752 | |
| 13753 | // WebSocket connection established inside tunnel. |
| 13754 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 13755 | MockRead("Upgrade: websocket\r\n"), |
| 13756 | MockRead("Connection: Upgrade\r\n"), |
| 13757 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 13758 | }; |
| 13759 | |
| 13760 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13761 | arraysize(data_writes)); |
| 13762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13763 | |
| 13764 | session->http_auth_cache()->Add( |
| 13765 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 13766 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 13767 | |
| 13768 | scoped_ptr<HttpTransaction> trans( |
| 13769 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13770 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 13771 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 13772 | &websocket_stream_create_helper); |
| 13773 | |
| 13774 | TestCompletionCallback callback; |
| 13775 | |
| 13776 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13778 | |
| 13779 | rv = callback.WaitForResult(); |
| 13780 | EXPECT_EQ(OK, rv); |
| 13781 | |
| 13782 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13783 | ASSERT_TRUE(response); |
| 13784 | ASSERT_TRUE(response->headers.get()); |
| 13785 | |
| 13786 | EXPECT_EQ(101, response->headers->response_code()); |
| 13787 | |
| 13788 | trans.reset(); |
| 13789 | session->CloseAllConnections(); |
| 13790 | } |
| 13791 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 13792 | } // namespace net |