[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" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 25 | #include "net/base/capturing_net_log.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 26 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 27 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 28 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 29 | #include "net/base/load_timing_info.h" |
| 30 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 31 | #include "net/base/net_errors.h" |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 32 | #include "net/base/net_log.h" |
| 33 | #include "net/base/net_log_unittest.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 34 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 35 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 36 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 37 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 38 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 39 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 40 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 41 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 42 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 46 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 47 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 48 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 49 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 50 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 51 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 52 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 53 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 54 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 55 | #include "net/http/http_transaction_test_util.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 56 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 57 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 58 | #include "net/proxy/proxy_resolver.h" |
| 59 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 60 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 61 | #include "net/socket/client_socket_pool_manager.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 62 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 63 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 64 | #include "net/socket/socket_test_util.h" |
| 65 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 66 | #include "net/spdy/spdy_framer.h" |
| 67 | #include "net/spdy/spdy_session.h" |
| 68 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 69 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 70 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 71 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 72 | #include "net/ssl/ssl_config_service_defaults.h" |
| 73 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 74 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 75 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 76 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 77 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 78 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 79 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 80 | using base::ASCIIToUTF16; |
| 81 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 82 | //----------------------------------------------------------------------------- |
| 83 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 84 | namespace { |
| 85 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 86 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 87 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 88 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 89 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 90 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 91 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 92 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 93 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 94 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 95 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 96 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 97 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 98 | |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 99 | int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) { |
| 100 | return session->GetTransportSocketPool( |
| 101 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 102 | } |
| 103 | |
| 104 | int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) { |
| 105 | return session->GetSSLSocketPool( |
| 106 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount(); |
| 107 | } |
| 108 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 109 | bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) { |
| 110 | return session->GetTransportSocketPool( |
| 111 | net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled(); |
| 112 | } |
| 113 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 114 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 115 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 116 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 117 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 118 | if (!params) |
| 119 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 120 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 121 | if (!params->GetList("headers", &header_list)) |
| 122 | return false; |
| 123 | std::string double_quote_headers; |
| 124 | base::JSONWriter::Write(header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 125 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 126 | return true; |
| 127 | } |
| 128 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 129 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 130 | // used. |
| 131 | void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) { |
| 132 | EXPECT_TRUE(load_timing_info.socket_reused); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 133 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 134 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 135 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 136 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 137 | |
| 138 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 139 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 140 | |
| 141 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 142 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 143 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 144 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 145 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 146 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 149 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 150 | // used. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info, |
| 152 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 153 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 154 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 155 | |
| 156 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 157 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 158 | |
| 159 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 160 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 161 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 162 | load_timing_info.send_start); |
| 163 | |
| 164 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 165 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 166 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 167 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 168 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 169 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 173 | // used. |
| 174 | void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) { |
| 175 | EXPECT_TRUE(load_timing_info.socket_reused); |
| 176 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 177 | |
| 178 | net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 179 | |
| 180 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 181 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 182 | load_timing_info.proxy_resolve_end); |
| 183 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 184 | load_timing_info.send_start); |
| 185 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 187 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 189 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 190 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 194 | // used. |
| 195 | void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info, |
| 196 | int connect_timing_flags) { |
| 197 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 198 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 199 | |
| 200 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 201 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 202 | load_timing_info.proxy_resolve_end); |
| 203 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 204 | load_timing_info.connect_timing.connect_start); |
| 205 | net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 206 | connect_timing_flags); |
| 207 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 208 | load_timing_info.send_start); |
| 209 | |
| 210 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 212 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 213 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 214 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 215 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 216 | } |
| 217 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 218 | void AddWebSocketHeaders(net::HttpRequestHeaders* headers) { |
| 219 | headers->SetHeader("Connection", "Upgrade"); |
| 220 | headers->SetHeader("Upgrade", "websocket"); |
| 221 | headers->SetHeader("Origin", "http://www.google.com"); |
| 222 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 223 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 224 | } |
| 225 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 226 | } // namespace |
| 227 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 228 | namespace net { |
| 229 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 230 | namespace { |
| 231 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 232 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 233 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 236 | } // namespace |
| 237 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 238 | class HttpNetworkTransactionTest |
| 239 | : public PlatformTest, |
| 240 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 241 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 242 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 243 | // Important to restore the per-pool limit first, since the pool limit must |
| 244 | // always be greater than group limit, and the tests reduce both limits. |
| 245 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 246 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 247 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 248 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 249 | } |
| 250 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 251 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 252 | HttpNetworkTransactionTest() |
| 253 | : spdy_util_(GetParam()), |
| 254 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 255 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 256 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 257 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 258 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 259 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 260 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 261 | struct SimpleGetHelperResult { |
| 262 | int rv; |
| 263 | std::string status_line; |
| 264 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 265 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | LoadTimingInfo load_timing_info; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 267 | }; |
| 268 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 269 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 270 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 271 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 272 | } |
| 273 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 274 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 275 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 276 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 277 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 278 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 279 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 280 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 281 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 282 | } |
| 283 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 284 | const char* GetAlternateProtocolFromParam() { |
| 285 | return |
| 286 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 287 | } |
| 288 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 289 | // This is the expected return from a current server advertising SPDY. |
| 290 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 291 | return std::string("Alternate-Protocol: 443:") + |
| 292 | GetAlternateProtocolFromParam() + "\r\n\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 295 | // Either |write_failure| specifies a write failure or |read_failure| |
| 296 | // specifies a read failure when using a reused socket. In either case, the |
| 297 | // failure should cause the network transaction to resend the request, and the |
| 298 | // other argument should be NULL. |
| 299 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 300 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 301 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 302 | // Either |write_failure| specifies a write failure or |read_failure| |
| 303 | // specifies a read failure when using a reused socket. In either case, the |
| 304 | // failure should cause the network transaction to resend the request, and the |
| 305 | // other argument should be NULL. |
| 306 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 307 | const MockRead* read_failure, |
| 308 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 309 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 310 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 311 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 312 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 313 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 314 | HttpRequestInfo request; |
| 315 | request.method = "GET"; |
| 316 | request.url = GURL("http://www.google.com/"); |
| 317 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 318 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 319 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 320 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 321 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 322 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 323 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 324 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 325 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 326 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 327 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 329 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 330 | |
[email protected] | c47c037 | 2014-03-12 23:07:02 | [diff] [blame] | 331 | EXPECT_TRUE(log.bound().IsLogging()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 332 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 333 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 334 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 335 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 336 | |
| 337 | // Even in the failure cases that use this function, connections are always |
| 338 | // successfully established before the error. |
| 339 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 340 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 341 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 342 | if (out.rv != OK) |
| 343 | return out; |
| 344 | |
| 345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 346 | // Can't use ASSERT_* inside helper functions like this, so |
| 347 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 348 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 349 | out.rv = ERR_UNEXPECTED; |
| 350 | return out; |
| 351 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 352 | out.status_line = response->headers->GetStatusLine(); |
| 353 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 354 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 355 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 356 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 357 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 358 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 359 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 360 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 361 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 362 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 363 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 364 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 365 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 366 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 367 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 368 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 369 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 370 | std::string line; |
| 371 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 372 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 373 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 374 | HttpRequestHeaders request_headers; |
| 375 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 376 | std::string value; |
| 377 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
| 378 | EXPECT_EQ("www.google.com", value); |
| 379 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 380 | EXPECT_EQ("keep-alive", value); |
| 381 | |
| 382 | std::string response_headers; |
| 383 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
| 384 | EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']", |
| 385 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 386 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 387 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 388 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 389 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 390 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 391 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 392 | size_t reads_count) { |
| 393 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 394 | StaticSocketDataProvider* data[] = { &reads }; |
| 395 | return SimpleGetHelperForData(data, 1); |
| 396 | } |
| 397 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 398 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 399 | int64 size = 0; |
| 400 | for (size_t i = 0; i < reads_count; ++i) |
| 401 | size += data_reads[i].data_len; |
| 402 | return size; |
| 403 | } |
| 404 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 405 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 406 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 407 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 408 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 409 | |
| 410 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 411 | |
| 412 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 413 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 414 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 415 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 416 | |
| 417 | // Original socket limits. Some tests set these. Safest to always restore |
| 418 | // them once each test has been run. |
| 419 | int old_max_group_sockets_; |
| 420 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 421 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 422 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 423 | INSTANTIATE_TEST_CASE_P( |
| 424 | NextProto, |
| 425 | HttpNetworkTransactionTest, |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 426 | testing::Values(kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 427 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 428 | namespace { |
| 429 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 430 | class BeforeNetworkStartHandler { |
| 431 | public: |
| 432 | explicit BeforeNetworkStartHandler(bool defer) |
| 433 | : defer_on_before_network_start_(defer), |
| 434 | observed_before_network_start_(false) {} |
| 435 | |
| 436 | void OnBeforeNetworkStart(bool* defer) { |
| 437 | *defer = defer_on_before_network_start_; |
| 438 | observed_before_network_start_ = true; |
| 439 | } |
| 440 | |
| 441 | bool observed_before_network_start() const { |
| 442 | return observed_before_network_start_; |
| 443 | } |
| 444 | |
| 445 | private: |
| 446 | const bool defer_on_before_network_start_; |
| 447 | bool observed_before_network_start_; |
| 448 | |
| 449 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 450 | }; |
| 451 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 452 | class BeforeProxyHeadersSentHandler { |
| 453 | public: |
| 454 | BeforeProxyHeadersSentHandler() |
| 455 | : observed_before_proxy_headers_sent_(false) {} |
| 456 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 457 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 458 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 459 | observed_before_proxy_headers_sent_ = true; |
| 460 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 461 | } |
| 462 | |
| 463 | bool observed_before_proxy_headers_sent() const { |
| 464 | return observed_before_proxy_headers_sent_; |
| 465 | } |
| 466 | |
| 467 | std::string observed_proxy_server_uri() const { |
| 468 | return observed_proxy_server_uri_; |
| 469 | } |
| 470 | |
| 471 | private: |
| 472 | bool observed_before_proxy_headers_sent_; |
| 473 | std::string observed_proxy_server_uri_; |
| 474 | |
| 475 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 476 | }; |
| 477 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 478 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 479 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 480 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 481 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 482 | const int sizeof_row = strlen(row); |
| 483 | const int num_rows = static_cast<int>( |
| 484 | ceil(static_cast<float>(size) / sizeof_row)); |
| 485 | const int sizeof_data = num_rows * sizeof_row; |
| 486 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 487 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 488 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 489 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 490 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 493 | // Alternative functions that eliminate randomness and dependency on the local |
| 494 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 495 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 496 | static const uint8 bytes[] = { |
| 497 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 498 | }; |
| 499 | static size_t current_byte = 0; |
| 500 | for (size_t i = 0; i < n; ++i) { |
| 501 | output[i] = bytes[current_byte++]; |
| 502 | current_byte %= arraysize(bytes); |
| 503 | } |
| 504 | } |
| 505 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 506 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 507 | static const uint8 bytes[] = { |
| 508 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 509 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 510 | }; |
| 511 | static size_t current_byte = 0; |
| 512 | for (size_t i = 0; i < n; ++i) { |
| 513 | output[i] = bytes[current_byte++]; |
| 514 | current_byte %= arraysize(bytes); |
| 515 | } |
| 516 | } |
| 517 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 518 | std::string MockGetHostName() { |
| 519 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 520 | } |
| 521 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 522 | template<typename ParentPool> |
| 523 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 524 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 525 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 526 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 527 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 528 | const std::string last_group_name_received() const { |
| 529 | return last_group_name_; |
| 530 | } |
| 531 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 532 | int RequestSocket(const std::string& group_name, |
| 533 | const void* socket_params, |
| 534 | RequestPriority priority, |
| 535 | ClientSocketHandle* handle, |
| 536 | const CompletionCallback& callback, |
| 537 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 538 | last_group_name_ = group_name; |
| 539 | return ERR_IO_PENDING; |
| 540 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 541 | void CancelRequest(const std::string& group_name, |
| 542 | ClientSocketHandle* handle) override {} |
| 543 | void ReleaseSocket(const std::string& group_name, |
| 544 | scoped_ptr<StreamSocket> socket, |
| 545 | int id) override {} |
| 546 | void CloseIdleSockets() override {} |
| 547 | int IdleSocketCount() const override { return 0; } |
| 548 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 549 | return 0; |
| 550 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 551 | LoadState GetLoadState(const std::string& group_name, |
| 552 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 553 | return LOAD_STATE_IDLE; |
| 554 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 555 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 556 | return base::TimeDelta(); |
| 557 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 558 | |
| 559 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 560 | std::string last_group_name_; |
| 561 | }; |
| 562 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 563 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 564 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 565 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 566 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 567 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 568 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 569 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 570 | CaptureGroupNameSSLSocketPool; |
| 571 | |
| 572 | template<typename ParentPool> |
| 573 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 574 | HostResolver* host_resolver, |
| 575 | CertVerifier* /* cert_verifier */) |
| 576 | : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 577 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 578 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 579 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 580 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 581 | CertVerifier* /* cert_verifier */) |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 582 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 583 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 584 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 585 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 586 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 587 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 588 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 589 | : SSLClientSocketPool(0, |
| 590 | 0, |
| 591 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 592 | cert_verifier, |
| 593 | NULL, |
| 594 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 595 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 596 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 597 | std::string(), |
| 598 | NULL, |
| 599 | NULL, |
| 600 | NULL, |
| 601 | NULL, |
| 602 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 603 | false, |
| 604 | NULL) { |
| 605 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 606 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 607 | //----------------------------------------------------------------------------- |
| 608 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 609 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 610 | // configured for common cases. |
| 611 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 612 | if (!auth_challenge) |
| 613 | return false; |
| 614 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 615 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 616 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 617 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 618 | return true; |
| 619 | } |
| 620 | |
| 621 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 622 | if (!auth_challenge) |
| 623 | return false; |
| 624 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 625 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 626 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 627 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 628 | return true; |
| 629 | } |
| 630 | |
| 631 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 632 | if (!auth_challenge) |
| 633 | return false; |
| 634 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 635 | EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString()); |
| 636 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 637 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 638 | return true; |
| 639 | } |
| 640 | |
| 641 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 642 | if (!auth_challenge) |
| 643 | return false; |
| 644 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 645 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 646 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 647 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 648 | return true; |
| 649 | } |
| 650 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 651 | } // namespace |
| 652 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 653 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 654 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 655 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 659 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 660 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 661 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 662 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 663 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 664 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 665 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 666 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 667 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 668 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 669 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 670 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 671 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 675 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 676 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 677 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 678 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 679 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 680 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 681 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 682 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 683 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 684 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 685 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 686 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 690 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 691 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 692 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 693 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 694 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 695 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 696 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 697 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 698 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 699 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 700 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 701 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 705 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 706 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 707 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 708 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 709 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 710 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 711 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 712 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 713 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 714 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 715 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 716 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | // 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] | 720 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 721 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 722 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 723 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 725 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 726 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 727 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 728 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 729 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 730 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 731 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 735 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 736 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 737 | MockRead("\n"), |
| 738 | MockRead("\n"), |
| 739 | MockRead("Q"), |
| 740 | MockRead("J"), |
| 741 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 743 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 744 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 745 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 746 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 747 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 748 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 749 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 750 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 754 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 755 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 756 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 757 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 758 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 759 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 760 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 761 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 762 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 763 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 764 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 765 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 766 | } |
| 767 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 768 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 769 | // persistent connection. The response should still terminate since a 204 |
| 770 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 771 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 772 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 773 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 774 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 775 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 776 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 777 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 778 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 779 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 780 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 781 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 782 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 783 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 784 | int64 response_size = reads_size - strlen(junk); |
| 785 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 786 | } |
| 787 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 788 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 789 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 790 | std::string final_chunk = "0\r\n\r\n"; |
| 791 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 792 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 793 | MockRead data_reads[] = { |
| 794 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 795 | MockRead("5\r\nHello\r\n"), |
| 796 | MockRead("1\r\n"), |
| 797 | MockRead(" \r\n"), |
| 798 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 799 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 800 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 801 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 802 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 803 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 804 | EXPECT_EQ(OK, out.rv); |
| 805 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 806 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 807 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 808 | int64 response_size = reads_size - extra_data.size(); |
| 809 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 810 | } |
| 811 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 812 | // Next tests deal with http://crbug.com/56344. |
| 813 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 814 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 815 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 816 | MockRead data_reads[] = { |
| 817 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 818 | MockRead("Content-Length: 10\r\n"), |
| 819 | MockRead("Content-Length: 5\r\n\r\n"), |
| 820 | }; |
| 821 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 822 | arraysize(data_reads)); |
| 823 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 824 | } |
| 825 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 826 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 827 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 828 | MockRead data_reads[] = { |
| 829 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 830 | MockRead("Content-Length: 5\r\n"), |
| 831 | MockRead("Content-Length: 5\r\n\r\n"), |
| 832 | MockRead("Hello"), |
| 833 | }; |
| 834 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 835 | arraysize(data_reads)); |
| 836 | EXPECT_EQ(OK, out.rv); |
| 837 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 838 | EXPECT_EQ("Hello", out.response_data); |
| 839 | } |
| 840 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 841 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 842 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 843 | // More than 2 dupes. |
| 844 | { |
| 845 | MockRead data_reads[] = { |
| 846 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 847 | MockRead("Content-Length: 5\r\n"), |
| 848 | MockRead("Content-Length: 5\r\n"), |
| 849 | MockRead("Content-Length: 5\r\n\r\n"), |
| 850 | MockRead("Hello"), |
| 851 | }; |
| 852 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 853 | arraysize(data_reads)); |
| 854 | EXPECT_EQ(OK, out.rv); |
| 855 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 856 | EXPECT_EQ("Hello", out.response_data); |
| 857 | } |
| 858 | // HTTP/1.0 |
| 859 | { |
| 860 | MockRead data_reads[] = { |
| 861 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 862 | MockRead("Content-Length: 5\r\n"), |
| 863 | MockRead("Content-Length: 5\r\n"), |
| 864 | MockRead("Content-Length: 5\r\n\r\n"), |
| 865 | MockRead("Hello"), |
| 866 | }; |
| 867 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 868 | arraysize(data_reads)); |
| 869 | EXPECT_EQ(OK, out.rv); |
| 870 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 871 | EXPECT_EQ("Hello", out.response_data); |
| 872 | } |
| 873 | // 2 dupes and one mismatched. |
| 874 | { |
| 875 | MockRead data_reads[] = { |
| 876 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 877 | MockRead("Content-Length: 10\r\n"), |
| 878 | MockRead("Content-Length: 10\r\n"), |
| 879 | MockRead("Content-Length: 5\r\n\r\n"), |
| 880 | }; |
| 881 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 882 | arraysize(data_reads)); |
| 883 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 884 | } |
| 885 | } |
| 886 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 887 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 888 | MultipleContentLengthHeadersTransferEncoding) { |
| 889 | MockRead data_reads[] = { |
| 890 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 891 | MockRead("Content-Length: 666\r\n"), |
| 892 | MockRead("Content-Length: 1337\r\n"), |
| 893 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 894 | MockRead("5\r\nHello\r\n"), |
| 895 | MockRead("1\r\n"), |
| 896 | MockRead(" \r\n"), |
| 897 | MockRead("5\r\nworld\r\n"), |
| 898 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 899 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 900 | }; |
| 901 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 902 | arraysize(data_reads)); |
| 903 | EXPECT_EQ(OK, out.rv); |
| 904 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 905 | EXPECT_EQ("Hello world", out.response_data); |
| 906 | } |
| 907 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 908 | // Next tests deal with http://crbug.com/98895. |
| 909 | |
| 910 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 911 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 912 | MockRead data_reads[] = { |
| 913 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 914 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 915 | MockRead("Content-Length: 5\r\n\r\n"), |
| 916 | MockRead("Hello"), |
| 917 | }; |
| 918 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 919 | arraysize(data_reads)); |
| 920 | EXPECT_EQ(OK, out.rv); |
| 921 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 922 | EXPECT_EQ("Hello", out.response_data); |
| 923 | } |
| 924 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 925 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 926 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 927 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 928 | MockRead data_reads[] = { |
| 929 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 930 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 931 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 932 | MockRead("Content-Length: 5\r\n\r\n"), |
| 933 | MockRead("Hello"), |
| 934 | }; |
| 935 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 936 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 937 | EXPECT_EQ(OK, out.rv); |
| 938 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 939 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 943 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 944 | MockRead data_reads[] = { |
| 945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 946 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 947 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 948 | MockRead("Content-Length: 5\r\n\r\n"), |
| 949 | MockRead("Hello"), |
| 950 | }; |
| 951 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 952 | arraysize(data_reads)); |
| 953 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 954 | } |
| 955 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 956 | // Checks that two identical Location headers result in no error. |
| 957 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 958 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 959 | MockRead data_reads[] = { |
| 960 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 961 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 962 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 963 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 964 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 965 | }; |
| 966 | |
| 967 | HttpRequestInfo request; |
| 968 | request.method = "GET"; |
| 969 | request.url = GURL("http://redirect.com/"); |
| 970 | request.load_flags = 0; |
| 971 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 972 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 973 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 974 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 975 | |
| 976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 977 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 979 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 981 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 983 | |
| 984 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 985 | |
| 986 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 987 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 988 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 989 | std::string url; |
| 990 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 991 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 992 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 993 | } |
| 994 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 995 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 996 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 997 | MockRead data_reads[] = { |
| 998 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 999 | MockRead("Location: http://good.com/\r\n"), |
| 1000 | MockRead("Location: http://evil.com/\r\n"), |
| 1001 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1002 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1003 | }; |
| 1004 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1005 | arraysize(data_reads)); |
| 1006 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1007 | } |
| 1008 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1009 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1010 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1011 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1012 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1013 | request.method = "HEAD"; |
| 1014 | request.url = GURL("http://www.google.com/"); |
| 1015 | request.load_flags = 0; |
| 1016 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1017 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1018 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1020 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1021 | trans->SetBeforeProxyHeadersSentCallback( |
| 1022 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1023 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1024 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1025 | MockWrite data_writes1[] = { |
| 1026 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1027 | "Host: www.google.com\r\n" |
| 1028 | "Connection: keep-alive\r\n" |
| 1029 | "Content-Length: 0\r\n\r\n"), |
| 1030 | }; |
| 1031 | MockRead data_reads1[] = { |
| 1032 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1033 | MockRead("Server: Blah\r\n"), |
| 1034 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1035 | |
| 1036 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1037 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1038 | }; |
| 1039 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1040 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1041 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1042 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1044 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1046 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1047 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1048 | |
| 1049 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1050 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1051 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1052 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1053 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1054 | |
| 1055 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1056 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1057 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1058 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1059 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1060 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1061 | |
| 1062 | std::string server_header; |
| 1063 | void* iter = NULL; |
| 1064 | bool has_server_header = response->headers->EnumerateHeader( |
| 1065 | &iter, "Server", &server_header); |
| 1066 | EXPECT_TRUE(has_server_header); |
| 1067 | EXPECT_EQ("Blah", server_header); |
| 1068 | |
| 1069 | // Reading should give EOF right away, since there is no message body |
| 1070 | // (despite non-zero content-length). |
| 1071 | std::string response_data; |
| 1072 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1073 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1074 | EXPECT_EQ("", response_data); |
| 1075 | } |
| 1076 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1077 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1078 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1079 | |
| 1080 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1081 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1082 | MockRead("hello"), |
| 1083 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1084 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1085 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1086 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1087 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1088 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1089 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1090 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1091 | "hello", "world" |
| 1092 | }; |
| 1093 | |
| 1094 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1095 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1096 | request.method = "GET"; |
| 1097 | request.url = GURL("http://www.google.com/"); |
| 1098 | request.load_flags = 0; |
| 1099 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1100 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1101 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1103 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1105 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1106 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1107 | |
| 1108 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1109 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1110 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1111 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1112 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1113 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1114 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1115 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1116 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1117 | |
| 1118 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1119 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1120 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1121 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1125 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1126 | ScopedVector<UploadElementReader> element_readers; |
| 1127 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1128 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1129 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1130 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1131 | request.method = "POST"; |
| 1132 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1133 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1134 | request.load_flags = 0; |
| 1135 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1136 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1137 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1138 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1139 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1140 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1141 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1142 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1143 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1144 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1145 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1146 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1147 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1149 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1151 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1152 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1153 | |
| 1154 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1155 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1156 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1157 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1158 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1159 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1160 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1161 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1162 | |
| 1163 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1164 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1165 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1166 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1167 | } |
| 1168 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1169 | // This test is almost the same as Ignores100 above, but the response contains |
| 1170 | // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1171 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1172 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1173 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1174 | request.method = "GET"; |
| 1175 | request.url = GURL("http://www.foo.com/"); |
| 1176 | request.load_flags = 0; |
| 1177 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1178 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1179 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1180 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1181 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1182 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1183 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1184 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1185 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1186 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1187 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1188 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1189 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1191 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1193 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1194 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1195 | |
| 1196 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1197 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1198 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1199 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1200 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1201 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1202 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1203 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1204 | |
| 1205 | std::string response_data; |
| 1206 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1207 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1208 | EXPECT_EQ("hello world", response_data); |
| 1209 | } |
| 1210 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1211 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1212 | HttpRequestInfo request; |
| 1213 | request.method = "POST"; |
| 1214 | request.url = GURL("http://www.foo.com/"); |
| 1215 | request.load_flags = 0; |
| 1216 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1217 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1218 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1219 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1220 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1221 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1222 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1223 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1224 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1225 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1226 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1228 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1230 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1232 | |
| 1233 | rv = callback.WaitForResult(); |
| 1234 | EXPECT_EQ(OK, rv); |
| 1235 | |
| 1236 | std::string response_data; |
| 1237 | rv = ReadTransaction(trans.get(), &response_data); |
| 1238 | EXPECT_EQ(OK, rv); |
| 1239 | EXPECT_EQ("", response_data); |
| 1240 | } |
| 1241 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1242 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1243 | HttpRequestInfo request; |
| 1244 | request.method = "POST"; |
| 1245 | request.url = GURL("http://www.foo.com/"); |
| 1246 | request.load_flags = 0; |
| 1247 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1248 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1249 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1250 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1251 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1252 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1253 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1254 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1255 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1256 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1258 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1260 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1261 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1262 | |
| 1263 | rv = callback.WaitForResult(); |
| 1264 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1265 | } |
| 1266 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1267 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1268 | const MockWrite* write_failure, |
| 1269 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1270 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1271 | request.method = "GET"; |
| 1272 | request.url = GURL("http://www.foo.com/"); |
| 1273 | request.load_flags = 0; |
| 1274 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1275 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1276 | session_deps_.net_log = &net_log; |
| 1277 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1278 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1279 | // Written data for successfully sending both requests. |
| 1280 | MockWrite data1_writes[] = { |
| 1281 | MockWrite("GET / HTTP/1.1\r\n" |
| 1282 | "Host: www.foo.com\r\n" |
| 1283 | "Connection: keep-alive\r\n\r\n"), |
| 1284 | MockWrite("GET / HTTP/1.1\r\n" |
| 1285 | "Host: www.foo.com\r\n" |
| 1286 | "Connection: keep-alive\r\n\r\n") |
| 1287 | }; |
| 1288 | |
| 1289 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1291 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1292 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1293 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1295 | |
| 1296 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1297 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1298 | data1_writes[1] = *write_failure; |
| 1299 | } else { |
| 1300 | ASSERT_TRUE(read_failure); |
| 1301 | data1_reads[2] = *read_failure; |
| 1302 | } |
| 1303 | |
| 1304 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1305 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1306 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | |
| 1308 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1309 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1310 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1311 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1313 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1314 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1316 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | "hello", "world" |
| 1318 | }; |
| 1319 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1320 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1322 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1324 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1325 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1327 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | |
| 1330 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1331 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1333 | LoadTimingInfo load_timing_info; |
| 1334 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1335 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1336 | if (i == 0) { |
| 1337 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1338 | } else { |
| 1339 | // The second request should be using a new socket. |
| 1340 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1341 | } |
| 1342 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1343 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1344 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1346 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1347 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | |
| 1349 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1350 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1351 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1352 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | } |
| 1354 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1355 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1356 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1357 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1358 | const MockRead* read_failure, |
| 1359 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1360 | HttpRequestInfo request; |
| 1361 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1362 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1363 | request.load_flags = 0; |
| 1364 | |
| 1365 | CapturingNetLog net_log; |
| 1366 | session_deps_.net_log = &net_log; |
| 1367 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1368 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1369 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1370 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1371 | if (use_spdy) { |
| 1372 | ssl1.SetNextProto(GetParam()); |
| 1373 | ssl2.SetNextProto(GetParam()); |
| 1374 | } |
| 1375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1377 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1378 | // SPDY versions of the request and response. |
| 1379 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1380 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1381 | scoped_ptr<SpdyFrame> spdy_response( |
| 1382 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1383 | scoped_ptr<SpdyFrame> spdy_data( |
| 1384 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1385 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1386 | // HTTP/1.1 versions of the request and response. |
| 1387 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1388 | "Host: www.foo.com\r\n" |
| 1389 | "Connection: keep-alive\r\n\r\n"; |
| 1390 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1391 | const char kHttpData[] = "hello"; |
| 1392 | |
| 1393 | std::vector<MockRead> data1_reads; |
| 1394 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1395 | if (write_failure) { |
| 1396 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1397 | data1_writes.push_back(*write_failure); |
| 1398 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1399 | } else { |
| 1400 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1401 | if (use_spdy) { |
| 1402 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1403 | } else { |
| 1404 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1405 | } |
| 1406 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1407 | } |
| 1408 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1409 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1410 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1412 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1413 | std::vector<MockRead> data2_reads; |
| 1414 | std::vector<MockWrite> data2_writes; |
| 1415 | |
| 1416 | if (use_spdy) { |
| 1417 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1418 | |
| 1419 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1420 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1421 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1422 | } else { |
| 1423 | data2_writes.push_back( |
| 1424 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1425 | |
| 1426 | data2_reads.push_back( |
| 1427 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1428 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1429 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1430 | } |
| 1431 | OrderedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1432 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1433 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1434 | |
| 1435 | // Preconnect a socket. |
| 1436 | net::SSLConfig ssl_config; |
| 1437 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1438 | session->GetNextProtos(&ssl_config.next_protos); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1439 | session->http_stream_factory()->PreconnectStreams( |
| 1440 | 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config); |
| 1441 | // Wait for the preconnect to complete. |
| 1442 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1443 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1444 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1445 | |
| 1446 | // Make the request. |
| 1447 | TestCompletionCallback callback; |
| 1448 | |
| 1449 | scoped_ptr<HttpTransaction> trans( |
| 1450 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1451 | |
| 1452 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1453 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1454 | |
| 1455 | rv = callback.WaitForResult(); |
| 1456 | EXPECT_EQ(OK, rv); |
| 1457 | |
| 1458 | LoadTimingInfo load_timing_info; |
| 1459 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1460 | TestLoadTimingNotReused( |
| 1461 | load_timing_info, |
| 1462 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1463 | |
| 1464 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1465 | ASSERT_TRUE(response != NULL); |
| 1466 | |
| 1467 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1468 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1469 | |
| 1470 | std::string response_data; |
| 1471 | rv = ReadTransaction(trans.get(), &response_data); |
| 1472 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1473 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1474 | } |
| 1475 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1476 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1477 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1478 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1479 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1480 | } |
| 1481 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1482 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1483 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1484 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1487 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1488 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1489 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1490 | } |
| 1491 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1492 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1493 | // if the socket was a reused keep alive socket. |
| 1494 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1495 | MockRead read_failure(SYNCHRONOUS, |
| 1496 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1497 | "Connection: Keep-Alive\r\n" |
| 1498 | "Content-Length: 6\r\n\r\n" |
| 1499 | "Pickle"); |
| 1500 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1501 | } |
| 1502 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1503 | TEST_P(HttpNetworkTransactionTest, |
| 1504 | PreconnectErrorNotConnectedOnWrite) { |
| 1505 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1506 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1510 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1511 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1515 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1516 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1517 | } |
| 1518 | |
| 1519 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1520 | MockRead read_failure(ASYNC, OK); // EOF |
| 1521 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1522 | } |
| 1523 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1524 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1525 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1526 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1527 | MockRead read_failure(SYNCHRONOUS, |
| 1528 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1529 | "Connection: Keep-Alive\r\n" |
| 1530 | "Content-Length: 6\r\n\r\n" |
| 1531 | "Pickle"); |
| 1532 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1533 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1534 | } |
| 1535 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1536 | TEST_P(HttpNetworkTransactionTest, |
| 1537 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1538 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1539 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1540 | } |
| 1541 | |
| 1542 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1543 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1544 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1545 | } |
| 1546 | |
| 1547 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1548 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1549 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1550 | } |
| 1551 | |
| 1552 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1553 | MockRead read_failure(ASYNC, OK); // EOF |
| 1554 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1555 | } |
| 1556 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1557 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1558 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1559 | request.method = "GET"; |
| 1560 | request.url = GURL("http://www.google.com/"); |
| 1561 | request.load_flags = 0; |
| 1562 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1563 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1564 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1565 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1566 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1567 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1568 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1569 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1570 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1571 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1572 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1573 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1574 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1576 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1577 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1578 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1579 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1580 | |
| 1581 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1582 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1583 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1584 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1585 | EXPECT_TRUE(response == NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | // What do various browsers do when the server closes a non-keepalive |
| 1589 | // connection without sending any response header or body? |
| 1590 | // |
| 1591 | // IE7: error page |
| 1592 | // Safari 3.1.2 (Windows): error page |
| 1593 | // Firefox 3.0.1: blank page |
| 1594 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1595 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1596 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1597 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1598 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1599 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1600 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1601 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1602 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1603 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1604 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1605 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1606 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1607 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1608 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1609 | // Test that network access can be deferred and resumed. |
| 1610 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1611 | HttpRequestInfo request; |
| 1612 | request.method = "GET"; |
| 1613 | request.url = GURL("http://www.google.com/"); |
| 1614 | request.load_flags = 0; |
| 1615 | |
| 1616 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1617 | scoped_ptr<HttpTransaction> trans( |
| 1618 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1619 | |
| 1620 | // Defer on OnBeforeNetworkStart. |
| 1621 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1622 | trans->SetBeforeNetworkStartCallback( |
| 1623 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1624 | base::Unretained(&net_start_handler))); |
| 1625 | |
| 1626 | MockRead data_reads[] = { |
| 1627 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1628 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1629 | MockRead("hello"), |
| 1630 | MockRead(SYNCHRONOUS, 0), |
| 1631 | }; |
| 1632 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1633 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1634 | |
| 1635 | TestCompletionCallback callback; |
| 1636 | |
| 1637 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1638 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1639 | base::MessageLoop::current()->RunUntilIdle(); |
| 1640 | |
| 1641 | // Should have deferred for network start. |
| 1642 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1643 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1644 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1645 | |
| 1646 | trans->ResumeNetworkStart(); |
| 1647 | rv = callback.WaitForResult(); |
| 1648 | EXPECT_EQ(OK, rv); |
| 1649 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1650 | |
| 1651 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1652 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1653 | if (rv == ERR_IO_PENDING) |
| 1654 | rv = callback.WaitForResult(); |
| 1655 | EXPECT_EQ(5, rv); |
| 1656 | trans.reset(); |
| 1657 | } |
| 1658 | |
| 1659 | // Test that network use can be deferred and canceled. |
| 1660 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1661 | HttpRequestInfo request; |
| 1662 | request.method = "GET"; |
| 1663 | request.url = GURL("http://www.google.com/"); |
| 1664 | request.load_flags = 0; |
| 1665 | |
| 1666 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1667 | scoped_ptr<HttpTransaction> trans( |
| 1668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1669 | |
| 1670 | // Defer on OnBeforeNetworkStart. |
| 1671 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1672 | trans->SetBeforeNetworkStartCallback( |
| 1673 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1674 | base::Unretained(&net_start_handler))); |
| 1675 | |
| 1676 | TestCompletionCallback callback; |
| 1677 | |
| 1678 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1679 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1680 | base::MessageLoop::current()->RunUntilIdle(); |
| 1681 | |
| 1682 | // Should have deferred for network start. |
| 1683 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1684 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
| 1685 | EXPECT_TRUE(trans->GetResponseInfo() == NULL); |
| 1686 | } |
| 1687 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1688 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1689 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1690 | // destructor in such situations. |
| 1691 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1692 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1693 | HttpRequestInfo request; |
| 1694 | request.method = "GET"; |
| 1695 | request.url = GURL("http://www.google.com/"); |
| 1696 | request.load_flags = 0; |
| 1697 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1698 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1699 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1700 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1701 | |
| 1702 | MockRead data_reads[] = { |
| 1703 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1704 | MockRead("Connection: keep-alive\r\n"), |
| 1705 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1706 | MockRead("hello"), |
| 1707 | MockRead(SYNCHRONOUS, 0), |
| 1708 | }; |
| 1709 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1710 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1711 | |
| 1712 | TestCompletionCallback callback; |
| 1713 | |
| 1714 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1715 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1716 | |
| 1717 | rv = callback.WaitForResult(); |
| 1718 | EXPECT_EQ(OK, rv); |
| 1719 | |
| 1720 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1721 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1722 | if (rv == ERR_IO_PENDING) |
| 1723 | rv = callback.WaitForResult(); |
| 1724 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1725 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1726 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1727 | |
| 1728 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1729 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1730 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1731 | } |
| 1732 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1733 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1734 | HttpRequestInfo request; |
| 1735 | request.method = "GET"; |
| 1736 | request.url = GURL("http://www.google.com/"); |
| 1737 | request.load_flags = 0; |
| 1738 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1739 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1740 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1741 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1742 | |
| 1743 | MockRead data_reads[] = { |
| 1744 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1745 | MockRead("Connection: keep-alive\r\n"), |
| 1746 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1747 | MockRead(SYNCHRONOUS, 0), |
| 1748 | }; |
| 1749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1751 | |
| 1752 | TestCompletionCallback callback; |
| 1753 | |
| 1754 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1755 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1756 | |
| 1757 | rv = callback.WaitForResult(); |
| 1758 | EXPECT_EQ(OK, rv); |
| 1759 | |
| 1760 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1761 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1762 | if (rv == ERR_IO_PENDING) |
| 1763 | rv = callback.WaitForResult(); |
| 1764 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1765 | |
| 1766 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1767 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1768 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1769 | } |
| 1770 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1771 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1772 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1773 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1774 | HttpRequestInfo request; |
| 1775 | request.method = "GET"; |
| 1776 | request.url = GURL("http://www.foo.com/"); |
| 1777 | request.load_flags = 0; |
| 1778 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1779 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1780 | session_deps_.net_log = &net_log; |
| 1781 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1782 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1783 | // Note that because all these reads happen in the same |
| 1784 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1785 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1786 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1787 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1788 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1789 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1790 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1791 | "Content-Length: 0\r\n\r\n"), |
| 1792 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1793 | "Content-Length: 5\r\n\r\n" |
| 1794 | "hello"), |
| 1795 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1796 | "Content-Length: 0\r\n\r\n"), |
| 1797 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1798 | "Content-Length: 5\r\n\r\n" |
| 1799 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1800 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1801 | MockRead("hello"), |
| 1802 | }; |
| 1803 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1804 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1805 | |
| 1806 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1807 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1808 | }; |
| 1809 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1810 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1811 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1812 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1813 | std::string response_lines[kNumUnreadBodies]; |
| 1814 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1815 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1816 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1817 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1818 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1819 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1820 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1822 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1824 | |
| 1825 | rv = callback.WaitForResult(); |
| 1826 | EXPECT_EQ(OK, rv); |
| 1827 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1828 | LoadTimingInfo load_timing_info; |
| 1829 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1830 | if (i == 0) { |
| 1831 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1832 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1833 | } else { |
| 1834 | TestLoadTimingReused(load_timing_info); |
| 1835 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1836 | } |
| 1837 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1838 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1839 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1840 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1841 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1842 | response_lines[i] = response->headers->GetStatusLine(); |
| 1843 | |
| 1844 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1845 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1846 | |
| 1847 | const char* const kStatusLines[] = { |
| 1848 | "HTTP/1.1 204 No Content", |
| 1849 | "HTTP/1.1 205 Reset Content", |
| 1850 | "HTTP/1.1 304 Not Modified", |
| 1851 | "HTTP/1.1 302 Found", |
| 1852 | "HTTP/1.1 302 Found", |
| 1853 | "HTTP/1.1 301 Moved Permanently", |
| 1854 | "HTTP/1.1 301 Moved Permanently", |
| 1855 | }; |
| 1856 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1857 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1858 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1859 | |
| 1860 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1861 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1863 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1864 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1865 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1866 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1867 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1868 | rv = callback.WaitForResult(); |
| 1869 | EXPECT_EQ(OK, rv); |
| 1870 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1871 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1872 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1873 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1874 | std::string response_data; |
| 1875 | rv = ReadTransaction(trans.get(), &response_data); |
| 1876 | EXPECT_EQ(OK, rv); |
| 1877 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1878 | } |
| 1879 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1880 | // Test the request-challenge-retry sequence for basic auth. |
| 1881 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1882 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1883 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1884 | request.method = "GET"; |
| 1885 | request.url = GURL("http://www.google.com/"); |
| 1886 | request.load_flags = 0; |
| 1887 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1888 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1889 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1890 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1891 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1893 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1894 | MockWrite data_writes1[] = { |
| 1895 | MockWrite("GET / HTTP/1.1\r\n" |
| 1896 | "Host: www.google.com\r\n" |
| 1897 | "Connection: keep-alive\r\n\r\n"), |
| 1898 | }; |
| 1899 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1900 | MockRead data_reads1[] = { |
| 1901 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1902 | // Give a couple authenticate options (only the middle one is actually |
| 1903 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1904 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1905 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1906 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1908 | // Large content-length -- won't matter, as connection will be reset. |
| 1909 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1910 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1911 | }; |
| 1912 | |
| 1913 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1914 | // be issuing -- the final header line contains the credentials. |
| 1915 | MockWrite data_writes2[] = { |
| 1916 | MockWrite("GET / HTTP/1.1\r\n" |
| 1917 | "Host: www.google.com\r\n" |
| 1918 | "Connection: keep-alive\r\n" |
| 1919 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 1920 | }; |
| 1921 | |
| 1922 | // Lastly, the server responds with the actual content. |
| 1923 | MockRead data_reads2[] = { |
| 1924 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1925 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1926 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1927 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1928 | }; |
| 1929 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1930 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1931 | data_writes1, arraysize(data_writes1)); |
| 1932 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1933 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1935 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1937 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1939 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1941 | |
| 1942 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1943 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1944 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1945 | LoadTimingInfo load_timing_info1; |
| 1946 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1947 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1948 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1949 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1950 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1951 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1952 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1953 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1954 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1956 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1958 | rv = trans->RestartWithAuth( |
| 1959 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1960 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1961 | |
| 1962 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1963 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1964 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1965 | LoadTimingInfo load_timing_info2; |
| 1966 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1967 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1968 | // The load timing after restart should have a new socket ID, and times after |
| 1969 | // those of the first load timing. |
| 1970 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1971 | load_timing_info2.connect_timing.connect_start); |
| 1972 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1973 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1974 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1975 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1976 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1977 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1978 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1979 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1980 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1981 | } |
| 1982 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1983 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1984 | HttpRequestInfo request; |
| 1985 | request.method = "GET"; |
| 1986 | request.url = GURL("http://www.google.com/"); |
| 1987 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 1988 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1989 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1990 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1991 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1992 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1993 | MockWrite data_writes[] = { |
| 1994 | MockWrite("GET / HTTP/1.1\r\n" |
| 1995 | "Host: www.google.com\r\n" |
| 1996 | "Connection: keep-alive\r\n\r\n"), |
| 1997 | }; |
| 1998 | |
| 1999 | MockRead data_reads[] = { |
| 2000 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2001 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2002 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2003 | // Large content-length -- won't matter, as connection will be reset. |
| 2004 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2005 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2006 | }; |
| 2007 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2008 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2009 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2011 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2013 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2014 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2015 | |
| 2016 | rv = callback.WaitForResult(); |
| 2017 | EXPECT_EQ(0, rv); |
| 2018 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2019 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2020 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2021 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2022 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2023 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2024 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2025 | } |
| 2026 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2027 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2028 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2029 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2030 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2031 | request.method = "GET"; |
| 2032 | request.url = GURL("http://www.google.com/"); |
| 2033 | request.load_flags = 0; |
| 2034 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2035 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2036 | session_deps_.net_log = &log; |
| 2037 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2038 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2039 | MockWrite data_writes1[] = { |
| 2040 | MockWrite("GET / HTTP/1.1\r\n" |
| 2041 | "Host: www.google.com\r\n" |
| 2042 | "Connection: keep-alive\r\n\r\n"), |
| 2043 | |
| 2044 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2045 | // be issuing -- the final header line contains the credentials. |
| 2046 | MockWrite("GET / HTTP/1.1\r\n" |
| 2047 | "Host: www.google.com\r\n" |
| 2048 | "Connection: keep-alive\r\n" |
| 2049 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2050 | }; |
| 2051 | |
| 2052 | MockRead data_reads1[] = { |
| 2053 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2054 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2055 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2056 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2057 | MockRead("Unauthorized\r\n"), |
| 2058 | |
| 2059 | // Lastly, the server responds with the actual content. |
| 2060 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2061 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2062 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2063 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2064 | }; |
| 2065 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2066 | // If there is a regression where we disconnect a Keep-Alive |
| 2067 | // connection during an auth roundtrip, we'll end up reading this. |
| 2068 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2069 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2070 | }; |
| 2071 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2072 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2073 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2074 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2075 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2076 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2077 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2079 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2080 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2081 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2082 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2083 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2084 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2085 | |
| 2086 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2087 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2088 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2089 | LoadTimingInfo load_timing_info1; |
| 2090 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2091 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2092 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2093 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2094 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2095 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2096 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2097 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2099 | rv = trans->RestartWithAuth( |
| 2100 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2101 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2102 | |
| 2103 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2104 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2105 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2106 | LoadTimingInfo load_timing_info2; |
| 2107 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2108 | TestLoadTimingReused(load_timing_info2); |
| 2109 | // The load timing after restart should have the same socket ID, and times |
| 2110 | // those of the first load timing. |
| 2111 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2112 | load_timing_info2.send_start); |
| 2113 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2114 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2115 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2116 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2117 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2118 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2119 | |
| 2120 | std::string response_data; |
| 2121 | rv = ReadTransaction(trans.get(), &response_data); |
| 2122 | EXPECT_EQ(OK, rv); |
| 2123 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2124 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2128 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2129 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2130 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2131 | request.method = "GET"; |
| 2132 | request.url = GURL("http://www.google.com/"); |
| 2133 | request.load_flags = 0; |
| 2134 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2135 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2136 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2137 | MockWrite data_writes1[] = { |
| 2138 | MockWrite("GET / HTTP/1.1\r\n" |
| 2139 | "Host: www.google.com\r\n" |
| 2140 | "Connection: keep-alive\r\n\r\n"), |
| 2141 | |
| 2142 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2143 | // be issuing -- the final header line contains the credentials. |
| 2144 | MockWrite("GET / HTTP/1.1\r\n" |
| 2145 | "Host: www.google.com\r\n" |
| 2146 | "Connection: keep-alive\r\n" |
| 2147 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2148 | }; |
| 2149 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2150 | MockRead data_reads1[] = { |
| 2151 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2152 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2153 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2154 | |
| 2155 | // Lastly, the server responds with the actual content. |
| 2156 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2157 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2158 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2159 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2160 | }; |
| 2161 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2162 | // An incorrect reconnect would cause this to be read. |
| 2163 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2164 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2165 | }; |
| 2166 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2167 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2168 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2169 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2170 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2172 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2174 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2175 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2176 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2177 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2178 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2180 | |
| 2181 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2182 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2183 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2184 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2185 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2186 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2188 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2190 | rv = trans->RestartWithAuth( |
| 2191 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2192 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2193 | |
| 2194 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2195 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2196 | |
| 2197 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2198 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2199 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2200 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2204 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2205 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2206 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2207 | request.method = "GET"; |
| 2208 | request.url = GURL("http://www.google.com/"); |
| 2209 | request.load_flags = 0; |
| 2210 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2211 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2212 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2213 | MockWrite data_writes1[] = { |
| 2214 | MockWrite("GET / HTTP/1.1\r\n" |
| 2215 | "Host: www.google.com\r\n" |
| 2216 | "Connection: keep-alive\r\n\r\n"), |
| 2217 | |
| 2218 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2219 | // be issuing -- the final header line contains the credentials. |
| 2220 | MockWrite("GET / HTTP/1.1\r\n" |
| 2221 | "Host: www.google.com\r\n" |
| 2222 | "Connection: keep-alive\r\n" |
| 2223 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2224 | }; |
| 2225 | |
| 2226 | // Respond with 5 kb of response body. |
| 2227 | std::string large_body_string("Unauthorized"); |
| 2228 | large_body_string.append(5 * 1024, ' '); |
| 2229 | large_body_string.append("\r\n"); |
| 2230 | |
| 2231 | MockRead data_reads1[] = { |
| 2232 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2233 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2234 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2235 | // 5134 = 12 + 5 * 1024 + 2 |
| 2236 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2237 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2238 | |
| 2239 | // Lastly, the server responds with the actual content. |
| 2240 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2241 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2242 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2243 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2244 | }; |
| 2245 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2246 | // An incorrect reconnect would cause this to be read. |
| 2247 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2248 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2249 | }; |
| 2250 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2251 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2252 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2253 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2254 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2255 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2256 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2258 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2259 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2260 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2262 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2264 | |
| 2265 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2266 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2267 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2268 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2269 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2270 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2272 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2274 | rv = trans->RestartWithAuth( |
| 2275 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2276 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2277 | |
| 2278 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2279 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2280 | |
| 2281 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2282 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2283 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2284 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2288 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2289 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2290 | HttpRequestInfo request; |
| 2291 | request.method = "GET"; |
| 2292 | request.url = GURL("http://www.google.com/"); |
| 2293 | request.load_flags = 0; |
| 2294 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2295 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2296 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2297 | MockWrite data_writes1[] = { |
| 2298 | MockWrite("GET / HTTP/1.1\r\n" |
| 2299 | "Host: www.google.com\r\n" |
| 2300 | "Connection: keep-alive\r\n\r\n"), |
| 2301 | // This simulates the seemingly successful write to a closed connection |
| 2302 | // if the bug is not fixed. |
| 2303 | MockWrite("GET / HTTP/1.1\r\n" |
| 2304 | "Host: www.google.com\r\n" |
| 2305 | "Connection: keep-alive\r\n" |
| 2306 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2307 | }; |
| 2308 | |
| 2309 | MockRead data_reads1[] = { |
| 2310 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2311 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2312 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2313 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2314 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2315 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2316 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2317 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2318 | }; |
| 2319 | |
| 2320 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2321 | // be issuing -- the final header line contains the credentials. |
| 2322 | MockWrite data_writes2[] = { |
| 2323 | MockWrite("GET / HTTP/1.1\r\n" |
| 2324 | "Host: www.google.com\r\n" |
| 2325 | "Connection: keep-alive\r\n" |
| 2326 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2327 | }; |
| 2328 | |
| 2329 | // Lastly, the server responds with the actual content. |
| 2330 | MockRead data_reads2[] = { |
| 2331 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2332 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2333 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2334 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2335 | }; |
| 2336 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2337 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2338 | data_writes1, arraysize(data_writes1)); |
| 2339 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2340 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2342 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2344 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2345 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2346 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2347 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2348 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2350 | |
| 2351 | rv = callback1.WaitForResult(); |
| 2352 | EXPECT_EQ(OK, rv); |
| 2353 | |
| 2354 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2355 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2356 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2357 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2358 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2359 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2360 | rv = trans->RestartWithAuth( |
| 2361 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2362 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2363 | |
| 2364 | rv = callback2.WaitForResult(); |
| 2365 | EXPECT_EQ(OK, rv); |
| 2366 | |
| 2367 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2368 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2369 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2370 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2371 | } |
| 2372 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2373 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2374 | // that requires a restart when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2375 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2376 | HttpRequestInfo request; |
| 2377 | request.method = "GET"; |
| 2378 | request.url = GURL("https://www.google.com/"); |
| 2379 | // when the no authentication data flag is set. |
| 2380 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2381 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2382 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2383 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2384 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2385 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2386 | session_deps_.net_log = log.bound().net_log(); |
| 2387 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2388 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2389 | // Since we have proxy, should try to establish tunnel. |
| 2390 | MockWrite data_writes1[] = { |
| 2391 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2392 | "Host: www.google.com\r\n" |
| 2393 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2394 | |
| 2395 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2396 | // be issuing -- the final header line contains the credentials. |
| 2397 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2398 | "Host: www.google.com\r\n" |
| 2399 | "Proxy-Connection: keep-alive\r\n" |
| 2400 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2401 | |
| 2402 | MockWrite("GET / HTTP/1.1\r\n" |
| 2403 | "Host: www.google.com\r\n" |
| 2404 | "Connection: keep-alive\r\n\r\n"), |
| 2405 | }; |
| 2406 | |
| 2407 | // The proxy responds to the connect with a 407, using a persistent |
| 2408 | // connection. |
| 2409 | MockRead data_reads1[] = { |
| 2410 | // No credentials. |
| 2411 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2412 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2413 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2414 | |
| 2415 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2416 | |
| 2417 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2418 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2419 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2420 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2421 | }; |
| 2422 | |
| 2423 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2424 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2425 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2426 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2429 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2430 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2431 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2432 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2434 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2435 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2436 | |
| 2437 | rv = callback1.WaitForResult(); |
| 2438 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2439 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2440 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2441 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2442 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2443 | NetLog::PHASE_NONE); |
| 2444 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2445 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2446 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2447 | NetLog::PHASE_NONE); |
| 2448 | |
| 2449 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2450 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2451 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2452 | EXPECT_EQ(407, response->headers->response_code()); |
| 2453 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2454 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2455 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2456 | LoadTimingInfo load_timing_info; |
| 2457 | // CONNECT requests and responses are handled at the connect job level, so |
| 2458 | // the transaction does not yet have a connection. |
| 2459 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2461 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2463 | rv = trans->RestartWithAuth( |
| 2464 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2465 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2466 | |
| 2467 | rv = callback2.WaitForResult(); |
| 2468 | EXPECT_EQ(OK, rv); |
| 2469 | |
| 2470 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2471 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2472 | |
| 2473 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2474 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2475 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2476 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2477 | |
| 2478 | // The password prompt info should not be set. |
| 2479 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2480 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2481 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2482 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2483 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2484 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2485 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2486 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2487 | } |
| 2488 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2489 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2490 | // proxy connection, when setting up an SSL tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2491 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2492 | HttpRequestInfo request; |
| 2493 | request.method = "GET"; |
| 2494 | request.url = GURL("https://www.google.com/"); |
| 2495 | // Ensure that proxy authentication is attempted even |
| 2496 | // when the no authentication data flag is set. |
| 2497 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2498 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2499 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2500 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2501 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2502 | session_deps_.net_log = log.bound().net_log(); |
| 2503 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2504 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2505 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2506 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2507 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [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" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2511 | "Host: www.google.com\r\n" |
| 2512 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 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" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2518 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2519 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2520 | }; |
| 2521 | |
| 2522 | // The proxy responds to the connect with a 407, using a persistent |
| 2523 | // connection. |
| 2524 | MockRead data_reads1[] = { |
| 2525 | // No credentials. |
| 2526 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2527 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2528 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2529 | MockRead("0123456789"), |
| 2530 | |
| 2531 | // Wrong credentials (wrong password). |
| 2532 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2533 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2534 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2535 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2536 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2537 | }; |
| 2538 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2539 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2540 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2543 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2544 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2545 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2546 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2547 | |
| 2548 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2549 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2550 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2551 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2552 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2553 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2554 | NetLog::PHASE_NONE); |
| 2555 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2556 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2557 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2558 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2559 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2560 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2561 | ASSERT_TRUE(response); |
| 2562 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2563 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2564 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2565 | EXPECT_EQ(-1, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2566 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2567 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2568 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2569 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2570 | |
| 2571 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2572 | rv = trans->RestartWithAuth( |
| 2573 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2574 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2575 | |
| 2576 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2577 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2578 | |
| 2579 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2580 | ASSERT_TRUE(response); |
| 2581 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2582 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2583 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2584 | EXPECT_EQ(-1, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2585 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2586 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2587 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2588 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2589 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2590 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2591 | } |
| 2592 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2593 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2594 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2595 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2596 | HttpRequestInfo request; |
| 2597 | request.method = "GET"; |
| 2598 | request.url = GURL("https://www.google.com/"); |
| 2599 | request.load_flags = 0; |
| 2600 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2601 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2602 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2603 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2604 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2605 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2606 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2607 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2608 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2609 | // Since we have proxy, should try to establish tunnel. |
| 2610 | MockWrite data_writes[] = { |
| 2611 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2612 | "Host: www.google.com\r\n" |
| 2613 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2614 | }; |
| 2615 | |
| 2616 | // The proxy responds to the connect with a 407. |
| 2617 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2618 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2619 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2620 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2621 | MockRead("0123456789"), // Should not be reached. |
| 2622 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2623 | }; |
| 2624 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2625 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2626 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2629 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2631 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2632 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2633 | |
| 2634 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2635 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2636 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2637 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2638 | ASSERT_TRUE(response); |
| 2639 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2640 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2641 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2642 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2643 | |
| 2644 | std::string response_data; |
| 2645 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2646 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2647 | |
| 2648 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2649 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2650 | } |
| 2651 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2652 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 2653 | // caller when the proxy responds to CONNECT with 407. |
| 2654 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 2655 | HttpRequestInfo request; |
| 2656 | request.method = "GET"; |
| 2657 | request.url = GURL("https://www.google.com/"); |
| 2658 | request.load_flags = 0; |
| 2659 | |
| 2660 | // Configure against proxy server "myproxy:70". |
| 2661 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2662 | |
| 2663 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2664 | |
| 2665 | scoped_ptr<HttpTransaction> trans( |
| 2666 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2667 | |
| 2668 | // Since we have proxy, should try to establish tunnel. |
| 2669 | MockWrite data_writes[] = { |
| 2670 | MockWrite( |
| 2671 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2672 | "Host: www.google.com\r\n" |
| 2673 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2674 | }; |
| 2675 | |
| 2676 | // The proxy responds to the connect with a 407. |
| 2677 | MockRead data_reads[] = { |
| 2678 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2679 | MockRead("X-Foo: bar\r\n"), |
| 2680 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 2681 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2682 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2683 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2684 | }; |
| 2685 | |
| 2686 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2687 | arraysize(data_writes)); |
| 2688 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2689 | |
| 2690 | TestCompletionCallback callback; |
| 2691 | |
| 2692 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2693 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2694 | |
| 2695 | rv = callback.WaitForResult(); |
| 2696 | EXPECT_EQ(OK, rv); |
| 2697 | |
| 2698 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2699 | ASSERT_TRUE(response); |
| 2700 | ASSERT_TRUE(response->headers); |
| 2701 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2702 | EXPECT_EQ(407, response->headers->response_code()); |
| 2703 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2704 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 2705 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 2706 | |
| 2707 | std::string response_data; |
| 2708 | rv = ReadTransaction(trans.get(), &response_data); |
| 2709 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 2710 | |
| 2711 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 2712 | session->CloseAllConnections(); |
| 2713 | } |
| 2714 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2715 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2716 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2717 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2718 | HttpRequestInfo request; |
| 2719 | request.method = "GET"; |
| 2720 | request.url = GURL("http://www.google.com/"); |
| 2721 | request.load_flags = 0; |
| 2722 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2723 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2724 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2725 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2726 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2727 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2728 | MockWrite data_writes1[] = { |
| 2729 | MockWrite("GET / HTTP/1.1\r\n" |
| 2730 | "Host: www.google.com\r\n" |
| 2731 | "Connection: keep-alive\r\n\r\n"), |
| 2732 | }; |
| 2733 | |
| 2734 | MockRead data_reads1[] = { |
| 2735 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2736 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2737 | // Large content-length -- won't matter, as connection will be reset. |
| 2738 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2739 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2740 | }; |
| 2741 | |
| 2742 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2743 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2744 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2746 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2748 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2749 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2750 | |
| 2751 | rv = callback.WaitForResult(); |
| 2752 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2753 | } |
| 2754 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2755 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2756 | // through a non-authenticating proxy. The request should fail with |
| 2757 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2758 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2759 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2760 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2761 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2762 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2763 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2764 | HttpRequestInfo request; |
| 2765 | request.method = "GET"; |
| 2766 | request.url = GURL("https://www.google.com/"); |
| 2767 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2768 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2769 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2770 | session_deps_.net_log = log.bound().net_log(); |
| 2771 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2772 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2773 | // Since we have proxy, should try to establish tunnel. |
| 2774 | MockWrite data_writes1[] = { |
| 2775 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2776 | "Host: www.google.com\r\n" |
| 2777 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2778 | |
| 2779 | MockWrite("GET / HTTP/1.1\r\n" |
| 2780 | "Host: www.google.com\r\n" |
| 2781 | "Connection: keep-alive\r\n\r\n"), |
| 2782 | }; |
| 2783 | |
| 2784 | MockRead data_reads1[] = { |
| 2785 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2786 | |
| 2787 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 2788 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2789 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2791 | }; |
| 2792 | |
| 2793 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2794 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2795 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2796 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2799 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2800 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2801 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2802 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2804 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2805 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2806 | |
| 2807 | rv = callback1.WaitForResult(); |
| 2808 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2809 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2810 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2811 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2812 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2813 | NetLog::PHASE_NONE); |
| 2814 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2815 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2816 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2817 | NetLog::PHASE_NONE); |
| 2818 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 2819 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2820 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2821 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2822 | HttpRequestInfo request1; |
| 2823 | request1.method = "GET"; |
| 2824 | request1.url = GURL("https://www.google.com/1"); |
| 2825 | |
| 2826 | HttpRequestInfo request2; |
| 2827 | request2.method = "GET"; |
| 2828 | request2.url = GURL("https://www.google.com/2"); |
| 2829 | |
| 2830 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2831 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2832 | ProxyService::CreateFixed("PROXY myproxy:70")); |
| 2833 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2834 | session_deps_.net_log = log.bound().net_log(); |
| 2835 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2836 | |
| 2837 | // Since we have proxy, should try to establish tunnel. |
| 2838 | MockWrite data_writes1[] = { |
| 2839 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2840 | "Host: www.google.com\r\n" |
| 2841 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2842 | |
| 2843 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2844 | "Host: www.google.com\r\n" |
| 2845 | "Connection: keep-alive\r\n\r\n"), |
| 2846 | |
| 2847 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2848 | "Host: www.google.com\r\n" |
| 2849 | "Connection: keep-alive\r\n\r\n"), |
| 2850 | }; |
| 2851 | |
| 2852 | // The proxy responds to the connect with a 407, using a persistent |
| 2853 | // connection. |
| 2854 | MockRead data_reads1[] = { |
| 2855 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2856 | |
| 2857 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2858 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2859 | MockRead(SYNCHRONOUS, "1"), |
| 2860 | |
| 2861 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2862 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2863 | MockRead(SYNCHRONOUS, "22"), |
| 2864 | }; |
| 2865 | |
| 2866 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2867 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2868 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2869 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2871 | |
| 2872 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2873 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2874 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2875 | |
| 2876 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2877 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2878 | |
| 2879 | rv = callback1.WaitForResult(); |
| 2880 | EXPECT_EQ(OK, rv); |
| 2881 | |
| 2882 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2883 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2884 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2885 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2886 | |
| 2887 | LoadTimingInfo load_timing_info1; |
| 2888 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2889 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 2890 | |
| 2891 | trans1.reset(); |
| 2892 | |
| 2893 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2894 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2896 | |
| 2897 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2899 | |
| 2900 | rv = callback2.WaitForResult(); |
| 2901 | EXPECT_EQ(OK, rv); |
| 2902 | |
| 2903 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2904 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2905 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2906 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 2907 | |
| 2908 | LoadTimingInfo load_timing_info2; |
| 2909 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 2910 | TestLoadTimingReused(load_timing_info2); |
| 2911 | |
| 2912 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2913 | |
| 2914 | trans2.reset(); |
| 2915 | session->CloseAllConnections(); |
| 2916 | } |
| 2917 | |
| 2918 | // Test the load timing for HTTPS requests with an HTTP proxy and a PAC script. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2919 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2920 | HttpRequestInfo request1; |
| 2921 | request1.method = "GET"; |
| 2922 | request1.url = GURL("https://www.google.com/1"); |
| 2923 | |
| 2924 | HttpRequestInfo request2; |
| 2925 | request2.method = "GET"; |
| 2926 | request2.url = GURL("https://www.google.com/2"); |
| 2927 | |
| 2928 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2929 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2930 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 2931 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2932 | session_deps_.net_log = log.bound().net_log(); |
| 2933 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2934 | |
| 2935 | // Since we have proxy, should try to establish tunnel. |
| 2936 | MockWrite data_writes1[] = { |
| 2937 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2938 | "Host: www.google.com\r\n" |
| 2939 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2940 | |
| 2941 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 2942 | "Host: www.google.com\r\n" |
| 2943 | "Connection: keep-alive\r\n\r\n"), |
| 2944 | |
| 2945 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 2946 | "Host: www.google.com\r\n" |
| 2947 | "Connection: keep-alive\r\n\r\n"), |
| 2948 | }; |
| 2949 | |
| 2950 | // The proxy responds to the connect with a 407, using a persistent |
| 2951 | // connection. |
| 2952 | MockRead data_reads1[] = { |
| 2953 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2954 | |
| 2955 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2956 | MockRead("Content-Length: 1\r\n\r\n"), |
| 2957 | MockRead(SYNCHRONOUS, "1"), |
| 2958 | |
| 2959 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2960 | MockRead("Content-Length: 2\r\n\r\n"), |
| 2961 | MockRead(SYNCHRONOUS, "22"), |
| 2962 | }; |
| 2963 | |
| 2964 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2965 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2966 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2967 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2969 | |
| 2970 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2971 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2972 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2973 | |
| 2974 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 2975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2976 | |
| 2977 | rv = callback1.WaitForResult(); |
| 2978 | EXPECT_EQ(OK, rv); |
| 2979 | |
| 2980 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2981 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2982 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2983 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 2984 | |
| 2985 | LoadTimingInfo load_timing_info1; |
| 2986 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 2987 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 2988 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2989 | |
| 2990 | trans1.reset(); |
| 2991 | |
| 2992 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2993 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2994 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2995 | |
| 2996 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 2997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2998 | |
| 2999 | rv = callback2.WaitForResult(); |
| 3000 | EXPECT_EQ(OK, rv); |
| 3001 | |
| 3002 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3003 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3004 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3005 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3006 | |
| 3007 | LoadTimingInfo load_timing_info2; |
| 3008 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3009 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3010 | |
| 3011 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3012 | |
| 3013 | trans2.reset(); |
| 3014 | session->CloseAllConnections(); |
| 3015 | } |
| 3016 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3017 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3018 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3019 | HttpRequestInfo request; |
| 3020 | request.method = "GET"; |
| 3021 | request.url = GURL("http://www.google.com/"); |
| 3022 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3023 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3024 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3025 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3026 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3027 | session_deps_.net_log = log.bound().net_log(); |
| 3028 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3029 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3030 | // Since we have proxy, should use full url |
| 3031 | MockWrite data_writes1[] = { |
| 3032 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3033 | "Host: www.google.com\r\n" |
| 3034 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3035 | }; |
| 3036 | |
| 3037 | MockRead data_reads1[] = { |
| 3038 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3039 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3040 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3041 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3042 | }; |
| 3043 | |
| 3044 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3045 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3046 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3047 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3050 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3051 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3052 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3053 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3055 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3056 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3057 | |
| 3058 | rv = callback1.WaitForResult(); |
| 3059 | EXPECT_EQ(OK, rv); |
| 3060 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3061 | LoadTimingInfo load_timing_info; |
| 3062 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3063 | TestLoadTimingNotReused(load_timing_info, |
| 3064 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3065 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3066 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3067 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3068 | |
| 3069 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3070 | EXPECT_EQ(200, response->headers->response_code()); |
| 3071 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3072 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3073 | |
| 3074 | // The password prompt info should not be set. |
| 3075 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3076 | } |
| 3077 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3078 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3079 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3080 | HttpRequestInfo request; |
| 3081 | request.method = "GET"; |
| 3082 | request.url = GURL("http://www.google.com/"); |
| 3083 | request.load_flags = 0; |
| 3084 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3085 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3086 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3087 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3088 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3089 | session_deps_.net_log = log.bound().net_log(); |
| 3090 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3091 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3092 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3093 | scoped_ptr<SpdyFrame> req( |
| 3094 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3095 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 3096 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3097 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3098 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3099 | MockRead spdy_reads[] = { |
| 3100 | CreateMockRead(*resp), |
| 3101 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3102 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3103 | }; |
| 3104 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3105 | DelayedSocketData spdy_data( |
| 3106 | 1, // wait for one write to finish before reading. |
| 3107 | spdy_reads, arraysize(spdy_reads), |
| 3108 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3109 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3110 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3111 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3112 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3115 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3116 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3117 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3118 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3120 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3121 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3122 | |
| 3123 | rv = callback1.WaitForResult(); |
| 3124 | EXPECT_EQ(OK, rv); |
| 3125 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3126 | LoadTimingInfo load_timing_info; |
| 3127 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3128 | TestLoadTimingNotReused(load_timing_info, |
| 3129 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3130 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3131 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3132 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3133 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3134 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3135 | |
| 3136 | std::string response_data; |
| 3137 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3138 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3139 | } |
| 3140 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3141 | // Verifies that a session which races and wins against the owning transaction |
| 3142 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3143 | // Regression test for crbug.com/334413. |
| 3144 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3145 | HttpRequestInfo request; |
| 3146 | request.method = "GET"; |
| 3147 | request.url = GURL("http://www.google.com/"); |
| 3148 | request.load_flags = 0; |
| 3149 | |
| 3150 | // Configure SPDY proxy server "proxy:70". |
| 3151 | session_deps_.proxy_service.reset( |
| 3152 | ProxyService::CreateFixed("https://proxy:70")); |
| 3153 | CapturingBoundNetLog log; |
| 3154 | session_deps_.net_log = log.bound().net_log(); |
| 3155 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3156 | |
| 3157 | // Fetch http://www.google.com/ through the SPDY proxy. |
| 3158 | scoped_ptr<SpdyFrame> req( |
| 3159 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
| 3160 | MockWrite spdy_writes[] = {CreateMockWrite(*req)}; |
| 3161 | |
| 3162 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3163 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3164 | MockRead spdy_reads[] = { |
| 3165 | CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0), |
| 3166 | }; |
| 3167 | |
| 3168 | DelayedSocketData spdy_data( |
| 3169 | 1, // wait for one write to finish before reading. |
| 3170 | spdy_reads, |
| 3171 | arraysize(spdy_reads), |
| 3172 | spdy_writes, |
| 3173 | arraysize(spdy_writes)); |
| 3174 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3175 | |
| 3176 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3177 | ssl.SetNextProto(GetParam()); |
| 3178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3179 | |
| 3180 | TestCompletionCallback callback1; |
| 3181 | |
| 3182 | scoped_ptr<HttpTransaction> trans( |
| 3183 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3184 | |
| 3185 | // Stall the hostname resolution begun by the transaction. |
| 3186 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3187 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3188 | |
| 3189 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3191 | |
| 3192 | // Race a session to the proxy, which completes first. |
| 3193 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3194 | SpdySessionKey key( |
| 3195 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3196 | base::WeakPtr<SpdySession> spdy_session = |
| 3197 | CreateSecureSpdySession(session, key, log.bound()); |
| 3198 | |
| 3199 | // Unstall the resolution begun by the transaction. |
| 3200 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3201 | session_deps_.host_resolver->ResolveAllPending(); |
| 3202 | |
| 3203 | EXPECT_FALSE(callback1.have_result()); |
| 3204 | rv = callback1.WaitForResult(); |
| 3205 | EXPECT_EQ(OK, rv); |
| 3206 | |
| 3207 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3208 | ASSERT_TRUE(response != NULL); |
| 3209 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3210 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3211 | |
| 3212 | std::string response_data; |
| 3213 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3214 | EXPECT_EQ(kUploadData, response_data); |
| 3215 | } |
| 3216 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3217 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3218 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3219 | HttpRequestInfo request; |
| 3220 | request.method = "GET"; |
| 3221 | request.url = GURL("http://www.google.com/"); |
| 3222 | request.load_flags = 0; |
| 3223 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3224 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3225 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3226 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3227 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3228 | session_deps_.net_log = log.bound().net_log(); |
| 3229 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3230 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3231 | // The first request will be a bare GET, the second request will be a |
| 3232 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3233 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3234 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3235 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3236 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3237 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3238 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3239 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3240 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3241 | false, |
| 3242 | 3, |
| 3243 | LOWEST, |
| 3244 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3245 | MockWrite spdy_writes[] = { |
| 3246 | CreateMockWrite(*req_get, 1), |
| 3247 | CreateMockWrite(*req_get_authorization, 4), |
| 3248 | }; |
| 3249 | |
| 3250 | // The first response is a 407 proxy authentication challenge, and the second |
| 3251 | // response will be a 200 response since the second request includes a valid |
| 3252 | // Authorization header. |
| 3253 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3254 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3255 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3256 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3257 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3258 | "407 Proxy Authentication Required", |
| 3259 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3260 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3261 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3262 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3263 | scoped_ptr<SpdyFrame> resp_data( |
| 3264 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3265 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3266 | MockRead spdy_reads[] = { |
| 3267 | CreateMockRead(*resp_authentication, 2), |
| 3268 | CreateMockRead(*body_authentication, 3), |
| 3269 | CreateMockRead(*resp_data, 5), |
| 3270 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3271 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3272 | }; |
| 3273 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3274 | OrderedSocketData data( |
| 3275 | spdy_reads, arraysize(spdy_reads), |
| 3276 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3277 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3278 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3279 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3280 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3283 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3284 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3285 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3288 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3290 | |
| 3291 | rv = callback1.WaitForResult(); |
| 3292 | EXPECT_EQ(OK, rv); |
| 3293 | |
| 3294 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3295 | |
| 3296 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3297 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3298 | EXPECT_EQ(407, response->headers->response_code()); |
| 3299 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3300 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3302 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3304 | rv = trans->RestartWithAuth( |
| 3305 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3306 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3307 | |
| 3308 | rv = callback2.WaitForResult(); |
| 3309 | EXPECT_EQ(OK, rv); |
| 3310 | |
| 3311 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3312 | |
| 3313 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3314 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3315 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3316 | // The password prompt info should not be set. |
| 3317 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3318 | } |
| 3319 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3320 | // 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] | 3321 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3322 | HttpRequestInfo request; |
| 3323 | request.method = "GET"; |
| 3324 | request.url = GURL("https://www.google.com/"); |
| 3325 | request.load_flags = 0; |
| 3326 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3327 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3328 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3329 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3330 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3331 | session_deps_.net_log = log.bound().net_log(); |
| 3332 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3333 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3334 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3336 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3337 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3338 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3339 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3340 | // fetch https://www.google.com/ via HTTP |
| 3341 | |
| 3342 | const char get[] = "GET / HTTP/1.1\r\n" |
| 3343 | "Host: www.google.com\r\n" |
| 3344 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3345 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3346 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3347 | scoped_ptr<SpdyFrame> conn_resp( |
| 3348 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3349 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3350 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3351 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3352 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3353 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3354 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3355 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3356 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3357 | |
| 3358 | MockWrite spdy_writes[] = { |
| 3359 | CreateMockWrite(*connect, 1), |
| 3360 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3361 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3362 | }; |
| 3363 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3364 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3365 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3366 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3367 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3368 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 3369 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3370 | }; |
| 3371 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3372 | OrderedSocketData spdy_data( |
| 3373 | spdy_reads, arraysize(spdy_reads), |
| 3374 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3375 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3376 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3377 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3378 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3380 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3381 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 3382 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3385 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3387 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3388 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3389 | |
| 3390 | rv = callback1.WaitForResult(); |
| 3391 | EXPECT_EQ(OK, rv); |
| 3392 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3393 | LoadTimingInfo load_timing_info; |
| 3394 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3395 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3396 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3398 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3399 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3400 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3401 | |
| 3402 | std::string response_data; |
| 3403 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3404 | EXPECT_EQ("1234567890", response_data); |
| 3405 | } |
| 3406 | |
| 3407 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3408 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3409 | HttpRequestInfo request; |
| 3410 | request.method = "GET"; |
| 3411 | request.url = GURL("https://www.google.com/"); |
| 3412 | request.load_flags = 0; |
| 3413 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3414 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3415 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3416 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3417 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3418 | session_deps_.net_log = log.bound().net_log(); |
| 3419 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3420 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3421 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3422 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3423 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3424 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3425 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3426 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3427 | // fetch https://www.google.com/ via SPDY |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 3428 | const char kMyUrl[] = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3429 | scoped_ptr<SpdyFrame> get( |
| 3430 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3431 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3432 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3433 | scoped_ptr<SpdyFrame> conn_resp( |
| 3434 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3435 | scoped_ptr<SpdyFrame> get_resp( |
| 3436 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3437 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3438 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3439 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3440 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3441 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3442 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3443 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3444 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3445 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3446 | |
| 3447 | MockWrite spdy_writes[] = { |
| 3448 | CreateMockWrite(*connect, 1), |
| 3449 | CreateMockWrite(*wrapped_get, 3), |
| 3450 | CreateMockWrite(*window_update_get_resp, 5), |
| 3451 | CreateMockWrite(*window_update_body, 7), |
| 3452 | }; |
| 3453 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3454 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3455 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3456 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3457 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3458 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3459 | }; |
| 3460 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3461 | OrderedSocketData spdy_data( |
| 3462 | spdy_reads, arraysize(spdy_reads), |
| 3463 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3465 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3466 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3467 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3469 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3470 | ssl2.SetNextProto(GetParam()); |
| 3471 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3474 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3476 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3477 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3478 | |
| 3479 | rv = callback1.WaitForResult(); |
| 3480 | EXPECT_EQ(OK, rv); |
| 3481 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3482 | LoadTimingInfo load_timing_info; |
| 3483 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3484 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3485 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3486 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3487 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3488 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3489 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3490 | |
| 3491 | std::string response_data; |
| 3492 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3493 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3497 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3498 | HttpRequestInfo request; |
| 3499 | request.method = "GET"; |
| 3500 | request.url = GURL("https://www.google.com/"); |
| 3501 | request.load_flags = 0; |
| 3502 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3503 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3504 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3505 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3506 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3507 | session_deps_.net_log = log.bound().net_log(); |
| 3508 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3509 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3510 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3512 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3513 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3514 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3515 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3516 | scoped_ptr<SpdyFrame> get( |
| 3517 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3518 | |
| 3519 | MockWrite spdy_writes[] = { |
| 3520 | CreateMockWrite(*connect, 1), |
| 3521 | CreateMockWrite(*get, 3), |
| 3522 | }; |
| 3523 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3524 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3525 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3526 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3527 | CreateMockRead(*resp, 2, ASYNC), |
| 3528 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3529 | }; |
| 3530 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3531 | OrderedSocketData spdy_data( |
| 3532 | spdy_reads, arraysize(spdy_reads), |
| 3533 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3534 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3535 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3536 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3537 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3539 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3540 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3543 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3544 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3545 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3546 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3547 | |
| 3548 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3549 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3550 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3551 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3552 | } |
| 3553 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3554 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3555 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3556 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3557 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3558 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3559 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3560 | "https://proxy:70")); |
| 3561 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3562 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3563 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3564 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3565 | |
| 3566 | HttpRequestInfo request1; |
| 3567 | request1.method = "GET"; |
| 3568 | request1.url = GURL("https://www.google.com/"); |
| 3569 | request1.load_flags = 0; |
| 3570 | |
| 3571 | HttpRequestInfo request2; |
| 3572 | request2.method = "GET"; |
| 3573 | request2.url = GURL("https://news.google.com/"); |
| 3574 | request2.load_flags = 0; |
| 3575 | |
| 3576 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3577 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3578 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3579 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3580 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3581 | |
| 3582 | // Fetch https://www.google.com/ via HTTP. |
| 3583 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3584 | "Host: www.google.com\r\n" |
| 3585 | "Connection: keep-alive\r\n\r\n"; |
| 3586 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3587 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3588 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3589 | "Content-Length: 1\r\n\r\n"; |
| 3590 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3591 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3592 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3593 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3594 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3595 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3596 | |
| 3597 | // CONNECT to news.google.com:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3598 | SpdyHeaderBlock connect2_block; |
| 3599 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 3600 | connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443"; |
| 3601 | connect2_block[spdy_util_.GetHostKey()] = "news.google.com"; |
| 3602 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3603 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3604 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3605 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3606 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3607 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3608 | |
| 3609 | // Fetch https://news.google.com/ via HTTP. |
| 3610 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3611 | "Host: news.google.com\r\n" |
| 3612 | "Connection: keep-alive\r\n\r\n"; |
| 3613 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3614 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3615 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3616 | "Content-Length: 2\r\n\r\n"; |
| 3617 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3618 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3619 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3620 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3621 | |
| 3622 | MockWrite spdy_writes[] = { |
| 3623 | CreateMockWrite(*connect1, 0), |
| 3624 | CreateMockWrite(*wrapped_get1, 2), |
| 3625 | CreateMockWrite(*connect2, 5), |
| 3626 | CreateMockWrite(*wrapped_get2, 7), |
| 3627 | }; |
| 3628 | |
| 3629 | MockRead spdy_reads[] = { |
| 3630 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3631 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3632 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3633 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3634 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3635 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3636 | MockRead(ASYNC, 0, 10), |
| 3637 | }; |
| 3638 | |
| 3639 | DeterministicSocketData spdy_data( |
| 3640 | spdy_reads, arraysize(spdy_reads), |
| 3641 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3642 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3643 | |
| 3644 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3645 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3646 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3647 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3648 | ssl2.was_npn_negotiated = false; |
| 3649 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3650 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3651 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3652 | ssl3.was_npn_negotiated = false; |
| 3653 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3654 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3655 | |
| 3656 | TestCompletionCallback callback; |
| 3657 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3658 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3659 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3660 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3662 | // The first connect and request, each of their responses, and the body. |
| 3663 | spdy_data.RunFor(5); |
| 3664 | |
| 3665 | rv = callback.WaitForResult(); |
| 3666 | EXPECT_EQ(OK, rv); |
| 3667 | |
| 3668 | LoadTimingInfo load_timing_info; |
| 3669 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3670 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3671 | |
| 3672 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3673 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3674 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3675 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3676 | |
| 3677 | std::string response_data; |
| 3678 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3679 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3680 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3681 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3682 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3683 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3684 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3685 | |
| 3686 | // The second connect and request, each of their responses, and the body. |
| 3687 | spdy_data.RunFor(5); |
| 3688 | rv = callback.WaitForResult(); |
| 3689 | EXPECT_EQ(OK, rv); |
| 3690 | |
| 3691 | LoadTimingInfo load_timing_info2; |
| 3692 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3693 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3694 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3695 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3696 | |
| 3697 | // The requests should have different IDs, since they each are using their own |
| 3698 | // separate stream. |
| 3699 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3700 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3701 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3705 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3706 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3707 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3708 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3709 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3710 | "https://proxy:70")); |
| 3711 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3712 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3713 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3714 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3715 | |
| 3716 | HttpRequestInfo request1; |
| 3717 | request1.method = "GET"; |
| 3718 | request1.url = GURL("https://www.google.com/"); |
| 3719 | request1.load_flags = 0; |
| 3720 | |
| 3721 | HttpRequestInfo request2; |
| 3722 | request2.method = "GET"; |
| 3723 | request2.url = GURL("https://www.google.com/2"); |
| 3724 | request2.load_flags = 0; |
| 3725 | |
| 3726 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3727 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3728 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3729 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3730 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3731 | |
| 3732 | // Fetch https://www.google.com/ via HTTP. |
| 3733 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3734 | "Host: www.google.com\r\n" |
| 3735 | "Connection: keep-alive\r\n\r\n"; |
| 3736 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3737 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3738 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3739 | "Content-Length: 1\r\n\r\n"; |
| 3740 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3741 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3742 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3743 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3744 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3745 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3746 | |
| 3747 | // Fetch https://www.google.com/2 via HTTP. |
| 3748 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3749 | "Host: www.google.com\r\n" |
| 3750 | "Connection: keep-alive\r\n\r\n"; |
| 3751 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3752 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3753 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3754 | "Content-Length: 2\r\n\r\n"; |
| 3755 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3756 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3757 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3758 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3759 | |
| 3760 | MockWrite spdy_writes[] = { |
| 3761 | CreateMockWrite(*connect1, 0), |
| 3762 | CreateMockWrite(*wrapped_get1, 2), |
| 3763 | CreateMockWrite(*wrapped_get2, 5), |
| 3764 | }; |
| 3765 | |
| 3766 | MockRead spdy_reads[] = { |
| 3767 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3768 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3769 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3770 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3771 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3772 | MockRead(ASYNC, 0, 8), |
| 3773 | }; |
| 3774 | |
| 3775 | DeterministicSocketData spdy_data( |
| 3776 | spdy_reads, arraysize(spdy_reads), |
| 3777 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3778 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3779 | |
| 3780 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3781 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3782 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3783 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3784 | ssl2.was_npn_negotiated = false; |
| 3785 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3786 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3787 | |
| 3788 | TestCompletionCallback callback; |
| 3789 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3790 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3792 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3794 | // The first connect and request, each of their responses, and the body. |
| 3795 | spdy_data.RunFor(5); |
| 3796 | |
| 3797 | rv = callback.WaitForResult(); |
| 3798 | EXPECT_EQ(OK, rv); |
| 3799 | |
| 3800 | LoadTimingInfo load_timing_info; |
| 3801 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3802 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3803 | |
| 3804 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3805 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3806 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3807 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3808 | |
| 3809 | std::string response_data; |
| 3810 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3811 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3812 | trans.reset(); |
| 3813 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3814 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3815 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3816 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3817 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3818 | |
| 3819 | // The second request, response, and body. There should not be a second |
| 3820 | // connect. |
| 3821 | spdy_data.RunFor(3); |
| 3822 | rv = callback.WaitForResult(); |
| 3823 | EXPECT_EQ(OK, rv); |
| 3824 | |
| 3825 | LoadTimingInfo load_timing_info2; |
| 3826 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3827 | TestLoadTimingReused(load_timing_info2); |
| 3828 | |
| 3829 | // The requests should have the same ID. |
| 3830 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3831 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3832 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 3836 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3837 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3838 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 3839 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3840 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3841 | "https://proxy:70")); |
| 3842 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3843 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3844 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3845 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3846 | |
| 3847 | HttpRequestInfo request1; |
| 3848 | request1.method = "GET"; |
| 3849 | request1.url = GURL("http://www.google.com/"); |
| 3850 | request1.load_flags = 0; |
| 3851 | |
| 3852 | HttpRequestInfo request2; |
| 3853 | request2.method = "GET"; |
| 3854 | request2.url = GURL("http://news.google.com/"); |
| 3855 | request2.load_flags = 0; |
| 3856 | |
| 3857 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3858 | scoped_ptr<SpdyHeaderBlock> headers( |
| 3859 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3860 | scoped_ptr<SpdyFrame> get1( |
| 3861 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3862 | scoped_ptr<SpdyFrame> get_resp1( |
| 3863 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3864 | scoped_ptr<SpdyFrame> body1( |
| 3865 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3866 | |
| 3867 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3868 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 3869 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3870 | scoped_ptr<SpdyFrame> get2( |
| 3871 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3872 | scoped_ptr<SpdyFrame> get_resp2( |
| 3873 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3874 | scoped_ptr<SpdyFrame> body2( |
| 3875 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3876 | |
| 3877 | MockWrite spdy_writes[] = { |
| 3878 | CreateMockWrite(*get1, 0), |
| 3879 | CreateMockWrite(*get2, 3), |
| 3880 | }; |
| 3881 | |
| 3882 | MockRead spdy_reads[] = { |
| 3883 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 3884 | CreateMockRead(*body1, 2, ASYNC), |
| 3885 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 3886 | CreateMockRead(*body2, 5, ASYNC), |
| 3887 | MockRead(ASYNC, 0, 6), |
| 3888 | }; |
| 3889 | |
| 3890 | DeterministicSocketData spdy_data( |
| 3891 | spdy_reads, arraysize(spdy_reads), |
| 3892 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3893 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3894 | |
| 3895 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3896 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3897 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3898 | |
| 3899 | TestCompletionCallback callback; |
| 3900 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3901 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3902 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3903 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3904 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3905 | spdy_data.RunFor(2); |
| 3906 | |
| 3907 | rv = callback.WaitForResult(); |
| 3908 | EXPECT_EQ(OK, rv); |
| 3909 | |
| 3910 | LoadTimingInfo load_timing_info; |
| 3911 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3912 | TestLoadTimingNotReused(load_timing_info, |
| 3913 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3914 | |
| 3915 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3916 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3917 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3918 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3919 | |
| 3920 | std::string response_data; |
| 3921 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3922 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3923 | spdy_data.RunFor(1); |
| 3924 | EXPECT_EQ(1, callback.WaitForResult()); |
| 3925 | // Delete the first request, so the second one can reuse the socket. |
| 3926 | trans.reset(); |
| 3927 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3928 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3929 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3930 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3931 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3932 | |
| 3933 | spdy_data.RunFor(2); |
| 3934 | rv = callback.WaitForResult(); |
| 3935 | EXPECT_EQ(OK, rv); |
| 3936 | |
| 3937 | LoadTimingInfo load_timing_info2; |
| 3938 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3939 | TestLoadTimingReused(load_timing_info2); |
| 3940 | |
| 3941 | // The requests should have the same ID. |
| 3942 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3943 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3944 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3945 | spdy_data.RunFor(1); |
| 3946 | EXPECT_EQ(2, callback.WaitForResult()); |
| 3947 | } |
| 3948 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3949 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3950 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3951 | HttpRequestInfo request; |
| 3952 | request.method = "GET"; |
| 3953 | request.url = GURL("http://www.google.com/"); |
| 3954 | // when the no authentication data flag is set. |
| 3955 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3956 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3957 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3958 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3959 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3960 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3961 | session_deps_.net_log = log.bound().net_log(); |
| 3962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3963 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3964 | // Since we have proxy, should use full url |
| 3965 | MockWrite data_writes1[] = { |
| 3966 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3967 | "Host: www.google.com\r\n" |
| 3968 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3969 | |
| 3970 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3971 | // be issuing -- the final header line contains the credentials. |
| 3972 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3973 | "Host: www.google.com\r\n" |
| 3974 | "Proxy-Connection: keep-alive\r\n" |
| 3975 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3976 | }; |
| 3977 | |
| 3978 | // The proxy responds to the GET with a 407, using a persistent |
| 3979 | // connection. |
| 3980 | MockRead data_reads1[] = { |
| 3981 | // No credentials. |
| 3982 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3983 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3984 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3985 | MockRead("Content-Length: 0\r\n\r\n"), |
| 3986 | |
| 3987 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3988 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3989 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3990 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3991 | }; |
| 3992 | |
| 3993 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3994 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3995 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3996 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3999 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4000 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4001 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4002 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4004 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4005 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4006 | |
| 4007 | rv = callback1.WaitForResult(); |
| 4008 | EXPECT_EQ(OK, rv); |
| 4009 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4010 | LoadTimingInfo load_timing_info; |
| 4011 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4012 | TestLoadTimingNotReused(load_timing_info, |
| 4013 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4014 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4015 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4016 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4017 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4018 | EXPECT_EQ(407, response->headers->response_code()); |
| 4019 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4020 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4022 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4024 | rv = trans->RestartWithAuth( |
| 4025 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4026 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4027 | |
| 4028 | rv = callback2.WaitForResult(); |
| 4029 | EXPECT_EQ(OK, rv); |
| 4030 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4031 | load_timing_info = LoadTimingInfo(); |
| 4032 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4033 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4034 | TestLoadTimingReused(load_timing_info); |
| 4035 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4036 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4037 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4038 | |
| 4039 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4040 | EXPECT_EQ(200, response->headers->response_code()); |
| 4041 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4042 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4043 | |
| 4044 | // The password prompt info should not be set. |
| 4045 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4046 | } |
| 4047 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4048 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4049 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4050 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4051 | request.method = "GET"; |
| 4052 | request.url = GURL("https://www.google.com/"); |
| 4053 | request.load_flags = 0; |
| 4054 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4055 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4056 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4057 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4058 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4059 | // Since we have proxy, should try to establish tunnel. |
| 4060 | MockWrite data_writes[] = { |
| 4061 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4062 | "Host: www.google.com\r\n" |
| 4063 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4064 | }; |
| 4065 | |
| 4066 | MockRead data_reads[] = { |
| 4067 | status, |
| 4068 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4069 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4070 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4071 | }; |
| 4072 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4073 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4074 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4077 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4078 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4079 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4080 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4082 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4084 | |
| 4085 | rv = callback.WaitForResult(); |
| 4086 | EXPECT_EQ(expected_status, rv); |
| 4087 | } |
| 4088 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4089 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4090 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4091 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4092 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4093 | } |
| 4094 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4095 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4096 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4097 | } |
| 4098 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4099 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4100 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4101 | } |
| 4102 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4103 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4104 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4105 | } |
| 4106 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4107 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4108 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4109 | } |
| 4110 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4111 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4112 | ConnectStatusHelper( |
| 4113 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4114 | } |
| 4115 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4116 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4117 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4118 | } |
| 4119 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4120 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4121 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4122 | } |
| 4123 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4124 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4125 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4126 | } |
| 4127 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4128 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4129 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4130 | } |
| 4131 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4132 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4133 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4134 | } |
| 4135 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4136 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4137 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4138 | } |
| 4139 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4140 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4141 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4142 | } |
| 4143 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4144 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4145 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4146 | } |
| 4147 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4148 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4149 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4150 | } |
| 4151 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4152 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4153 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4154 | } |
| 4155 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4156 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4157 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4158 | } |
| 4159 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4160 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4161 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4162 | } |
| 4163 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4164 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4165 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4166 | } |
| 4167 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4168 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4169 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4170 | } |
| 4171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4172 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4173 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4174 | } |
| 4175 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4176 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4177 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4178 | } |
| 4179 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4180 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4181 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4182 | } |
| 4183 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4184 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4185 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4186 | } |
| 4187 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4188 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4189 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4190 | } |
| 4191 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4192 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4193 | ConnectStatusHelperWithExpectedStatus( |
| 4194 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4195 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4196 | } |
| 4197 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4198 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4199 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4200 | } |
| 4201 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4202 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4203 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4204 | } |
| 4205 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4206 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4207 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4208 | } |
| 4209 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4210 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4211 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4212 | } |
| 4213 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4214 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4215 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4216 | } |
| 4217 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4218 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4219 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4220 | } |
| 4221 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4222 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4223 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4224 | } |
| 4225 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4226 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4227 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4228 | } |
| 4229 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4230 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4231 | ConnectStatusHelper( |
| 4232 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4233 | } |
| 4234 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4235 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4236 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4237 | } |
| 4238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4239 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4240 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4241 | } |
| 4242 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4243 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4244 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4245 | } |
| 4246 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4247 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4248 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4249 | } |
| 4250 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4251 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4252 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4253 | } |
| 4254 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4255 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4256 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4257 | } |
| 4258 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4259 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4260 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4261 | } |
| 4262 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4263 | // Test the flow when both the proxy server AND origin server require |
| 4264 | // authentication. Again, this uses basic auth for both since that is |
| 4265 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4266 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4267 | HttpRequestInfo request; |
| 4268 | request.method = "GET"; |
| 4269 | request.url = GURL("http://www.google.com/"); |
| 4270 | request.load_flags = 0; |
| 4271 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4272 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4273 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4274 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4275 | |
| 4276 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4278 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4279 | MockWrite data_writes1[] = { |
| 4280 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4281 | "Host: www.google.com\r\n" |
| 4282 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4283 | }; |
| 4284 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4285 | MockRead data_reads1[] = { |
| 4286 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4287 | // Give a couple authenticate options (only the middle one is actually |
| 4288 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4289 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4290 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4291 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4292 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4293 | // Large content-length -- won't matter, as connection will be reset. |
| 4294 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4295 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4296 | }; |
| 4297 | |
| 4298 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4299 | // request we should be issuing -- the final header line contains the |
| 4300 | // proxy's credentials. |
| 4301 | MockWrite data_writes2[] = { |
| 4302 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4303 | "Host: www.google.com\r\n" |
| 4304 | "Proxy-Connection: keep-alive\r\n" |
| 4305 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4306 | }; |
| 4307 | |
| 4308 | // Now the proxy server lets the request pass through to origin server. |
| 4309 | // The origin server responds with a 401. |
| 4310 | MockRead data_reads2[] = { |
| 4311 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4312 | // Note: We are using the same realm-name as the proxy server. This is |
| 4313 | // completely valid, as realms are unique across hosts. |
| 4314 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4315 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4316 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4317 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4318 | }; |
| 4319 | |
| 4320 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4321 | // the credentials for both the proxy and origin server. |
| 4322 | MockWrite data_writes3[] = { |
| 4323 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4324 | "Host: www.google.com\r\n" |
| 4325 | "Proxy-Connection: keep-alive\r\n" |
| 4326 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4327 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4328 | }; |
| 4329 | |
| 4330 | // Lastly we get the desired content. |
| 4331 | MockRead data_reads3[] = { |
| 4332 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4333 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4334 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4335 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4336 | }; |
| 4337 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4338 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4339 | data_writes1, arraysize(data_writes1)); |
| 4340 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4341 | data_writes2, arraysize(data_writes2)); |
| 4342 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4343 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4344 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4345 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4346 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4348 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4350 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4351 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4352 | |
| 4353 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4354 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4355 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4356 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4357 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4358 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4359 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4360 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4362 | rv = trans->RestartWithAuth( |
| 4363 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4364 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4365 | |
| 4366 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4367 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4368 | |
| 4369 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4370 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4371 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4373 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4375 | rv = trans->RestartWithAuth( |
| 4376 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4378 | |
| 4379 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4380 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4381 | |
| 4382 | response = trans->GetResponseInfo(); |
| 4383 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4384 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4385 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4386 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4387 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4388 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4389 | // authorization headers. |
| 4390 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4391 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4392 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4393 | // bytes in the debugger. |
| 4394 | |
| 4395 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4396 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4397 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4398 | request.method = "GET"; |
| 4399 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4400 | |
| 4401 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4402 | // to other auth schemes. |
| 4403 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4404 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4405 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4406 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4407 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4408 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4409 | MockWrite data_writes1[] = { |
| 4410 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4411 | "Host: 172.22.68.17\r\n" |
| 4412 | "Connection: keep-alive\r\n\r\n"), |
| 4413 | }; |
| 4414 | |
| 4415 | MockRead data_reads1[] = { |
| 4416 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4417 | // Negotiate and NTLM are often requested together. However, we only want |
| 4418 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4419 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4420 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4421 | MockRead("Connection: close\r\n"), |
| 4422 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4423 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4424 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4425 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4426 | }; |
| 4427 | |
| 4428 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4429 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4430 | // request we should be issuing -- the final header line contains a Type |
| 4431 | // 1 message. |
| 4432 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4433 | "Host: 172.22.68.17\r\n" |
| 4434 | "Connection: keep-alive\r\n" |
| 4435 | "Authorization: NTLM " |
| 4436 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4437 | |
| 4438 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4439 | // (the credentials for the origin server). The second request continues |
| 4440 | // on the same connection. |
| 4441 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4442 | "Host: 172.22.68.17\r\n" |
| 4443 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4444 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4445 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4446 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4447 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4448 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4449 | }; |
| 4450 | |
| 4451 | MockRead data_reads2[] = { |
| 4452 | // The origin server responds with a Type 2 message. |
| 4453 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4454 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4455 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4456 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4457 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4458 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4459 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4460 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4461 | "BtAAAAAAA=\r\n"), |
| 4462 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4463 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4464 | MockRead("You are not authorized to view this page\r\n"), |
| 4465 | |
| 4466 | // Lastly we get the desired content. |
| 4467 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4468 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4469 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4470 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4471 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4472 | }; |
| 4473 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4474 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4475 | data_writes1, arraysize(data_writes1)); |
| 4476 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4477 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4478 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4479 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4481 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4482 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4483 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4484 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4486 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4487 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4488 | |
| 4489 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4490 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4491 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4492 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4493 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4494 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4495 | ASSERT_FALSE(response == NULL); |
| 4496 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4498 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4499 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4500 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4501 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4502 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4503 | |
| 4504 | rv = callback2.WaitForResult(); |
| 4505 | EXPECT_EQ(OK, rv); |
| 4506 | |
| 4507 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4508 | |
| 4509 | response = trans->GetResponseInfo(); |
| 4510 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4511 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4513 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4515 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4517 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4518 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4519 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4520 | |
| 4521 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4522 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4523 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4524 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4525 | } |
| 4526 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4527 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4528 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4529 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4530 | request.method = "GET"; |
| 4531 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4532 | request.load_flags = 0; |
| 4533 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4534 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4535 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4536 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4537 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4538 | MockWrite data_writes1[] = { |
| 4539 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4540 | "Host: 172.22.68.17\r\n" |
| 4541 | "Connection: keep-alive\r\n\r\n"), |
| 4542 | }; |
| 4543 | |
| 4544 | MockRead data_reads1[] = { |
| 4545 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4546 | // Negotiate and NTLM are often requested together. However, we only want |
| 4547 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4548 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4549 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4550 | MockRead("Connection: close\r\n"), |
| 4551 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4552 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4553 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4554 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4555 | }; |
| 4556 | |
| 4557 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4558 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4559 | // request we should be issuing -- the final header line contains a Type |
| 4560 | // 1 message. |
| 4561 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4562 | "Host: 172.22.68.17\r\n" |
| 4563 | "Connection: keep-alive\r\n" |
| 4564 | "Authorization: NTLM " |
| 4565 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4566 | |
| 4567 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4568 | // (the credentials for the origin server). The second request continues |
| 4569 | // on the same connection. |
| 4570 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4571 | "Host: 172.22.68.17\r\n" |
| 4572 | "Connection: keep-alive\r\n" |
| 4573 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4574 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4575 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4576 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4577 | "4Ww7b7E=\r\n\r\n"), |
| 4578 | }; |
| 4579 | |
| 4580 | MockRead data_reads2[] = { |
| 4581 | // The origin server responds with a Type 2 message. |
| 4582 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4583 | MockRead("WWW-Authenticate: NTLM " |
| 4584 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4585 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4586 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4587 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4588 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4589 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4590 | "BtAAAAAAA=\r\n"), |
| 4591 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4592 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4593 | MockRead("You are not authorized to view this page\r\n"), |
| 4594 | |
| 4595 | // Wrong password. |
| 4596 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4597 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4598 | MockRead("Connection: close\r\n"), |
| 4599 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4600 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4601 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4602 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4603 | }; |
| 4604 | |
| 4605 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4606 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4607 | // request we should be issuing -- the final header line contains a Type |
| 4608 | // 1 message. |
| 4609 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4610 | "Host: 172.22.68.17\r\n" |
| 4611 | "Connection: keep-alive\r\n" |
| 4612 | "Authorization: NTLM " |
| 4613 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4614 | |
| 4615 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4616 | // (the credentials for the origin server). The second request continues |
| 4617 | // on the same connection. |
| 4618 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4619 | "Host: 172.22.68.17\r\n" |
| 4620 | "Connection: keep-alive\r\n" |
| 4621 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4622 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4623 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4624 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4625 | "+4MUm7c=\r\n\r\n"), |
| 4626 | }; |
| 4627 | |
| 4628 | MockRead data_reads3[] = { |
| 4629 | // The origin server responds with a Type 2 message. |
| 4630 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4631 | MockRead("WWW-Authenticate: NTLM " |
| 4632 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4633 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4634 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4635 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4636 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4637 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4638 | "BtAAAAAAA=\r\n"), |
| 4639 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4640 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4641 | MockRead("You are not authorized to view this page\r\n"), |
| 4642 | |
| 4643 | // Lastly we get the desired content. |
| 4644 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4645 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4646 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4647 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4648 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4649 | }; |
| 4650 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4651 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4652 | data_writes1, arraysize(data_writes1)); |
| 4653 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4654 | data_writes2, arraysize(data_writes2)); |
| 4655 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4656 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4657 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4658 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4659 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4661 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4662 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4663 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4664 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4666 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4667 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4668 | |
| 4669 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4670 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4671 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4672 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4673 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4674 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4675 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4676 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4677 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4678 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4679 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4680 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4681 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4682 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4683 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4684 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4685 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4686 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4687 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4688 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4689 | TestCompletionCallback callback3; |
| 4690 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4691 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4692 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4693 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4694 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4695 | |
| 4696 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4697 | ASSERT_FALSE(response == NULL); |
| 4698 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4700 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4701 | |
| 4702 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4703 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4704 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4705 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4706 | |
| 4707 | rv = callback4.WaitForResult(); |
| 4708 | EXPECT_EQ(OK, rv); |
| 4709 | |
| 4710 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4712 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4713 | |
| 4714 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4715 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4716 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4717 | |
| 4718 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4719 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4720 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4721 | response = trans->GetResponseInfo(); |
| 4722 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4723 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4724 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4725 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4726 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4727 | // Test reading a server response which has only headers, and no body. |
| 4728 | // After some maximum number of bytes is consumed, the transaction should |
| 4729 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4730 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4731 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4732 | request.method = "GET"; |
| 4733 | request.url = GURL("http://www.google.com/"); |
| 4734 | request.load_flags = 0; |
| 4735 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4736 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4737 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4738 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4739 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4740 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4741 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4742 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4743 | |
| 4744 | MockRead data_reads[] = { |
| 4745 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4746 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4747 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4748 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4749 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4750 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4753 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4755 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4757 | |
| 4758 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4759 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4760 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4761 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4762 | EXPECT_TRUE(response == NULL); |
| 4763 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4764 | |
| 4765 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4766 | // establish tunnel. |
| 4767 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4768 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4769 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4770 | HttpRequestInfo request; |
| 4771 | request.method = "GET"; |
| 4772 | request.url = GURL("https://www.google.com/"); |
| 4773 | request.load_flags = 0; |
| 4774 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4775 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4776 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 4777 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4778 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4779 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4780 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4782 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4783 | // Since we have proxy, should try to establish tunnel. |
| 4784 | MockWrite data_writes1[] = { |
| 4785 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4786 | "Host: www.google.com\r\n" |
| 4787 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4788 | }; |
| 4789 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 4790 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4791 | // connection. Usually a proxy would return 501 (not implemented), |
| 4792 | // or 200 (tunnel established). |
| 4793 | MockRead data_reads1[] = { |
| 4794 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 4795 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4796 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4797 | }; |
| 4798 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4799 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4800 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4803 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4805 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4806 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4807 | |
| 4808 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4809 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4810 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4811 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4812 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4813 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4814 | // Empty the current queue. This is necessary because idle sockets are |
| 4815 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4816 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 4817 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4818 | // We now check to make sure the TCPClientSocket was not added back to |
| 4819 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4820 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4821 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4822 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4823 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4824 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4825 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 4826 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4827 | // 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] | 4828 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4829 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4830 | request.method = "GET"; |
| 4831 | request.url = GURL("http://www.google.com/"); |
| 4832 | request.load_flags = 0; |
| 4833 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4834 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4835 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4836 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4838 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4839 | MockRead data_reads[] = { |
| 4840 | // A part of the response body is received with the response headers. |
| 4841 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 4842 | // The rest of the response body is received in two parts. |
| 4843 | MockRead("lo"), |
| 4844 | MockRead(" world"), |
| 4845 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4847 | }; |
| 4848 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4849 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4850 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4852 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4853 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4854 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4856 | |
| 4857 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4858 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4859 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4860 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4861 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4862 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4863 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4864 | std::string status_line = response->headers->GetStatusLine(); |
| 4865 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 4866 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4867 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4868 | |
| 4869 | std::string response_data; |
| 4870 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4871 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4872 | EXPECT_EQ("hello world", response_data); |
| 4873 | |
| 4874 | // Empty the current queue. This is necessary because idle sockets are |
| 4875 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4876 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4877 | |
| 4878 | // 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] | 4879 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 4880 | } |
| 4881 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4882 | // Make sure that we recycle a SSL socket after reading all of the response |
| 4883 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4884 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4885 | HttpRequestInfo request; |
| 4886 | request.method = "GET"; |
| 4887 | request.url = GURL("https://www.google.com/"); |
| 4888 | request.load_flags = 0; |
| 4889 | |
| 4890 | MockWrite data_writes[] = { |
| 4891 | MockWrite("GET / HTTP/1.1\r\n" |
| 4892 | "Host: www.google.com\r\n" |
| 4893 | "Connection: keep-alive\r\n\r\n"), |
| 4894 | }; |
| 4895 | |
| 4896 | MockRead data_reads[] = { |
| 4897 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4898 | MockRead("Content-Length: 11\r\n\r\n"), |
| 4899 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4900 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4901 | }; |
| 4902 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4903 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4905 | |
| 4906 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4907 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4910 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4911 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4912 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4913 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4914 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4916 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4917 | |
| 4918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4919 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4920 | |
| 4921 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4922 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4923 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4924 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4925 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4926 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4927 | |
| 4928 | std::string response_data; |
| 4929 | rv = ReadTransaction(trans.get(), &response_data); |
| 4930 | EXPECT_EQ(OK, rv); |
| 4931 | EXPECT_EQ("hello world", response_data); |
| 4932 | |
| 4933 | // Empty the current queue. This is necessary because idle sockets are |
| 4934 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 4935 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4936 | |
| 4937 | // 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] | 4938 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 4942 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4943 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4944 | HttpRequestInfo request; |
| 4945 | request.method = "GET"; |
| 4946 | request.url = GURL("https://www.google.com/"); |
| 4947 | request.load_flags = 0; |
| 4948 | |
| 4949 | MockWrite data_writes[] = { |
| 4950 | MockWrite("GET / HTTP/1.1\r\n" |
| 4951 | "Host: www.google.com\r\n" |
| 4952 | "Connection: keep-alive\r\n\r\n"), |
| 4953 | MockWrite("GET / HTTP/1.1\r\n" |
| 4954 | "Host: www.google.com\r\n" |
| 4955 | "Connection: keep-alive\r\n\r\n"), |
| 4956 | }; |
| 4957 | |
| 4958 | MockRead data_reads[] = { |
| 4959 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4960 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4961 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4962 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4963 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4964 | }; |
| 4965 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4966 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4967 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4970 | |
| 4971 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4972 | data_writes, arraysize(data_writes)); |
| 4973 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 4974 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4975 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4976 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4978 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4979 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4980 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4981 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4982 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4984 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4985 | |
| 4986 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4987 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 4988 | |
| 4989 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4990 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4991 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4992 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4993 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4994 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 4995 | |
| 4996 | std::string response_data; |
| 4997 | rv = ReadTransaction(trans.get(), &response_data); |
| 4998 | EXPECT_EQ(OK, rv); |
| 4999 | EXPECT_EQ("hello world", response_data); |
| 5000 | |
| 5001 | // Empty the current queue. This is necessary because idle sockets are |
| 5002 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5003 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5004 | |
| 5005 | // 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] | 5006 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5007 | |
| 5008 | // Now start the second transaction, which should reuse the previous socket. |
| 5009 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5010 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5012 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5013 | |
| 5014 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5015 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5016 | |
| 5017 | response = trans->GetResponseInfo(); |
| 5018 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5019 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5020 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5021 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5022 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5023 | |
| 5024 | rv = ReadTransaction(trans.get(), &response_data); |
| 5025 | EXPECT_EQ(OK, rv); |
| 5026 | EXPECT_EQ("hello world", response_data); |
| 5027 | |
| 5028 | // Empty the current queue. This is necessary because idle sockets are |
| 5029 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5030 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5031 | |
| 5032 | // 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] | 5033 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5034 | } |
| 5035 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5036 | // Make sure that we recycle a socket after a zero-length response. |
| 5037 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5038 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5039 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5040 | request.method = "GET"; |
| 5041 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 5042 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5043 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5044 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 5045 | request.load_flags = 0; |
| 5046 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5047 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5048 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5049 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5051 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5052 | MockRead data_reads[] = { |
| 5053 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5054 | "Content-Length: 0\r\n" |
| 5055 | "Content-Type: text/html\r\n\r\n"), |
| 5056 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5057 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5058 | }; |
| 5059 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5060 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5063 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5065 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5067 | |
| 5068 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5069 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5070 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5071 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5072 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5073 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5074 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5075 | std::string status_line = response->headers->GetStatusLine(); |
| 5076 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5077 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5078 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5079 | |
| 5080 | std::string response_data; |
| 5081 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5082 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5083 | EXPECT_EQ("", response_data); |
| 5084 | |
| 5085 | // Empty the current queue. This is necessary because idle sockets are |
| 5086 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5087 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5088 | |
| 5089 | // 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] | 5090 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5091 | } |
| 5092 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5093 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5094 | ScopedVector<UploadElementReader> element_readers; |
| 5095 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5096 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5097 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5098 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5099 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5100 | // after use. |
| 5101 | request[0].method = "GET"; |
| 5102 | request[0].url = GURL("http://www.google.com/"); |
| 5103 | request[0].load_flags = 0; |
| 5104 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5105 | // transaction 1. The first attempts fails when writing the POST data. |
| 5106 | // This causes the transaction to retry with a new socket. The second |
| 5107 | // attempt succeeds. |
| 5108 | request[1].method = "POST"; |
| 5109 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5110 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5111 | request[1].load_flags = 0; |
| 5112 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5113 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5114 | |
| 5115 | // The first socket is used for transaction 1 and the first attempt of |
| 5116 | // transaction 2. |
| 5117 | |
| 5118 | // The response of transaction 1. |
| 5119 | MockRead data_reads1[] = { |
| 5120 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5121 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5122 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5123 | }; |
| 5124 | // The mock write results of transaction 1 and the first attempt of |
| 5125 | // transaction 2. |
| 5126 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5127 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5128 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5129 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5130 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5131 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5132 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5133 | |
| 5134 | // The second socket is used for the second attempt of transaction 2. |
| 5135 | |
| 5136 | // The response of transaction 2. |
| 5137 | MockRead data_reads2[] = { |
| 5138 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5139 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5140 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5141 | }; |
| 5142 | // The mock write results of the second attempt of transaction 2. |
| 5143 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5144 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5145 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5146 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5147 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5148 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5149 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5150 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5151 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5152 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5153 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5154 | "hello world", "welcome" |
| 5155 | }; |
| 5156 | |
| 5157 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5158 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5159 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5161 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5163 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5165 | |
| 5166 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5167 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5168 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5170 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5171 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5172 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5173 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5174 | |
| 5175 | std::string response_data; |
| 5176 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5177 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5178 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5179 | } |
| 5180 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5181 | |
| 5182 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5183 | // an identity in the URL. The request should be sent as normal, but when |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5184 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5185 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5186 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5187 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5188 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5189 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5190 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5191 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5192 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5194 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5195 | // The password contains an escaped character -- for this test to pass it |
| 5196 | // will need to be unescaped by HttpNetworkTransaction. |
| 5197 | EXPECT_EQ("b%40r", request.url.password()); |
| 5198 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5199 | MockWrite data_writes1[] = { |
| 5200 | MockWrite("GET / HTTP/1.1\r\n" |
| 5201 | "Host: www.google.com\r\n" |
| 5202 | "Connection: keep-alive\r\n\r\n"), |
| 5203 | }; |
| 5204 | |
| 5205 | MockRead data_reads1[] = { |
| 5206 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5207 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5208 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5209 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5210 | }; |
| 5211 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5212 | // After the challenge above, the transaction will be restarted using the |
| 5213 | // identity from the url (foo, b@r) to answer the challenge. |
| 5214 | MockWrite data_writes2[] = { |
| 5215 | MockWrite("GET / HTTP/1.1\r\n" |
| 5216 | "Host: www.google.com\r\n" |
| 5217 | "Connection: keep-alive\r\n" |
| 5218 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 5219 | }; |
| 5220 | |
| 5221 | MockRead data_reads2[] = { |
| 5222 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5223 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5224 | MockRead(SYNCHRONOUS, OK), |
| 5225 | }; |
| 5226 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5227 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5228 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5229 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5230 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5231 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5232 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5234 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5235 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5236 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5237 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5238 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5239 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5240 | |
| 5241 | TestCompletionCallback callback2; |
| 5242 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5244 | rv = callback2.WaitForResult(); |
| 5245 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5246 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5247 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5248 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5249 | ASSERT_TRUE(response != NULL); |
| 5250 | |
| 5251 | // There is no challenge info, since the identity in URL worked. |
| 5252 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5253 | |
| 5254 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5255 | |
| 5256 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5257 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5261 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5262 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5263 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5264 | HttpRequestInfo request; |
| 5265 | request.method = "GET"; |
| 5266 | // Note: the URL has a username:password in it. The password "baz" is |
| 5267 | // wrong (should be "bar"). |
| 5268 | request.url = GURL("http://foo:[email protected]/"); |
| 5269 | |
| 5270 | request.load_flags = LOAD_NORMAL; |
| 5271 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5272 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5273 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5274 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5275 | |
| 5276 | MockWrite data_writes1[] = { |
| 5277 | MockWrite("GET / HTTP/1.1\r\n" |
| 5278 | "Host: www.google.com\r\n" |
| 5279 | "Connection: keep-alive\r\n\r\n"), |
| 5280 | }; |
| 5281 | |
| 5282 | MockRead data_reads1[] = { |
| 5283 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5284 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5285 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5286 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5287 | }; |
| 5288 | |
| 5289 | // After the challenge above, the transaction will be restarted using the |
| 5290 | // identity from the url (foo, baz) to answer the challenge. |
| 5291 | MockWrite data_writes2[] = { |
| 5292 | MockWrite("GET / HTTP/1.1\r\n" |
| 5293 | "Host: www.google.com\r\n" |
| 5294 | "Connection: keep-alive\r\n" |
| 5295 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 5296 | }; |
| 5297 | |
| 5298 | MockRead data_reads2[] = { |
| 5299 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5300 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5301 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5302 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5303 | }; |
| 5304 | |
| 5305 | // After the challenge above, the transaction will be restarted using the |
| 5306 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5307 | MockWrite data_writes3[] = { |
| 5308 | MockWrite("GET / HTTP/1.1\r\n" |
| 5309 | "Host: www.google.com\r\n" |
| 5310 | "Connection: keep-alive\r\n" |
| 5311 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5312 | }; |
| 5313 | |
| 5314 | MockRead data_reads3[] = { |
| 5315 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5316 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5317 | MockRead(SYNCHRONOUS, OK), |
| 5318 | }; |
| 5319 | |
| 5320 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5321 | data_writes1, arraysize(data_writes1)); |
| 5322 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5323 | data_writes2, arraysize(data_writes2)); |
| 5324 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5325 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5326 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5327 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5328 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5329 | |
| 5330 | TestCompletionCallback callback1; |
| 5331 | |
| 5332 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5333 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5334 | |
| 5335 | rv = callback1.WaitForResult(); |
| 5336 | EXPECT_EQ(OK, rv); |
| 5337 | |
| 5338 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5339 | TestCompletionCallback callback2; |
| 5340 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5342 | rv = callback2.WaitForResult(); |
| 5343 | EXPECT_EQ(OK, rv); |
| 5344 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5345 | |
| 5346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5347 | ASSERT_TRUE(response != NULL); |
| 5348 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5349 | |
| 5350 | TestCompletionCallback callback3; |
| 5351 | rv = trans->RestartWithAuth( |
| 5352 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5354 | rv = callback3.WaitForResult(); |
| 5355 | EXPECT_EQ(OK, rv); |
| 5356 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5357 | |
| 5358 | response = trans->GetResponseInfo(); |
| 5359 | ASSERT_TRUE(response != NULL); |
| 5360 | |
| 5361 | // There is no challenge info, since the identity worked. |
| 5362 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5363 | |
| 5364 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5365 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5366 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5367 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5368 | } |
| 5369 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5370 | |
| 5371 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5372 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5373 | // from the URL should never be used. |
| 5374 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5375 | HttpRequestInfo request; |
| 5376 | request.method = "GET"; |
| 5377 | request.url = GURL("http://foo:[email protected]/"); |
| 5378 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5379 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5380 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5381 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5382 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5383 | |
| 5384 | MockWrite data_writes1[] = { |
| 5385 | MockWrite("GET / HTTP/1.1\r\n" |
| 5386 | "Host: www.google.com\r\n" |
| 5387 | "Connection: keep-alive\r\n\r\n"), |
| 5388 | }; |
| 5389 | |
| 5390 | MockRead data_reads1[] = { |
| 5391 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5392 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5393 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5394 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5395 | }; |
| 5396 | |
| 5397 | // After the challenge above, the transaction will be restarted using the |
| 5398 | // identity supplied by the user, not the one in the URL, to answer the |
| 5399 | // challenge. |
| 5400 | MockWrite data_writes3[] = { |
| 5401 | MockWrite("GET / HTTP/1.1\r\n" |
| 5402 | "Host: www.google.com\r\n" |
| 5403 | "Connection: keep-alive\r\n" |
| 5404 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5405 | }; |
| 5406 | |
| 5407 | MockRead data_reads3[] = { |
| 5408 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5409 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5410 | MockRead(SYNCHRONOUS, OK), |
| 5411 | }; |
| 5412 | |
| 5413 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5414 | data_writes1, arraysize(data_writes1)); |
| 5415 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5416 | data_writes3, arraysize(data_writes3)); |
| 5417 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5418 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5419 | |
| 5420 | TestCompletionCallback callback1; |
| 5421 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5422 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5423 | rv = callback1.WaitForResult(); |
| 5424 | EXPECT_EQ(OK, rv); |
| 5425 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5426 | |
| 5427 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5428 | ASSERT_TRUE(response != NULL); |
| 5429 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5430 | |
| 5431 | TestCompletionCallback callback3; |
| 5432 | rv = trans->RestartWithAuth( |
| 5433 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5434 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5435 | rv = callback3.WaitForResult(); |
| 5436 | EXPECT_EQ(OK, rv); |
| 5437 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5438 | |
| 5439 | response = trans->GetResponseInfo(); |
| 5440 | ASSERT_TRUE(response != NULL); |
| 5441 | |
| 5442 | // There is no challenge info, since the identity worked. |
| 5443 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5444 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5445 | |
| 5446 | // Empty the current queue. |
| 5447 | base::MessageLoop::current()->RunUntilIdle(); |
| 5448 | } |
| 5449 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5450 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5451 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5452 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5453 | |
| 5454 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5455 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5456 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5457 | request.method = "GET"; |
| 5458 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5459 | request.load_flags = 0; |
| 5460 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5461 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5462 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5463 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5464 | MockWrite data_writes1[] = { |
| 5465 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5466 | "Host: www.google.com\r\n" |
| 5467 | "Connection: keep-alive\r\n\r\n"), |
| 5468 | }; |
| 5469 | |
| 5470 | MockRead data_reads1[] = { |
| 5471 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5472 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5473 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5474 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5475 | }; |
| 5476 | |
| 5477 | // Resend with authorization (username=foo, password=bar) |
| 5478 | MockWrite data_writes2[] = { |
| 5479 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5480 | "Host: www.google.com\r\n" |
| 5481 | "Connection: keep-alive\r\n" |
| 5482 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5483 | }; |
| 5484 | |
| 5485 | // Sever accepts the authorization. |
| 5486 | MockRead data_reads2[] = { |
| 5487 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5488 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5489 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5490 | }; |
| 5491 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5492 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5493 | data_writes1, arraysize(data_writes1)); |
| 5494 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5495 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5497 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5499 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5501 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5502 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5503 | |
| 5504 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5505 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5506 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5508 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5509 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5510 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5511 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5513 | rv = trans->RestartWithAuth( |
| 5514 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5516 | |
| 5517 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5518 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5519 | |
| 5520 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5521 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5522 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5523 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5524 | } |
| 5525 | |
| 5526 | // ------------------------------------------------------------------------ |
| 5527 | |
| 5528 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5529 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5530 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5531 | request.method = "GET"; |
| 5532 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5533 | // protection space as MyRealm1. |
| 5534 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5535 | request.load_flags = 0; |
| 5536 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5537 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5538 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5539 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5540 | MockWrite data_writes1[] = { |
| 5541 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5542 | "Host: www.google.com\r\n" |
| 5543 | "Connection: keep-alive\r\n" |
| 5544 | // Send preemptive authorization for MyRealm1 |
| 5545 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5546 | }; |
| 5547 | |
| 5548 | // The server didn't like the preemptive authorization, and |
| 5549 | // challenges us for a different realm (MyRealm2). |
| 5550 | MockRead data_reads1[] = { |
| 5551 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5552 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5553 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5554 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5555 | }; |
| 5556 | |
| 5557 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5558 | MockWrite data_writes2[] = { |
| 5559 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5560 | "Host: www.google.com\r\n" |
| 5561 | "Connection: keep-alive\r\n" |
| 5562 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 5563 | }; |
| 5564 | |
| 5565 | // Sever accepts the authorization. |
| 5566 | MockRead data_reads2[] = { |
| 5567 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5568 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5569 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5570 | }; |
| 5571 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5572 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5573 | data_writes1, arraysize(data_writes1)); |
| 5574 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5575 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5576 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5577 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5579 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5581 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5582 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5583 | |
| 5584 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5585 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5586 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5587 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5588 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5589 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5590 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 5591 | EXPECT_EQ("www.google.com:80", |
| 5592 | response->auth_challenge->challenger.ToString()); |
| 5593 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5594 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5596 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5598 | rv = trans->RestartWithAuth( |
| 5599 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5601 | |
| 5602 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5603 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5604 | |
| 5605 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5606 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5607 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5608 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5609 | } |
| 5610 | |
| 5611 | // ------------------------------------------------------------------------ |
| 5612 | |
| 5613 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5614 | // succeed with preemptive authorization. |
| 5615 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5616 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5617 | request.method = "GET"; |
| 5618 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 5619 | request.load_flags = 0; |
| 5620 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5621 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5622 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5623 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5624 | MockWrite data_writes1[] = { |
| 5625 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 5626 | "Host: www.google.com\r\n" |
| 5627 | "Connection: keep-alive\r\n" |
| 5628 | // The authorization for MyRealm1 gets sent preemptively |
| 5629 | // (since the url is in the same protection space) |
| 5630 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5631 | }; |
| 5632 | |
| 5633 | // Sever accepts the preemptive authorization |
| 5634 | MockRead data_reads1[] = { |
| 5635 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5636 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5637 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5638 | }; |
| 5639 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5640 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5641 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5642 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5644 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5646 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5647 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5648 | |
| 5649 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5650 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5651 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5652 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5653 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5654 | |
| 5655 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5656 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5657 | } |
| 5658 | |
| 5659 | // ------------------------------------------------------------------------ |
| 5660 | |
| 5661 | // Transaction 4: request another URL in MyRealm (however the |
| 5662 | // url is not known to belong to the protection space, so no pre-auth). |
| 5663 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5664 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5665 | request.method = "GET"; |
| 5666 | request.url = GURL("http://www.google.com/x/1"); |
| 5667 | request.load_flags = 0; |
| 5668 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5669 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5670 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5671 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5672 | MockWrite data_writes1[] = { |
| 5673 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5674 | "Host: www.google.com\r\n" |
| 5675 | "Connection: keep-alive\r\n\r\n"), |
| 5676 | }; |
| 5677 | |
| 5678 | MockRead data_reads1[] = { |
| 5679 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5680 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5681 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5682 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5683 | }; |
| 5684 | |
| 5685 | // Resend with authorization from MyRealm's cache. |
| 5686 | MockWrite data_writes2[] = { |
| 5687 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5688 | "Host: www.google.com\r\n" |
| 5689 | "Connection: keep-alive\r\n" |
| 5690 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5691 | }; |
| 5692 | |
| 5693 | // Sever accepts the authorization. |
| 5694 | MockRead data_reads2[] = { |
| 5695 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5696 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5697 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5698 | }; |
| 5699 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5700 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5701 | data_writes1, arraysize(data_writes1)); |
| 5702 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5703 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5704 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5705 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5707 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5709 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5711 | |
| 5712 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5713 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5714 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5715 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5716 | TestCompletionCallback callback2; |
| 5717 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5718 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5719 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5720 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5721 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5722 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5723 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5724 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5725 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5726 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5727 | } |
| 5728 | |
| 5729 | // ------------------------------------------------------------------------ |
| 5730 | |
| 5731 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5732 | // cached identity. Should invalidate and re-prompt. |
| 5733 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5734 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5735 | request.method = "GET"; |
| 5736 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5737 | request.load_flags = 0; |
| 5738 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5739 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5740 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5741 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5742 | MockWrite data_writes1[] = { |
| 5743 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5744 | "Host: www.google.com\r\n" |
| 5745 | "Connection: keep-alive\r\n\r\n"), |
| 5746 | }; |
| 5747 | |
| 5748 | MockRead data_reads1[] = { |
| 5749 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5750 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5751 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5752 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5753 | }; |
| 5754 | |
| 5755 | // Resend with authorization from cache for MyRealm. |
| 5756 | MockWrite data_writes2[] = { |
| 5757 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5758 | "Host: www.google.com\r\n" |
| 5759 | "Connection: keep-alive\r\n" |
| 5760 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5761 | }; |
| 5762 | |
| 5763 | // Sever rejects the authorization. |
| 5764 | MockRead data_reads2[] = { |
| 5765 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5766 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5767 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5768 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5769 | }; |
| 5770 | |
| 5771 | // At this point we should prompt for new credentials for MyRealm. |
| 5772 | // Restart with username=foo3, password=foo4. |
| 5773 | MockWrite data_writes3[] = { |
| 5774 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5775 | "Host: www.google.com\r\n" |
| 5776 | "Connection: keep-alive\r\n" |
| 5777 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 5778 | }; |
| 5779 | |
| 5780 | // Sever accepts the authorization. |
| 5781 | MockRead data_reads3[] = { |
| 5782 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5783 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5784 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5785 | }; |
| 5786 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5787 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5788 | data_writes1, arraysize(data_writes1)); |
| 5789 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5790 | data_writes2, arraysize(data_writes2)); |
| 5791 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5792 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5793 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5794 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5795 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5796 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5797 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5799 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5801 | |
| 5802 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5803 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5804 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5805 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5806 | TestCompletionCallback callback2; |
| 5807 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5808 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5809 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5810 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5811 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5812 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5814 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5815 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5817 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5819 | rv = trans->RestartWithAuth( |
| 5820 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5822 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5823 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5824 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5825 | |
| 5826 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5827 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5828 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5829 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5830 | } |
| 5831 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5832 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5833 | // Tests that nonce count increments when multiple auth attempts |
| 5834 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5835 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 5836 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 5837 | new HttpAuthHandlerDigest::Factory(); |
| 5838 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 5839 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 5840 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5841 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 5842 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5843 | |
| 5844 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5845 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5846 | HttpRequestInfo request; |
| 5847 | request.method = "GET"; |
| 5848 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5849 | request.load_flags = 0; |
| 5850 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5851 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5852 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5853 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5854 | MockWrite data_writes1[] = { |
| 5855 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5856 | "Host: www.google.com\r\n" |
| 5857 | "Connection: keep-alive\r\n\r\n"), |
| 5858 | }; |
| 5859 | |
| 5860 | MockRead data_reads1[] = { |
| 5861 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5862 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 5863 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5864 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5865 | }; |
| 5866 | |
| 5867 | // Resend with authorization (username=foo, password=bar) |
| 5868 | MockWrite data_writes2[] = { |
| 5869 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5870 | "Host: www.google.com\r\n" |
| 5871 | "Connection: keep-alive\r\n" |
| 5872 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5873 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 5874 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 5875 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5876 | }; |
| 5877 | |
| 5878 | // Sever accepts the authorization. |
| 5879 | MockRead data_reads2[] = { |
| 5880 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5881 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5882 | }; |
| 5883 | |
| 5884 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5885 | data_writes1, arraysize(data_writes1)); |
| 5886 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5887 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5888 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5889 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5891 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5893 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5895 | |
| 5896 | rv = callback1.WaitForResult(); |
| 5897 | EXPECT_EQ(OK, rv); |
| 5898 | |
| 5899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5900 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5901 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5903 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5905 | rv = trans->RestartWithAuth( |
| 5906 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5907 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5908 | |
| 5909 | rv = callback2.WaitForResult(); |
| 5910 | EXPECT_EQ(OK, rv); |
| 5911 | |
| 5912 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5913 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5914 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5915 | } |
| 5916 | |
| 5917 | // ------------------------------------------------------------------------ |
| 5918 | |
| 5919 | // Transaction 2: Request another resource in digestive's protection space. |
| 5920 | // This will preemptively add an Authorization header which should have an |
| 5921 | // "nc" value of 2 (as compared to 1 in the first use. |
| 5922 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5923 | HttpRequestInfo request; |
| 5924 | request.method = "GET"; |
| 5925 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5926 | // protection space as digest. |
| 5927 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5928 | request.load_flags = 0; |
| 5929 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5930 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5931 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5932 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5933 | MockWrite data_writes1[] = { |
| 5934 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5935 | "Host: www.google.com\r\n" |
| 5936 | "Connection: keep-alive\r\n" |
| 5937 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 5938 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 5939 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 5940 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 5941 | }; |
| 5942 | |
| 5943 | // Sever accepts the authorization. |
| 5944 | MockRead data_reads1[] = { |
| 5945 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5946 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5948 | }; |
| 5949 | |
| 5950 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5951 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5954 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5956 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5957 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5958 | |
| 5959 | rv = callback1.WaitForResult(); |
| 5960 | EXPECT_EQ(OK, rv); |
| 5961 | |
| 5962 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5963 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 5964 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5965 | } |
| 5966 | } |
| 5967 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5968 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5969 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5970 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5971 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 5972 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5974 | |
| 5975 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5976 | trans->read_buf_ = new IOBuffer(15); |
| 5977 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 5978 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5979 | |
| 5980 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 5981 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5982 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 5983 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 5984 | response->response_time = base::Time::Now(); |
| 5985 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5986 | |
| 5987 | { // Setup state for response_.vary_data |
| 5988 | HttpRequestInfo request; |
| 5989 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 5990 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 5991 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 5992 | request.extra_headers.SetHeader("Foo", "1"); |
| 5993 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5994 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | // Cause the above state to be reset. |
| 5998 | trans->ResetStateForRestart(); |
| 5999 | |
| 6000 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6001 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6002 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6003 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6004 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6005 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6006 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6007 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6008 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6009 | } |
| 6010 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6011 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6012 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6013 | HttpRequestInfo request; |
| 6014 | request.method = "GET"; |
| 6015 | request.url = GURL("https://www.google.com/"); |
| 6016 | request.load_flags = 0; |
| 6017 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6018 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6019 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6021 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6022 | MockWrite data_writes[] = { |
| 6023 | MockWrite("GET / HTTP/1.1\r\n" |
| 6024 | "Host: www.google.com\r\n" |
| 6025 | "Connection: keep-alive\r\n\r\n"), |
| 6026 | }; |
| 6027 | |
| 6028 | MockRead data_reads[] = { |
| 6029 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6030 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6031 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6032 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6033 | }; |
| 6034 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6035 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6037 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6038 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6039 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6040 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6041 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6042 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6043 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6046 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6048 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6050 | |
| 6051 | rv = callback.WaitForResult(); |
| 6052 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6054 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6055 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6056 | |
| 6057 | rv = callback.WaitForResult(); |
| 6058 | EXPECT_EQ(OK, rv); |
| 6059 | |
| 6060 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6061 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6062 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6063 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6064 | } |
| 6065 | |
| 6066 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6067 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6068 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6069 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6070 | |
| 6071 | HttpRequestInfo request; |
| 6072 | request.method = "GET"; |
| 6073 | request.url = GURL("https://www.google.com/"); |
| 6074 | request.load_flags = 0; |
| 6075 | |
| 6076 | MockWrite proxy_writes[] = { |
| 6077 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6078 | "Host: www.google.com\r\n" |
| 6079 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6080 | }; |
| 6081 | |
| 6082 | MockRead proxy_reads[] = { |
| 6083 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6084 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6085 | }; |
| 6086 | |
| 6087 | MockWrite data_writes[] = { |
| 6088 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6089 | "Host: www.google.com\r\n" |
| 6090 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6091 | MockWrite("GET / HTTP/1.1\r\n" |
| 6092 | "Host: www.google.com\r\n" |
| 6093 | "Connection: keep-alive\r\n\r\n"), |
| 6094 | }; |
| 6095 | |
| 6096 | MockRead data_reads[] = { |
| 6097 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6098 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6099 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6100 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6101 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6102 | }; |
| 6103 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6104 | StaticSocketDataProvider ssl_bad_certificate( |
| 6105 | proxy_reads, arraysize(proxy_reads), |
| 6106 | proxy_writes, arraysize(proxy_writes)); |
| 6107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6108 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6109 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6110 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6111 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6112 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6113 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6117 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6118 | |
| 6119 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6120 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6121 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6122 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6123 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6124 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6125 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6126 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6127 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6128 | |
| 6129 | rv = callback.WaitForResult(); |
| 6130 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6132 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6134 | |
| 6135 | rv = callback.WaitForResult(); |
| 6136 | EXPECT_EQ(OK, rv); |
| 6137 | |
| 6138 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6139 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6140 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6141 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6142 | } |
| 6143 | } |
| 6144 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6145 | |
| 6146 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6147 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6148 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6149 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6150 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6151 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6152 | |
| 6153 | HttpRequestInfo request; |
| 6154 | request.method = "GET"; |
| 6155 | request.url = GURL("https://www.google.com/"); |
| 6156 | request.load_flags = 0; |
| 6157 | |
| 6158 | MockWrite data_writes[] = { |
| 6159 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6160 | "Host: www.google.com\r\n" |
| 6161 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6162 | MockWrite("GET / HTTP/1.1\r\n" |
| 6163 | "Host: www.google.com\r\n" |
| 6164 | "Connection: keep-alive\r\n\r\n"), |
| 6165 | }; |
| 6166 | |
| 6167 | MockRead data_reads[] = { |
| 6168 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6169 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6170 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6171 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6172 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6173 | }; |
| 6174 | |
| 6175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6176 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6177 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6178 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6179 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6181 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6184 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6185 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6186 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6187 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6188 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6190 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6191 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6192 | |
| 6193 | rv = callback.WaitForResult(); |
| 6194 | EXPECT_EQ(OK, rv); |
| 6195 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6196 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6197 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6198 | |
| 6199 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6200 | EXPECT_EQ(200, response->headers->response_code()); |
| 6201 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6202 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6203 | |
| 6204 | LoadTimingInfo load_timing_info; |
| 6205 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6206 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6207 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6208 | } |
| 6209 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6210 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6211 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6212 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6213 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6214 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6215 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6216 | |
| 6217 | HttpRequestInfo request; |
| 6218 | request.method = "GET"; |
| 6219 | request.url = GURL("https://www.google.com/"); |
| 6220 | request.load_flags = 0; |
| 6221 | |
| 6222 | MockWrite data_writes[] = { |
| 6223 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6224 | "Host: www.google.com\r\n" |
| 6225 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6226 | }; |
| 6227 | |
| 6228 | MockRead data_reads[] = { |
| 6229 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6230 | MockRead("Location: http://login.example.com/\r\n"), |
| 6231 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6232 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6233 | }; |
| 6234 | |
| 6235 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6236 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6237 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6238 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6242 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6243 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6244 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6245 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6248 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6250 | |
| 6251 | rv = callback.WaitForResult(); |
| 6252 | EXPECT_EQ(OK, rv); |
| 6253 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6254 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6255 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6256 | |
| 6257 | EXPECT_EQ(302, response->headers->response_code()); |
| 6258 | std::string url; |
| 6259 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6260 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6261 | |
| 6262 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6263 | // timing for the proxy connection instead of the connection to the host, |
| 6264 | // and no send / receive times. |
| 6265 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6266 | LoadTimingInfo load_timing_info; |
| 6267 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6268 | |
| 6269 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 6270 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 6271 | |
| 6272 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6273 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6274 | load_timing_info.proxy_resolve_end); |
| 6275 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6276 | load_timing_info.connect_timing.connect_start); |
| 6277 | ExpectConnectTimingHasTimes( |
| 6278 | load_timing_info.connect_timing, |
| 6279 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6280 | |
| 6281 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6282 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6283 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6287 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6288 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6289 | ProxyService::CreateFixed("https://proxy:70")); |
| 6290 | |
| 6291 | HttpRequestInfo request; |
| 6292 | request.method = "GET"; |
| 6293 | request.url = GURL("https://www.google.com/"); |
| 6294 | request.load_flags = 0; |
| 6295 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6296 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6297 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6298 | scoped_ptr<SpdyFrame> goaway( |
| 6299 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6300 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6301 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 6302 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6303 | }; |
| 6304 | |
| 6305 | static const char* const kExtraHeaders[] = { |
| 6306 | "location", |
| 6307 | "http://login.example.com/", |
| 6308 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6309 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6310 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6311 | arraysize(kExtraHeaders)/2, 1)); |
| 6312 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6313 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6314 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6315 | }; |
| 6316 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6317 | DelayedSocketData data( |
| 6318 | 1, // wait for one write to finish before reading. |
| 6319 | data_reads, arraysize(data_reads), |
| 6320 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6321 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6322 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6323 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6327 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6328 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6329 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6330 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6332 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6333 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6335 | |
| 6336 | rv = callback.WaitForResult(); |
| 6337 | EXPECT_EQ(OK, rv); |
| 6338 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6339 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6340 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6341 | |
| 6342 | EXPECT_EQ(302, response->headers->response_code()); |
| 6343 | std::string url; |
| 6344 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6345 | EXPECT_EQ("http://login.example.com/", url); |
| 6346 | } |
| 6347 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6348 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6349 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6350 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6351 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6352 | ProxyService::CreateFixed("https://proxy:70")); |
| 6353 | |
| 6354 | HttpRequestInfo request; |
| 6355 | request.method = "GET"; |
| 6356 | request.url = GURL("https://www.google.com/"); |
| 6357 | request.load_flags = 0; |
| 6358 | |
| 6359 | MockWrite data_writes[] = { |
| 6360 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6361 | "Host: www.google.com\r\n" |
| 6362 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6363 | }; |
| 6364 | |
| 6365 | MockRead data_reads[] = { |
| 6366 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6367 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6368 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6369 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6370 | }; |
| 6371 | |
| 6372 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6373 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6374 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6375 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6376 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6379 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6380 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6381 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6382 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6385 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6387 | |
| 6388 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6389 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6390 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6391 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6392 | } |
| 6393 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6394 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6395 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6396 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6397 | session_deps_.proxy_service.reset( |
| 6398 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6399 | |
| 6400 | HttpRequestInfo request; |
| 6401 | request.method = "GET"; |
| 6402 | request.url = GURL("https://www.google.com/"); |
| 6403 | request.load_flags = 0; |
| 6404 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6405 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6406 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6407 | scoped_ptr<SpdyFrame> rst( |
| 6408 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6409 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6410 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6411 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6412 | }; |
| 6413 | |
| 6414 | static const char* const kExtraHeaders[] = { |
| 6415 | "location", |
| 6416 | "http://login.example.com/", |
| 6417 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6418 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6419 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6420 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6421 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6422 | spdy_util_.ConstructSpdyBodyFrame( |
| 6423 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6424 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6425 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6426 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6427 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6428 | }; |
| 6429 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6430 | DelayedSocketData data( |
| 6431 | 1, // wait for one write to finish before reading. |
| 6432 | data_reads, arraysize(data_reads), |
| 6433 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6434 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6435 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6436 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6440 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6441 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6442 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6443 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6444 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6446 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6447 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6448 | |
| 6449 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6450 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6451 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6452 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6453 | } |
| 6454 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6455 | // Test the request-challenge-retry sequence for basic auth, through |
| 6456 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6457 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6458 | HttpRequestInfo request; |
| 6459 | request.method = "GET"; |
| 6460 | request.url = GURL("https://www.google.com/"); |
| 6461 | // when the no authentication data flag is set. |
| 6462 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 6463 | |
| 6464 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6465 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6466 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6467 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6468 | session_deps_.net_log = log.bound().net_log(); |
| 6469 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6470 | |
| 6471 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6472 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
| 6473 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6474 | scoped_ptr<SpdyFrame> rst( |
| 6475 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6476 | |
| 6477 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6478 | // be issuing -- the final header line contains the credentials. |
| 6479 | const char* const kAuthCredentials[] = { |
| 6480 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6481 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6482 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6483 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
| 6484 | HostPortPair("www.google.com", 443))); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6485 | // fetch https://www.google.com/ via HTTP |
| 6486 | const char get[] = "GET / HTTP/1.1\r\n" |
| 6487 | "Host: www.google.com\r\n" |
| 6488 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6489 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6490 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6491 | |
| 6492 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6493 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 6494 | CreateMockWrite(*rst, 4, ASYNC), |
| 6495 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6496 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6497 | }; |
| 6498 | |
| 6499 | // The proxy responds to the connect with a 407, using a persistent |
| 6500 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6501 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6502 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6503 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6504 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6505 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6506 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6507 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6508 | scoped_ptr<SpdyFrame> conn_resp( |
| 6509 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6510 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6511 | "Content-Length: 5\r\n\r\n"; |
| 6512 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6513 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6514 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6515 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6516 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6517 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6518 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 6519 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 6520 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 6521 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 6522 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6523 | }; |
| 6524 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6525 | OrderedSocketData spdy_data( |
| 6526 | spdy_reads, arraysize(spdy_reads), |
| 6527 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6528 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6529 | // Negotiate SPDY to the proxy |
| 6530 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6531 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6533 | // Vanilla SSL to the server |
| 6534 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6536 | |
| 6537 | TestCompletionCallback callback1; |
| 6538 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6539 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6540 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6541 | |
| 6542 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6543 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6544 | |
| 6545 | rv = callback1.WaitForResult(); |
| 6546 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 6547 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6548 | log.GetEntries(&entries); |
| 6549 | size_t pos = ExpectLogContainsSomewhere( |
| 6550 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6551 | NetLog::PHASE_NONE); |
| 6552 | ExpectLogContainsSomewhere( |
| 6553 | entries, pos, |
| 6554 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6555 | NetLog::PHASE_NONE); |
| 6556 | |
| 6557 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6558 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6559 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6560 | EXPECT_EQ(407, response->headers->response_code()); |
| 6561 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6562 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6563 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6564 | |
| 6565 | TestCompletionCallback callback2; |
| 6566 | |
| 6567 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6568 | callback2.callback()); |
| 6569 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6570 | |
| 6571 | rv = callback2.WaitForResult(); |
| 6572 | EXPECT_EQ(OK, rv); |
| 6573 | |
| 6574 | response = trans->GetResponseInfo(); |
| 6575 | ASSERT_TRUE(response != NULL); |
| 6576 | |
| 6577 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6578 | EXPECT_EQ(200, response->headers->response_code()); |
| 6579 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6580 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6581 | |
| 6582 | // The password prompt info should not be set. |
| 6583 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6584 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6585 | LoadTimingInfo load_timing_info; |
| 6586 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6587 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6588 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6589 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6590 | trans.reset(); |
| 6591 | session->CloseAllConnections(); |
| 6592 | } |
| 6593 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6594 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6595 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6596 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6597 | HttpRequestInfo request; |
| 6598 | HttpRequestInfo push_request; |
| 6599 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6600 | request.method = "GET"; |
| 6601 | request.url = GURL("http://www.google.com/"); |
| 6602 | push_request.method = "GET"; |
| 6603 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6604 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6605 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6606 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6607 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6608 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6609 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6610 | |
| 6611 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6612 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6613 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6614 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6615 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6616 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6617 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6618 | |
| 6619 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6620 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6621 | }; |
| 6622 | |
| 6623 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6624 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6625 | |
| 6626 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6627 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6628 | |
| 6629 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6630 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6631 | 0, |
| 6632 | 2, |
| 6633 | 1, |
| 6634 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6635 | const char kPushedData[] = "pushed"; |
| 6636 | scoped_ptr<SpdyFrame> stream2_body( |
| 6637 | spdy_util_.ConstructSpdyBodyFrame( |
| 6638 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6639 | |
| 6640 | MockRead spdy_reads[] = { |
| 6641 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6642 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6643 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6644 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6645 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6646 | }; |
| 6647 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6648 | OrderedSocketData spdy_data( |
| 6649 | spdy_reads, arraysize(spdy_reads), |
| 6650 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6651 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6652 | // Negotiate SPDY to the proxy |
| 6653 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6654 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6656 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6657 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6658 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6659 | TestCompletionCallback callback; |
| 6660 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6662 | |
| 6663 | rv = callback.WaitForResult(); |
| 6664 | EXPECT_EQ(OK, rv); |
| 6665 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6666 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6667 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6669 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6671 | |
| 6672 | rv = callback.WaitForResult(); |
| 6673 | EXPECT_EQ(OK, rv); |
| 6674 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6675 | |
| 6676 | ASSERT_TRUE(response != NULL); |
| 6677 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6678 | |
| 6679 | EXPECT_EQ(200, response->headers->response_code()); |
| 6680 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6681 | |
| 6682 | std::string response_data; |
| 6683 | rv = ReadTransaction(trans.get(), &response_data); |
| 6684 | EXPECT_EQ(OK, rv); |
| 6685 | EXPECT_EQ("hello!", response_data); |
| 6686 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6687 | LoadTimingInfo load_timing_info; |
| 6688 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6689 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6690 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6691 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6692 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6693 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6694 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6695 | |
| 6696 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6697 | EXPECT_EQ(OK, rv); |
| 6698 | EXPECT_EQ("pushed", response_data); |
| 6699 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6700 | LoadTimingInfo push_load_timing_info; |
| 6701 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6702 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6703 | // The transactions should share a socket ID, despite being for different |
| 6704 | // origins. |
| 6705 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6706 | push_load_timing_info.socket_log_id); |
| 6707 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6708 | trans.reset(); |
| 6709 | push_trans.reset(); |
| 6710 | session->CloseAllConnections(); |
| 6711 | } |
| 6712 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6713 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6714 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6715 | HttpRequestInfo request; |
| 6716 | |
| 6717 | request.method = "GET"; |
| 6718 | request.url = GURL("http://www.google.com/"); |
| 6719 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6720 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6721 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6722 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6723 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6724 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6725 | |
| 6726 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6727 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6728 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6729 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6730 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6731 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6732 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6733 | |
| 6734 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6735 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6736 | |
| 6737 | MockWrite spdy_writes[] = { |
| 6738 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6739 | CreateMockWrite(*push_rst, 4), |
| 6740 | }; |
| 6741 | |
| 6742 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6743 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6744 | |
| 6745 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6746 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6747 | |
| 6748 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6749 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6750 | 0, |
| 6751 | 2, |
| 6752 | 1, |
| 6753 | "https://www.another-origin.com/foo.dat")); |
| 6754 | |
| 6755 | MockRead spdy_reads[] = { |
| 6756 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6757 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6758 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6759 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6760 | }; |
| 6761 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6762 | OrderedSocketData spdy_data( |
| 6763 | spdy_reads, arraysize(spdy_reads), |
| 6764 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6765 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6766 | // Negotiate SPDY to the proxy |
| 6767 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6768 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6770 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6771 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6772 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6773 | TestCompletionCallback callback; |
| 6774 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6775 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6776 | |
| 6777 | rv = callback.WaitForResult(); |
| 6778 | EXPECT_EQ(OK, rv); |
| 6779 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6780 | |
| 6781 | ASSERT_TRUE(response != NULL); |
| 6782 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6783 | |
| 6784 | EXPECT_EQ(200, response->headers->response_code()); |
| 6785 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6786 | |
| 6787 | std::string response_data; |
| 6788 | rv = ReadTransaction(trans.get(), &response_data); |
| 6789 | EXPECT_EQ(OK, rv); |
| 6790 | EXPECT_EQ("hello!", response_data); |
| 6791 | |
| 6792 | trans.reset(); |
| 6793 | session->CloseAllConnections(); |
| 6794 | } |
| 6795 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6796 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 6797 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6798 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6799 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 6800 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6801 | |
| 6802 | HttpRequestInfo request; |
| 6803 | request.method = "GET"; |
| 6804 | request.url = GURL("https://www.google.com/"); |
| 6805 | request.load_flags = 0; |
| 6806 | |
| 6807 | // Attempt to fetch the URL from a server with a bad cert |
| 6808 | MockWrite bad_cert_writes[] = { |
| 6809 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6810 | "Host: www.google.com\r\n" |
| 6811 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6812 | }; |
| 6813 | |
| 6814 | MockRead bad_cert_reads[] = { |
| 6815 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6816 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6817 | }; |
| 6818 | |
| 6819 | // Attempt to fetch the URL with a good cert |
| 6820 | MockWrite good_data_writes[] = { |
| 6821 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6822 | "Host: www.google.com\r\n" |
| 6823 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6824 | MockWrite("GET / HTTP/1.1\r\n" |
| 6825 | "Host: www.google.com\r\n" |
| 6826 | "Connection: keep-alive\r\n\r\n"), |
| 6827 | }; |
| 6828 | |
| 6829 | MockRead good_cert_reads[] = { |
| 6830 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6831 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6832 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6833 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6834 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6835 | }; |
| 6836 | |
| 6837 | StaticSocketDataProvider ssl_bad_certificate( |
| 6838 | bad_cert_reads, arraysize(bad_cert_reads), |
| 6839 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 6840 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 6841 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6842 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6843 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6844 | |
| 6845 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6847 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6849 | |
| 6850 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6853 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6855 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6856 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6857 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6858 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6859 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6861 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6863 | |
| 6864 | rv = callback.WaitForResult(); |
| 6865 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6867 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6868 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6869 | |
| 6870 | rv = callback.WaitForResult(); |
| 6871 | EXPECT_EQ(OK, rv); |
| 6872 | |
| 6873 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6874 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6875 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6876 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6877 | } |
| 6878 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6879 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6880 | HttpRequestInfo request; |
| 6881 | request.method = "GET"; |
| 6882 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6883 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6884 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6885 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6886 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6887 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6888 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6889 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6890 | MockWrite data_writes[] = { |
| 6891 | MockWrite("GET / HTTP/1.1\r\n" |
| 6892 | "Host: www.google.com\r\n" |
| 6893 | "Connection: keep-alive\r\n" |
| 6894 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6895 | }; |
| 6896 | |
| 6897 | // Lastly, the server responds with the actual content. |
| 6898 | MockRead data_reads[] = { |
| 6899 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6900 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6901 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6902 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6903 | }; |
| 6904 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6905 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6906 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6907 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6909 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6911 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6912 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6913 | |
| 6914 | rv = callback.WaitForResult(); |
| 6915 | EXPECT_EQ(OK, rv); |
| 6916 | } |
| 6917 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6918 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6919 | HttpRequestInfo request; |
| 6920 | request.method = "GET"; |
| 6921 | request.url = GURL("https://www.google.com/"); |
| 6922 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 6923 | "Chromium Ultra Awesome X Edition"); |
| 6924 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6925 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6926 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6927 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6928 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6929 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6930 | MockWrite data_writes[] = { |
| 6931 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6932 | "Host: www.google.com\r\n" |
| 6933 | "Proxy-Connection: keep-alive\r\n" |
| 6934 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 6935 | }; |
| 6936 | MockRead data_reads[] = { |
| 6937 | // Return an error, so the transaction stops here (this test isn't |
| 6938 | // interested in the rest). |
| 6939 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6940 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6941 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 6942 | }; |
| 6943 | |
| 6944 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6945 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6948 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6950 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 6951 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6952 | |
| 6953 | rv = callback.WaitForResult(); |
| 6954 | EXPECT_EQ(OK, rv); |
| 6955 | } |
| 6956 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6957 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6958 | HttpRequestInfo request; |
| 6959 | request.method = "GET"; |
| 6960 | request.url = GURL("http://www.google.com/"); |
| 6961 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 6962 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 6963 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6964 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6965 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6966 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6967 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6968 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6969 | MockWrite data_writes[] = { |
| 6970 | MockWrite("GET / HTTP/1.1\r\n" |
| 6971 | "Host: www.google.com\r\n" |
| 6972 | "Connection: keep-alive\r\n" |
| 6973 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 6974 | }; |
| 6975 | |
| 6976 | // Lastly, the server responds with the actual content. |
| 6977 | MockRead data_reads[] = { |
| 6978 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6979 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6980 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6982 | }; |
| 6983 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6984 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6985 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6986 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6988 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6990 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6991 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6992 | |
| 6993 | rv = callback.WaitForResult(); |
| 6994 | EXPECT_EQ(OK, rv); |
| 6995 | } |
| 6996 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6997 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6998 | HttpRequestInfo request; |
| 6999 | request.method = "POST"; |
| 7000 | request.url = GURL("http://www.google.com/"); |
| 7001 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7002 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7003 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7004 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7005 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7006 | MockWrite data_writes[] = { |
| 7007 | MockWrite("POST / HTTP/1.1\r\n" |
| 7008 | "Host: www.google.com\r\n" |
| 7009 | "Connection: keep-alive\r\n" |
| 7010 | "Content-Length: 0\r\n\r\n"), |
| 7011 | }; |
| 7012 | |
| 7013 | // Lastly, the server responds with the actual content. |
| 7014 | MockRead data_reads[] = { |
| 7015 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7016 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7017 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7018 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7019 | }; |
| 7020 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7021 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7022 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7025 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7026 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7027 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7028 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7029 | |
| 7030 | rv = callback.WaitForResult(); |
| 7031 | EXPECT_EQ(OK, rv); |
| 7032 | } |
| 7033 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7034 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7035 | HttpRequestInfo request; |
| 7036 | request.method = "PUT"; |
| 7037 | request.url = GURL("http://www.google.com/"); |
| 7038 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7039 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7040 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7041 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7042 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7043 | MockWrite data_writes[] = { |
| 7044 | MockWrite("PUT / HTTP/1.1\r\n" |
| 7045 | "Host: www.google.com\r\n" |
| 7046 | "Connection: keep-alive\r\n" |
| 7047 | "Content-Length: 0\r\n\r\n"), |
| 7048 | }; |
| 7049 | |
| 7050 | // Lastly, the server responds with the actual content. |
| 7051 | MockRead data_reads[] = { |
| 7052 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7054 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7055 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7056 | }; |
| 7057 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7058 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7059 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7062 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7064 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7065 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7066 | |
| 7067 | rv = callback.WaitForResult(); |
| 7068 | EXPECT_EQ(OK, rv); |
| 7069 | } |
| 7070 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7071 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7072 | HttpRequestInfo request; |
| 7073 | request.method = "HEAD"; |
| 7074 | request.url = GURL("http://www.google.com/"); |
| 7075 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7076 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7077 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7079 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7080 | MockWrite data_writes[] = { |
| 7081 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7082 | "Host: www.google.com\r\n" |
| 7083 | "Connection: keep-alive\r\n" |
| 7084 | "Content-Length: 0\r\n\r\n"), |
| 7085 | }; |
| 7086 | |
| 7087 | // Lastly, the server responds with the actual content. |
| 7088 | MockRead data_reads[] = { |
| 7089 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7090 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7091 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7092 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7093 | }; |
| 7094 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7095 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7096 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7097 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7099 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7101 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7103 | |
| 7104 | rv = callback.WaitForResult(); |
| 7105 | EXPECT_EQ(OK, rv); |
| 7106 | } |
| 7107 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7108 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7109 | HttpRequestInfo request; |
| 7110 | request.method = "GET"; |
| 7111 | request.url = GURL("http://www.google.com/"); |
| 7112 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7113 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7114 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7115 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7116 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7117 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7118 | MockWrite data_writes[] = { |
| 7119 | MockWrite("GET / HTTP/1.1\r\n" |
| 7120 | "Host: www.google.com\r\n" |
| 7121 | "Connection: keep-alive\r\n" |
| 7122 | "Pragma: no-cache\r\n" |
| 7123 | "Cache-Control: no-cache\r\n\r\n"), |
| 7124 | }; |
| 7125 | |
| 7126 | // Lastly, the server responds with the actual content. |
| 7127 | MockRead data_reads[] = { |
| 7128 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7129 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7130 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7131 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7132 | }; |
| 7133 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7134 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7135 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7136 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7138 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7140 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7141 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7142 | |
| 7143 | rv = callback.WaitForResult(); |
| 7144 | EXPECT_EQ(OK, rv); |
| 7145 | } |
| 7146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7147 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7148 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7149 | HttpRequestInfo request; |
| 7150 | request.method = "GET"; |
| 7151 | request.url = GURL("http://www.google.com/"); |
| 7152 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7153 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7154 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7155 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7156 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7157 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7158 | MockWrite data_writes[] = { |
| 7159 | MockWrite("GET / HTTP/1.1\r\n" |
| 7160 | "Host: www.google.com\r\n" |
| 7161 | "Connection: keep-alive\r\n" |
| 7162 | "Cache-Control: max-age=0\r\n\r\n"), |
| 7163 | }; |
| 7164 | |
| 7165 | // Lastly, the server responds with the actual content. |
| 7166 | MockRead data_reads[] = { |
| 7167 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7168 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7169 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7170 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7171 | }; |
| 7172 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7174 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7177 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7179 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7180 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7181 | |
| 7182 | rv = callback.WaitForResult(); |
| 7183 | EXPECT_EQ(OK, rv); |
| 7184 | } |
| 7185 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7186 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7187 | HttpRequestInfo request; |
| 7188 | request.method = "GET"; |
| 7189 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7190 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[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 | "FooHeader: Bar\r\n\r\n"), |
| 7201 | }; |
| 7202 | |
| 7203 | // Lastly, the server responds with the actual content. |
| 7204 | MockRead data_reads[] = { |
| 7205 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7206 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7207 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 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_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7225 | HttpRequestInfo request; |
| 7226 | request.method = "GET"; |
| 7227 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7228 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7229 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7230 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7231 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7232 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7233 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7234 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7235 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7236 | MockWrite data_writes[] = { |
| 7237 | MockWrite("GET / HTTP/1.1\r\n" |
| 7238 | "Host: www.google.com\r\n" |
| 7239 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7240 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7241 | "hEllo: Kitty\r\n" |
| 7242 | "FoO: bar\r\n\r\n"), |
| 7243 | }; |
| 7244 | |
| 7245 | // Lastly, the server responds with the actual content. |
| 7246 | MockRead data_reads[] = { |
| 7247 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7248 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7249 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7250 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7251 | }; |
| 7252 | |
| 7253 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7254 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7257 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7259 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7261 | |
| 7262 | rv = callback.WaitForResult(); |
| 7263 | EXPECT_EQ(OK, rv); |
| 7264 | } |
| 7265 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7266 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7267 | HttpRequestInfo request; |
| 7268 | request.method = "GET"; |
| 7269 | request.url = GURL("http://www.google.com/"); |
| 7270 | request.load_flags = 0; |
| 7271 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7272 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7273 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7274 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7275 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7276 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7277 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7278 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7279 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7280 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7281 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7282 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7283 | |
| 7284 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7285 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7286 | MockWrite("GET / HTTP/1.1\r\n" |
| 7287 | "Host: www.google.com\r\n" |
| 7288 | "Connection: keep-alive\r\n\r\n") |
| 7289 | }; |
| 7290 | |
| 7291 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7292 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7293 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7294 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7295 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7296 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7297 | }; |
| 7298 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7299 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7300 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7301 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7303 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7304 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7305 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7306 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7307 | |
| 7308 | rv = callback.WaitForResult(); |
| 7309 | EXPECT_EQ(OK, rv); |
| 7310 | |
| 7311 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7312 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7313 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7314 | LoadTimingInfo load_timing_info; |
| 7315 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7316 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7317 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7318 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7319 | std::string response_text; |
| 7320 | rv = ReadTransaction(trans.get(), &response_text); |
| 7321 | EXPECT_EQ(OK, rv); |
| 7322 | EXPECT_EQ("Payload", response_text); |
| 7323 | } |
| 7324 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7325 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7326 | HttpRequestInfo request; |
| 7327 | request.method = "GET"; |
| 7328 | request.url = GURL("https://www.google.com/"); |
| 7329 | request.load_flags = 0; |
| 7330 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7331 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7332 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7333 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7334 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7335 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7336 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7337 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7338 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7339 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7340 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7341 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7342 | |
| 7343 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7344 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7345 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7346 | MockWrite("GET / HTTP/1.1\r\n" |
| 7347 | "Host: www.google.com\r\n" |
| 7348 | "Connection: keep-alive\r\n\r\n") |
| 7349 | }; |
| 7350 | |
| 7351 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7352 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7353 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7354 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7355 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7356 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7357 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7358 | }; |
| 7359 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7360 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7361 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7363 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7364 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7367 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7369 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7371 | |
| 7372 | rv = callback.WaitForResult(); |
| 7373 | EXPECT_EQ(OK, rv); |
| 7374 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7375 | LoadTimingInfo load_timing_info; |
| 7376 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7377 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7378 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7379 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7380 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7381 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7382 | |
| 7383 | std::string response_text; |
| 7384 | rv = ReadTransaction(trans.get(), &response_text); |
| 7385 | EXPECT_EQ(OK, rv); |
| 7386 | EXPECT_EQ("Payload", response_text); |
| 7387 | } |
| 7388 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7389 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7390 | HttpRequestInfo request; |
| 7391 | request.method = "GET"; |
| 7392 | request.url = GURL("http://www.google.com/"); |
| 7393 | request.load_flags = 0; |
| 7394 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7395 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7396 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
| 7397 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7398 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7399 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7400 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7401 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7402 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7403 | |
| 7404 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7405 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7406 | |
| 7407 | MockWrite data_writes[] = { |
| 7408 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7409 | MockWrite("GET / HTTP/1.1\r\n" |
| 7410 | "Host: www.google.com\r\n" |
| 7411 | "Connection: keep-alive\r\n\r\n") |
| 7412 | }; |
| 7413 | |
| 7414 | MockRead data_reads[] = { |
| 7415 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7416 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7417 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7418 | MockRead("Payload"), |
| 7419 | MockRead(SYNCHRONOUS, OK) |
| 7420 | }; |
| 7421 | |
| 7422 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7423 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7425 | |
| 7426 | TestCompletionCallback callback; |
| 7427 | |
| 7428 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7430 | |
| 7431 | rv = callback.WaitForResult(); |
| 7432 | EXPECT_EQ(OK, rv); |
| 7433 | |
| 7434 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7435 | ASSERT_TRUE(response != NULL); |
| 7436 | |
| 7437 | LoadTimingInfo load_timing_info; |
| 7438 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7439 | TestLoadTimingNotReused(load_timing_info, |
| 7440 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7441 | |
| 7442 | std::string response_text; |
| 7443 | rv = ReadTransaction(trans.get(), &response_text); |
| 7444 | EXPECT_EQ(OK, rv); |
| 7445 | EXPECT_EQ("Payload", response_text); |
| 7446 | } |
| 7447 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7448 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7449 | HttpRequestInfo request; |
| 7450 | request.method = "GET"; |
| 7451 | request.url = GURL("http://www.google.com/"); |
| 7452 | request.load_flags = 0; |
| 7453 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7454 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7455 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7456 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7457 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7458 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7459 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [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] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7462 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7463 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7464 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7465 | const char kSOCKS5OkRequest[] = { |
| 7466 | 0x05, // Version |
| 7467 | 0x01, // Command (CONNECT) |
| 7468 | 0x00, // Reserved. |
| 7469 | 0x03, // Address type (DOMAINNAME). |
| 7470 | 0x0E, // Length of domain (14) |
| 7471 | // Domain string: |
| 7472 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7473 | 0x00, 0x50, // 16-bit port (80) |
| 7474 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7475 | const char kSOCKS5OkResponse[] = |
| 7476 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7477 | |
| 7478 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7479 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7480 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7481 | MockWrite("GET / HTTP/1.1\r\n" |
| 7482 | "Host: www.google.com\r\n" |
| 7483 | "Connection: keep-alive\r\n\r\n") |
| 7484 | }; |
| 7485 | |
| 7486 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7487 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7488 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7489 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7490 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7491 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7492 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7493 | }; |
| 7494 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7495 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7496 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7499 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7501 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7502 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7503 | |
| 7504 | rv = callback.WaitForResult(); |
| 7505 | EXPECT_EQ(OK, rv); |
| 7506 | |
| 7507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7508 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7509 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7510 | LoadTimingInfo load_timing_info; |
| 7511 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7512 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7513 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7514 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7515 | std::string response_text; |
| 7516 | rv = ReadTransaction(trans.get(), &response_text); |
| 7517 | EXPECT_EQ(OK, rv); |
| 7518 | EXPECT_EQ("Payload", response_text); |
| 7519 | } |
| 7520 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7521 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7522 | HttpRequestInfo request; |
| 7523 | request.method = "GET"; |
| 7524 | request.url = GURL("https://www.google.com/"); |
| 7525 | request.load_flags = 0; |
| 7526 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7527 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7528 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7529 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7530 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7531 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7532 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7533 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7534 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7535 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7536 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7537 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7538 | const unsigned char kSOCKS5OkRequest[] = { |
| 7539 | 0x05, // Version |
| 7540 | 0x01, // Command (CONNECT) |
| 7541 | 0x00, // Reserved. |
| 7542 | 0x03, // Address type (DOMAINNAME). |
| 7543 | 0x0E, // Length of domain (14) |
| 7544 | // Domain string: |
| 7545 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7546 | 0x01, 0xBB, // 16-bit port (443) |
| 7547 | }; |
| 7548 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7549 | const char kSOCKS5OkResponse[] = |
| 7550 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7551 | |
| 7552 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7553 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7554 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7555 | arraysize(kSOCKS5OkRequest)), |
| 7556 | MockWrite("GET / HTTP/1.1\r\n" |
| 7557 | "Host: www.google.com\r\n" |
| 7558 | "Connection: keep-alive\r\n\r\n") |
| 7559 | }; |
| 7560 | |
| 7561 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7562 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7563 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7564 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7565 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7566 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7567 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7568 | }; |
| 7569 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7570 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7571 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7573 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7574 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7577 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7579 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7581 | |
| 7582 | rv = callback.WaitForResult(); |
| 7583 | EXPECT_EQ(OK, rv); |
| 7584 | |
| 7585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7586 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7587 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7588 | LoadTimingInfo load_timing_info; |
| 7589 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7590 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7591 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7592 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7593 | std::string response_text; |
| 7594 | rv = ReadTransaction(trans.get(), &response_text); |
| 7595 | EXPECT_EQ(OK, rv); |
| 7596 | EXPECT_EQ("Payload", response_text); |
| 7597 | } |
| 7598 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7599 | namespace { |
| 7600 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7601 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7602 | |
| 7603 | struct GroupNameTest { |
| 7604 | std::string proxy_server; |
| 7605 | std::string url; |
| 7606 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7607 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7608 | }; |
| 7609 | |
| 7610 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7611 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7612 | SpdySessionDependencies* session_deps_) { |
| 7613 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7614 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7615 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7616 | session->http_server_properties(); |
| 7617 | http_server_properties->SetAlternateProtocol( |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7618 | HostPortPair("host.with.alternate", 80), 443, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 7619 | AlternateProtocolFromNextProto(next_proto), 1.0); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7620 | |
| 7621 | return session; |
| 7622 | } |
| 7623 | |
| 7624 | int GroupNameTransactionHelper( |
| 7625 | const std::string& url, |
| 7626 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7627 | HttpRequestInfo request; |
| 7628 | request.method = "GET"; |
| 7629 | request.url = GURL(url); |
| 7630 | request.load_flags = 0; |
| 7631 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7632 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7633 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7635 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7636 | |
| 7637 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7638 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7639 | } |
| 7640 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7641 | } // namespace |
| 7642 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7643 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7644 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7645 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7646 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7647 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7648 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7649 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7650 | }, |
| 7651 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7652 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7653 | "http://[2001:1418:13:1::25]/direct", |
| 7654 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7655 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7656 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7657 | |
| 7658 | // SSL Tests |
| 7659 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7660 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7661 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7662 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7663 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7664 | }, |
| 7665 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7666 | "", // unused |
| 7667 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7668 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7669 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7670 | }, |
| 7671 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7672 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7673 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7674 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7675 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7676 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7677 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7678 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7679 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7680 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7681 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7682 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7683 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7684 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7685 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7686 | |
| 7687 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7688 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7689 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7690 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7691 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7692 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7693 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7694 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7695 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7696 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7697 | |
| 7698 | EXPECT_EQ(ERR_IO_PENDING, |
| 7699 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7700 | if (tests[i].ssl) |
| 7701 | EXPECT_EQ(tests[i].expected_group_name, |
| 7702 | ssl_conn_pool->last_group_name_received()); |
| 7703 | else |
| 7704 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7705 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7706 | } |
| 7707 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7708 | } |
| 7709 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7710 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7711 | const GroupNameTest tests[] = { |
| 7712 | { |
| 7713 | "http_proxy", |
| 7714 | "http://www.google.com/http_proxy_normal", |
| 7715 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7716 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7717 | }, |
| 7718 | |
| 7719 | // SSL Tests |
| 7720 | { |
| 7721 | "http_proxy", |
| 7722 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7723 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7724 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7725 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7726 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7727 | { |
| 7728 | "http_proxy", |
| 7729 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7730 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7731 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7732 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7733 | |
| 7734 | { |
| 7735 | "http_proxy", |
| 7736 | "ftp://ftp.google.com/http_proxy_normal", |
| 7737 | "ftp/ftp.google.com:21", |
| 7738 | false, |
| 7739 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7740 | }; |
| 7741 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7742 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7743 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7744 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7745 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7746 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7747 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7748 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7749 | |
| 7750 | HttpNetworkSessionPeer peer(session); |
| 7751 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7752 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7753 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7754 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7755 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7756 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7757 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7758 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7759 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7760 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7761 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7762 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7763 | |
| 7764 | EXPECT_EQ(ERR_IO_PENDING, |
| 7765 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7766 | if (tests[i].ssl) |
| 7767 | EXPECT_EQ(tests[i].expected_group_name, |
| 7768 | ssl_conn_pool->last_group_name_received()); |
| 7769 | else |
| 7770 | EXPECT_EQ(tests[i].expected_group_name, |
| 7771 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7772 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7773 | } |
| 7774 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7775 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7776 | const GroupNameTest tests[] = { |
| 7777 | { |
| 7778 | "socks4://socks_proxy:1080", |
| 7779 | "http://www.google.com/socks4_direct", |
| 7780 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7781 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7782 | }, |
| 7783 | { |
| 7784 | "socks5://socks_proxy:1080", |
| 7785 | "http://www.google.com/socks5_direct", |
| 7786 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7787 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7788 | }, |
| 7789 | |
| 7790 | // SSL Tests |
| 7791 | { |
| 7792 | "socks4://socks_proxy:1080", |
| 7793 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7794 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7795 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7796 | }, |
| 7797 | { |
| 7798 | "socks5://socks_proxy:1080", |
| 7799 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7800 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7801 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7802 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7803 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7804 | { |
| 7805 | "socks4://socks_proxy:1080", |
| 7806 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7807 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7808 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7809 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7810 | }; |
| 7811 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7812 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7813 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7814 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7815 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7816 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7817 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7818 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7819 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7820 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7821 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7822 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7823 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7824 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7825 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7826 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7827 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7828 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7829 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7830 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 7831 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7832 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7833 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7834 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7835 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7836 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7837 | EXPECT_EQ(ERR_IO_PENDING, |
| 7838 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7839 | if (tests[i].ssl) |
| 7840 | EXPECT_EQ(tests[i].expected_group_name, |
| 7841 | ssl_conn_pool->last_group_name_received()); |
| 7842 | else |
| 7843 | EXPECT_EQ(tests[i].expected_group_name, |
| 7844 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7845 | } |
| 7846 | } |
| 7847 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7848 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7849 | HttpRequestInfo request; |
| 7850 | request.method = "GET"; |
| 7851 | request.url = GURL("http://www.google.com/"); |
| 7852 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7853 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 7854 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7855 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 7856 | // This simulates failure resolving all hostnames; that means we will fail |
| 7857 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7858 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7859 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7860 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7861 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7862 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7864 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7866 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7867 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7868 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7869 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 7870 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 7871 | } |
| 7872 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7873 | // Base test to make sure that when the load flags for a request specify to |
| 7874 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7875 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7876 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7877 | // Issue a request, asking to bypass the cache(s). |
| 7878 | HttpRequestInfo request; |
| 7879 | request.method = "GET"; |
| 7880 | request.load_flags = load_flags; |
| 7881 | request.url = GURL("http://www.google.com/"); |
| 7882 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 7883 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7884 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7885 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7886 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7887 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7888 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7889 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7890 | // 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] | 7891 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 7892 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7893 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7894 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7895 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7896 | &addrlist, |
| 7897 | callback.callback(), |
| 7898 | NULL, |
| 7899 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 7900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7901 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7902 | EXPECT_EQ(OK, rv); |
| 7903 | |
| 7904 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 7905 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7906 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 7907 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 7908 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 7909 | &addrlist, |
| 7910 | callback.callback(), |
| 7911 | NULL, |
| 7912 | BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 7913 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7914 | |
| 7915 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 7916 | // we can tell if the next lookup hit the cache, or the "network". |
| 7917 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7918 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7919 | |
| 7920 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 7921 | // first read -- this won't be reached as the host resolution will fail first. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7922 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7923 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7925 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7926 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7927 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7928 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7929 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 7930 | |
| 7931 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 7932 | // "www.google.com". |
| 7933 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 7934 | } |
| 7935 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7936 | // There are multiple load flags that should trigger the host cache bypass. |
| 7937 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7938 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7939 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 7940 | } |
| 7941 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7942 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7943 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 7944 | } |
| 7945 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7946 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 7947 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 7948 | } |
| 7949 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7950 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7951 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7952 | HttpRequestInfo request; |
| 7953 | request.method = "GET"; |
| 7954 | request.url = GURL("http://www.foo.com/"); |
| 7955 | request.load_flags = 0; |
| 7956 | |
| 7957 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7958 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7959 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7960 | StaticSocketDataProvider data(NULL, 0, |
| 7961 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7963 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7965 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7966 | |
| 7967 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7968 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7970 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7971 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7972 | |
| 7973 | rv = callback.WaitForResult(); |
| 7974 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 7975 | } |
| 7976 | |
| 7977 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7978 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7979 | HttpRequestInfo request; |
| 7980 | request.method = "GET"; |
| 7981 | request.url = GURL("http://www.foo.com/"); |
| 7982 | request.load_flags = 0; |
| 7983 | |
| 7984 | MockRead data_reads[] = { |
| 7985 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7986 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7987 | }; |
| 7988 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7989 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7991 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7993 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7994 | |
| 7995 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7996 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7998 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7999 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8000 | |
| 8001 | rv = callback.WaitForResult(); |
| 8002 | EXPECT_EQ(OK, rv); |
| 8003 | |
| 8004 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8005 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8006 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8007 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8008 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8009 | |
| 8010 | std::string response_data; |
| 8011 | rv = ReadTransaction(trans.get(), &response_data); |
| 8012 | EXPECT_EQ(OK, rv); |
| 8013 | EXPECT_EQ("", response_data); |
| 8014 | } |
| 8015 | |
| 8016 | // Make sure that a dropped connection while draining the body for auth |
| 8017 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8018 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8019 | HttpRequestInfo request; |
| 8020 | request.method = "GET"; |
| 8021 | request.url = GURL("http://www.google.com/"); |
| 8022 | request.load_flags = 0; |
| 8023 | |
| 8024 | MockWrite data_writes1[] = { |
| 8025 | MockWrite("GET / HTTP/1.1\r\n" |
| 8026 | "Host: www.google.com\r\n" |
| 8027 | "Connection: keep-alive\r\n\r\n"), |
| 8028 | }; |
| 8029 | |
| 8030 | MockRead data_reads1[] = { |
| 8031 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8032 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8033 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8034 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8035 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8036 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8037 | }; |
| 8038 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8039 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8040 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8041 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8042 | |
| 8043 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8044 | // be issuing -- the final header line contains the credentials. |
| 8045 | MockWrite data_writes2[] = { |
| 8046 | MockWrite("GET / HTTP/1.1\r\n" |
| 8047 | "Host: www.google.com\r\n" |
| 8048 | "Connection: keep-alive\r\n" |
| 8049 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 8050 | }; |
| 8051 | |
| 8052 | // Lastly, the server responds with the actual content. |
| 8053 | MockRead data_reads2[] = { |
| 8054 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8055 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8056 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8057 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8058 | }; |
| 8059 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8060 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8061 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8062 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8063 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8065 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8066 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8067 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8068 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8070 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8072 | |
| 8073 | rv = callback1.WaitForResult(); |
| 8074 | EXPECT_EQ(OK, rv); |
| 8075 | |
| 8076 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8077 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8078 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8080 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8082 | rv = trans->RestartWithAuth( |
| 8083 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8084 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8085 | |
| 8086 | rv = callback2.WaitForResult(); |
| 8087 | EXPECT_EQ(OK, rv); |
| 8088 | |
| 8089 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8090 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8091 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8092 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8093 | } |
| 8094 | |
| 8095 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8096 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8097 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8098 | |
| 8099 | HttpRequestInfo request; |
| 8100 | request.method = "GET"; |
| 8101 | request.url = GURL("https://www.google.com/"); |
| 8102 | request.load_flags = 0; |
| 8103 | |
| 8104 | MockRead proxy_reads[] = { |
| 8105 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8106 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8107 | }; |
| 8108 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8109 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8110 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8111 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8115 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8116 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8117 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8118 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8119 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8120 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8123 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8124 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8125 | |
| 8126 | rv = callback.WaitForResult(); |
| 8127 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8128 | } |
| 8129 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8130 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8131 | HttpRequestInfo request; |
| 8132 | request.method = "GET"; |
| 8133 | request.url = GURL("http://www.google.com/"); |
| 8134 | request.load_flags = 0; |
| 8135 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8136 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8137 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8138 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8139 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8140 | MockRead data_reads[] = { |
| 8141 | 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] | 8142 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8143 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8144 | |
| 8145 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8148 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8150 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8151 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8152 | |
| 8153 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8154 | |
| 8155 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8156 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8157 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8158 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8159 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8160 | |
| 8161 | std::string response_data; |
| 8162 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8163 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8164 | } |
| 8165 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8166 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8167 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8168 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8169 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8170 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8171 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8172 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8173 | ScopedVector<UploadElementReader> element_readers; |
| 8174 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8175 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8176 | temp_file_path, |
| 8177 | 0, |
| 8178 | kuint64max, |
| 8179 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8180 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8181 | |
| 8182 | HttpRequestInfo request; |
| 8183 | request.method = "POST"; |
| 8184 | request.url = GURL("http://www.google.com/upload"); |
| 8185 | request.upload_data_stream = &upload_data_stream; |
| 8186 | request.load_flags = 0; |
| 8187 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8188 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8189 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8191 | |
| 8192 | MockRead data_reads[] = { |
| 8193 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8194 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8195 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8196 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8197 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8198 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8200 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8202 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8203 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8204 | |
| 8205 | rv = callback.WaitForResult(); |
| 8206 | EXPECT_EQ(OK, rv); |
| 8207 | |
| 8208 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8209 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8210 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8211 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8212 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8213 | |
| 8214 | std::string response_data; |
| 8215 | rv = ReadTransaction(trans.get(), &response_data); |
| 8216 | EXPECT_EQ(OK, rv); |
| 8217 | EXPECT_EQ("hello world", response_data); |
| 8218 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8219 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8220 | } |
| 8221 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8222 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8223 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8224 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8225 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8226 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8227 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8228 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8229 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8230 | ScopedVector<UploadElementReader> element_readers; |
| 8231 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8232 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8233 | temp_file, |
| 8234 | 0, |
| 8235 | kuint64max, |
| 8236 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8237 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8238 | |
| 8239 | HttpRequestInfo request; |
| 8240 | request.method = "POST"; |
| 8241 | request.url = GURL("http://www.google.com/upload"); |
| 8242 | request.upload_data_stream = &upload_data_stream; |
| 8243 | request.load_flags = 0; |
| 8244 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8245 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8246 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8247 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8249 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8250 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8251 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8253 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8255 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8257 | |
| 8258 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8259 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8260 | |
| 8261 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8262 | EXPECT_FALSE(response); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8263 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8264 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8265 | } |
| 8266 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8267 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8268 | class FakeUploadElementReader : public UploadElementReader { |
| 8269 | public: |
| 8270 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8271 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8272 | |
| 8273 | const CompletionCallback& callback() const { return callback_; } |
| 8274 | |
| 8275 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8276 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8277 | callback_ = callback; |
| 8278 | return ERR_IO_PENDING; |
| 8279 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8280 | uint64 GetContentLength() const override { return 0; } |
| 8281 | uint64 BytesRemaining() const override { return 0; } |
| 8282 | int Read(IOBuffer* buf, |
| 8283 | int buf_length, |
| 8284 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8285 | return ERR_FAILED; |
| 8286 | } |
| 8287 | |
| 8288 | private: |
| 8289 | CompletionCallback callback_; |
| 8290 | }; |
| 8291 | |
| 8292 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8293 | ScopedVector<UploadElementReader> element_readers; |
| 8294 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8295 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8296 | |
| 8297 | HttpRequestInfo request; |
| 8298 | request.method = "POST"; |
| 8299 | request.url = GURL("http://www.google.com/upload"); |
| 8300 | request.upload_data_stream = &upload_data_stream; |
| 8301 | request.load_flags = 0; |
| 8302 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8303 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8304 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8306 | |
| 8307 | StaticSocketDataProvider data; |
| 8308 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8309 | |
| 8310 | TestCompletionCallback callback; |
| 8311 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8312 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8313 | base::MessageLoop::current()->RunUntilIdle(); |
| 8314 | |
| 8315 | // Transaction is pending on request body initialization. |
| 8316 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8317 | |
| 8318 | // Return Init()'s result after the transaction gets destroyed. |
| 8319 | trans.reset(); |
| 8320 | fake_reader->callback().Run(OK); // Should not crash. |
| 8321 | } |
| 8322 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8323 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8324 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8325 | |
| 8326 | HttpRequestInfo request; |
| 8327 | request.method = "GET"; |
| 8328 | request.url = GURL("http://www.google.com/"); |
| 8329 | request.load_flags = 0; |
| 8330 | |
| 8331 | // First transaction will request a resource and receive a Basic challenge |
| 8332 | // with realm="first_realm". |
| 8333 | MockWrite data_writes1[] = { |
| 8334 | MockWrite("GET / HTTP/1.1\r\n" |
| 8335 | "Host: www.google.com\r\n" |
| 8336 | "Connection: keep-alive\r\n" |
| 8337 | "\r\n"), |
| 8338 | }; |
| 8339 | MockRead data_reads1[] = { |
| 8340 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8341 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8342 | "\r\n"), |
| 8343 | }; |
| 8344 | |
| 8345 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8346 | // for first_realm. The server will reject and provide a challenge with |
| 8347 | // second_realm. |
| 8348 | MockWrite data_writes2[] = { |
| 8349 | MockWrite("GET / HTTP/1.1\r\n" |
| 8350 | "Host: www.google.com\r\n" |
| 8351 | "Connection: keep-alive\r\n" |
| 8352 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8353 | "\r\n"), |
| 8354 | }; |
| 8355 | MockRead data_reads2[] = { |
| 8356 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8357 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8358 | "\r\n"), |
| 8359 | }; |
| 8360 | |
| 8361 | // This again fails, and goes back to first_realm. Make sure that the |
| 8362 | // entry is removed from cache. |
| 8363 | MockWrite data_writes3[] = { |
| 8364 | MockWrite("GET / HTTP/1.1\r\n" |
| 8365 | "Host: www.google.com\r\n" |
| 8366 | "Connection: keep-alive\r\n" |
| 8367 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8368 | "\r\n"), |
| 8369 | }; |
| 8370 | MockRead data_reads3[] = { |
| 8371 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8372 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8373 | "\r\n"), |
| 8374 | }; |
| 8375 | |
| 8376 | // Try one last time (with the correct password) and get the resource. |
| 8377 | MockWrite data_writes4[] = { |
| 8378 | MockWrite("GET / HTTP/1.1\r\n" |
| 8379 | "Host: www.google.com\r\n" |
| 8380 | "Connection: keep-alive\r\n" |
| 8381 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8382 | "\r\n"), |
| 8383 | }; |
| 8384 | MockRead data_reads4[] = { |
| 8385 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8386 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8387 | "Content-Length: 5\r\n" |
| 8388 | "\r\n" |
| 8389 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8390 | }; |
| 8391 | |
| 8392 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8393 | data_writes1, arraysize(data_writes1)); |
| 8394 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8395 | data_writes2, arraysize(data_writes2)); |
| 8396 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8397 | data_writes3, arraysize(data_writes3)); |
| 8398 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8399 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8400 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8401 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8402 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8403 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8405 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8406 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8407 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8408 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8409 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8410 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8411 | // Issue the first request with Authorize headers. There should be a |
| 8412 | // password prompt for first_realm waiting to be filled in after the |
| 8413 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8414 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8416 | rv = callback1.WaitForResult(); |
| 8417 | EXPECT_EQ(OK, rv); |
| 8418 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8419 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8420 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8421 | ASSERT_FALSE(challenge == NULL); |
| 8422 | EXPECT_FALSE(challenge->is_proxy); |
| 8423 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8424 | EXPECT_EQ("first_realm", challenge->realm); |
| 8425 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8426 | |
| 8427 | // Issue the second request with an incorrect password. There should be a |
| 8428 | // password prompt for second_realm waiting to be filled in after the |
| 8429 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8430 | TestCompletionCallback callback2; |
| 8431 | rv = trans->RestartWithAuth( |
| 8432 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8433 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8434 | rv = callback2.WaitForResult(); |
| 8435 | EXPECT_EQ(OK, rv); |
| 8436 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8437 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8438 | challenge = response->auth_challenge.get(); |
| 8439 | ASSERT_FALSE(challenge == NULL); |
| 8440 | EXPECT_FALSE(challenge->is_proxy); |
| 8441 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8442 | EXPECT_EQ("second_realm", challenge->realm); |
| 8443 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8444 | |
| 8445 | // Issue the third request with another incorrect password. There should be |
| 8446 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8447 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8448 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8449 | TestCompletionCallback callback3; |
| 8450 | rv = trans->RestartWithAuth( |
| 8451 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8452 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8453 | rv = callback3.WaitForResult(); |
| 8454 | EXPECT_EQ(OK, rv); |
| 8455 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8456 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8457 | challenge = response->auth_challenge.get(); |
| 8458 | ASSERT_FALSE(challenge == NULL); |
| 8459 | EXPECT_FALSE(challenge->is_proxy); |
| 8460 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8461 | EXPECT_EQ("first_realm", challenge->realm); |
| 8462 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8463 | |
| 8464 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8465 | TestCompletionCallback callback4; |
| 8466 | rv = trans->RestartWithAuth( |
| 8467 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8468 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8469 | rv = callback4.WaitForResult(); |
| 8470 | EXPECT_EQ(OK, rv); |
| 8471 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8472 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8473 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8474 | } |
| 8475 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8476 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8477 | session_deps_.next_protos = SpdyNextProtos(); |
| 8478 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8479 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8480 | std::string alternate_protocol_http_header = |
| 8481 | GetAlternateProtocolHttpHeader(); |
| 8482 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8483 | MockRead data_reads[] = { |
| 8484 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8485 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8486 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8487 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8488 | }; |
| 8489 | |
| 8490 | HttpRequestInfo request; |
| 8491 | request.method = "GET"; |
| 8492 | request.url = GURL("http://www.google.com/"); |
| 8493 | request.load_flags = 0; |
| 8494 | |
| 8495 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8496 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8499 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8500 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8501 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8502 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8503 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8505 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8506 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8507 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 8508 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8509 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8510 | *session->http_server_properties(); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8511 | EXPECT_FALSE( |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8512 | http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8513 | |
| 8514 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8515 | |
| 8516 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8517 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8518 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8519 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8520 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8521 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8522 | |
| 8523 | std::string response_data; |
| 8524 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8525 | EXPECT_EQ("hello world", response_data); |
| 8526 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8527 | ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8528 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8529 | http_server_properties.GetAlternateProtocol(http_host_port_pair); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8530 | AlternateProtocolInfo expected_alternate( |
| 8531 | 443, AlternateProtocolFromNextProto(GetParam()), 1); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8532 | EXPECT_TRUE(expected_alternate.Equals(alternate)); |
| 8533 | } |
| 8534 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8535 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8536 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8537 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8538 | |
| 8539 | HttpRequestInfo request; |
| 8540 | request.method = "GET"; |
| 8541 | request.url = GURL("http://www.google.com/"); |
| 8542 | request.load_flags = 0; |
| 8543 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8544 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8545 | StaticSocketDataProvider first_data; |
| 8546 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8547 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8548 | |
| 8549 | MockRead data_reads[] = { |
| 8550 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8551 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8552 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8553 | }; |
| 8554 | StaticSocketDataProvider second_data( |
| 8555 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8556 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8557 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8558 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8559 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8560 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8561 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8562 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8563 | // port 80 (another restricted port). |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8564 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8565 | HostPortPair::FromURL(request.url), |
| 8566 | 666 /* port is ignored by MockConnect anyway */, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8567 | AlternateProtocolFromNextProto(GetParam()), 1.0); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8568 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8569 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8571 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8572 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8573 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8574 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8575 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8576 | |
| 8577 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8578 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8579 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8580 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8581 | |
| 8582 | std::string response_data; |
| 8583 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8584 | EXPECT_EQ("hello world", response_data); |
| 8585 | |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8586 | ASSERT_TRUE(http_server_properties->HasAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8587 | HostPortPair::FromURL(request.url))); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8588 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8589 | http_server_properties->GetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8590 | HostPortPair::FromURL(request.url)); |
bnc | cbd55d5f | 2014-11-06 19:50:40 | [diff] [blame] | 8591 | EXPECT_TRUE(alternate.is_broken); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8592 | } |
| 8593 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8594 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8595 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8596 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8597 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8598 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8599 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8600 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8601 | |
| 8602 | HttpRequestInfo restricted_port_request; |
| 8603 | restricted_port_request.method = "GET"; |
| 8604 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8605 | restricted_port_request.load_flags = 0; |
| 8606 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8607 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8608 | StaticSocketDataProvider first_data; |
| 8609 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8610 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8611 | |
| 8612 | MockRead data_reads[] = { |
| 8613 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8614 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8615 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8616 | }; |
| 8617 | StaticSocketDataProvider second_data( |
| 8618 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8619 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8620 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8621 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8622 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8623 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8624 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8625 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8626 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8627 | HostPortPair::FromURL(restricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8628 | kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8629 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8630 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8631 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8632 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8633 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8635 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8636 | &restricted_port_request, |
| 8637 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8638 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8639 | // Invalid change to unrestricted port should fail. |
| 8640 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8641 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8642 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8643 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8644 | AlternateProtocolPortRestrictedPermitted) { |
| 8645 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8646 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8647 | // on a restricted port (port < 1024) if we set |
| 8648 | // enable_user_alternate_protocol_ports. |
| 8649 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8650 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8651 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8652 | |
| 8653 | HttpRequestInfo restricted_port_request; |
| 8654 | restricted_port_request.method = "GET"; |
| 8655 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8656 | restricted_port_request.load_flags = 0; |
| 8657 | |
| 8658 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8659 | StaticSocketDataProvider first_data; |
| 8660 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8661 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8662 | |
| 8663 | MockRead data_reads[] = { |
| 8664 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8665 | MockRead("hello world"), |
| 8666 | MockRead(ASYNC, OK), |
| 8667 | }; |
| 8668 | StaticSocketDataProvider second_data( |
| 8669 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8670 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8671 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8672 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8673 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8674 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8675 | session->http_server_properties(); |
| 8676 | const int kUnrestrictedAlternatePort = 1024; |
| 8677 | http_server_properties->SetAlternateProtocol( |
| 8678 | HostPortPair::FromURL(restricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8679 | kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8680 | 1.0); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8681 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8682 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8683 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8684 | TestCompletionCallback callback; |
| 8685 | |
| 8686 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8687 | &restricted_port_request, |
| 8688 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8689 | // Change to unrestricted port should succeed. |
| 8690 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8691 | } |
| 8692 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8693 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8694 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8695 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8696 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8697 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8698 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8699 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8700 | |
| 8701 | HttpRequestInfo restricted_port_request; |
| 8702 | restricted_port_request.method = "GET"; |
| 8703 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8704 | restricted_port_request.load_flags = 0; |
| 8705 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8706 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8707 | StaticSocketDataProvider first_data; |
| 8708 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8709 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8710 | |
| 8711 | MockRead data_reads[] = { |
| 8712 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8713 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8714 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8715 | }; |
| 8716 | StaticSocketDataProvider second_data( |
| 8717 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8718 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8719 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8720 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8721 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8722 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8723 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8724 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8725 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8726 | HostPortPair::FromURL(restricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8727 | kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8728 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8729 | |
[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] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8732 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8734 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8735 | &restricted_port_request, |
| 8736 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8737 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8738 | // Valid change to restricted port should pass. |
| 8739 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8740 | } |
| 8741 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8742 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8743 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8744 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8745 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8746 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8747 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8748 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8749 | |
| 8750 | HttpRequestInfo unrestricted_port_request; |
| 8751 | unrestricted_port_request.method = "GET"; |
| 8752 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8753 | unrestricted_port_request.load_flags = 0; |
| 8754 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8755 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8756 | StaticSocketDataProvider first_data; |
| 8757 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8758 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8759 | |
| 8760 | MockRead data_reads[] = { |
| 8761 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8762 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8763 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8764 | }; |
| 8765 | StaticSocketDataProvider second_data( |
| 8766 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8767 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8768 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8769 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8770 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8771 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8772 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8773 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8774 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8775 | HostPortPair::FromURL(unrestricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8776 | kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8777 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8778 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8779 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8780 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8781 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8783 | int rv = trans->Start( |
| 8784 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8785 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8786 | // Valid change to restricted port should pass. |
| 8787 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8788 | } |
| 8789 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8790 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8791 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8792 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8793 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8794 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8795 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8796 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8797 | |
| 8798 | HttpRequestInfo unrestricted_port_request; |
| 8799 | unrestricted_port_request.method = "GET"; |
| 8800 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8801 | unrestricted_port_request.load_flags = 0; |
| 8802 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8803 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8804 | StaticSocketDataProvider first_data; |
| 8805 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8806 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8807 | |
| 8808 | MockRead data_reads[] = { |
| 8809 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8810 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8811 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8812 | }; |
| 8813 | StaticSocketDataProvider second_data( |
| 8814 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8815 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8816 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8817 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8818 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8819 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8820 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8821 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8822 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8823 | HostPortPair::FromURL(unrestricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8824 | kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8825 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8826 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8827 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8828 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8829 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8831 | int rv = trans->Start( |
| 8832 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8833 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8834 | // Valid change to an unrestricted port should pass. |
| 8835 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8836 | } |
| 8837 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8838 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8839 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8840 | // protocol to an unsafe port, and that we resume the second |
| 8841 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8842 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8843 | |
| 8844 | HttpRequestInfo request; |
| 8845 | request.method = "GET"; |
| 8846 | request.url = GURL("http://www.google.com/"); |
| 8847 | request.load_flags = 0; |
| 8848 | |
| 8849 | // The alternate protocol request will error out before we attempt to connect, |
| 8850 | // so only the standard HTTP request will try to connect. |
| 8851 | MockRead data_reads[] = { |
| 8852 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8853 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8854 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8855 | }; |
| 8856 | StaticSocketDataProvider data( |
| 8857 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8859 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8860 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8861 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8862 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8863 | session->http_server_properties(); |
| 8864 | const int kUnsafePort = 7; |
| 8865 | http_server_properties->SetAlternateProtocol( |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame^] | 8866 | HostPortPair::FromURL(request.url), kUnsafePort, |
| 8867 | AlternateProtocolFromNextProto(GetParam()), 1.0); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8868 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8869 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8871 | TestCompletionCallback callback; |
| 8872 | |
| 8873 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8875 | // The HTTP request should succeed. |
| 8876 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8877 | |
| 8878 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8879 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8880 | |
| 8881 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8882 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8883 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 8884 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8885 | |
| 8886 | std::string response_data; |
| 8887 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8888 | EXPECT_EQ("hello world", response_data); |
| 8889 | } |
| 8890 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8891 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8892 | session_deps_.use_alternate_protocols = true; |
| 8893 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8894 | |
| 8895 | HttpRequestInfo request; |
| 8896 | request.method = "GET"; |
| 8897 | request.url = GURL("http://www.google.com/"); |
| 8898 | request.load_flags = 0; |
| 8899 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8900 | std::string alternate_protocol_http_header = |
| 8901 | GetAlternateProtocolHttpHeader(); |
| 8902 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8903 | MockRead data_reads[] = { |
| 8904 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8905 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8906 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8907 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 8908 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8909 | }; |
| 8910 | |
| 8911 | StaticSocketDataProvider first_transaction( |
| 8912 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8913 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8914 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8915 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8916 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8918 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 8919 | scoped_ptr<SpdyFrame> req( |
| 8920 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8921 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8922 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8923 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 8924 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8925 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 8926 | CreateMockRead(*resp), |
| 8927 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8928 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8929 | }; |
| 8930 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 8931 | DelayedSocketData spdy_data( |
| 8932 | 1, // wait for one write to finish before reading. |
| 8933 | spdy_reads, arraysize(spdy_reads), |
| 8934 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8935 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8936 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8937 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8938 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 8939 | NULL, 0, NULL, 0); |
| 8940 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 8941 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8942 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8943 | &hanging_non_alternate_protocol_socket); |
| 8944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8945 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8946 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8947 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8948 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8949 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8951 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8952 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8953 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8954 | |
| 8955 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8956 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8957 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8958 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8959 | |
| 8960 | std::string response_data; |
| 8961 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8962 | EXPECT_EQ("hello world", response_data); |
| 8963 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8964 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8966 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8968 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8969 | |
| 8970 | response = trans->GetResponseInfo(); |
| 8971 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8972 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8973 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8974 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 8975 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8976 | |
| 8977 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8978 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8979 | } |
| 8980 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8981 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8982 | session_deps_.use_alternate_protocols = true; |
| 8983 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8984 | |
| 8985 | HttpRequestInfo request; |
| 8986 | request.method = "GET"; |
| 8987 | request.url = GURL("http://www.google.com/"); |
| 8988 | request.load_flags = 0; |
| 8989 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8990 | std::string alternate_protocol_http_header = |
| 8991 | GetAlternateProtocolHttpHeader(); |
| 8992 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8993 | MockRead data_reads[] = { |
| 8994 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8995 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8996 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 8997 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8998 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 8999 | }; |
| 9000 | |
| 9001 | StaticSocketDataProvider first_transaction( |
| 9002 | data_reads, arraysize(data_reads), NULL, 0); |
| 9003 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9004 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9005 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9006 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9007 | StaticSocketDataProvider hanging_socket( |
| 9008 | NULL, 0, NULL, 0); |
| 9009 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9010 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9011 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9012 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9013 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9014 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9015 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9016 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9017 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9018 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9019 | scoped_ptr<SpdyFrame> req1( |
| 9020 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9021 | scoped_ptr<SpdyFrame> req2( |
| 9022 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9023 | MockWrite spdy_writes[] = { |
| 9024 | CreateMockWrite(*req1), |
| 9025 | CreateMockWrite(*req2), |
| 9026 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9027 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9028 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9029 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9030 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9031 | MockRead spdy_reads[] = { |
| 9032 | CreateMockRead(*resp1), |
| 9033 | CreateMockRead(*data1), |
| 9034 | CreateMockRead(*resp2), |
| 9035 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9036 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9037 | }; |
| 9038 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9039 | DelayedSocketData spdy_data( |
| 9040 | 2, // wait for writes to finish before reading. |
| 9041 | spdy_reads, arraysize(spdy_reads), |
| 9042 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9043 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9044 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9045 | |
| 9046 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9047 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9048 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9049 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9050 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9051 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9053 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9055 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9056 | |
| 9057 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9058 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9059 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9060 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9061 | |
| 9062 | std::string response_data; |
| 9063 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9064 | EXPECT_EQ("hello world", response_data); |
| 9065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9066 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9067 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9068 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9071 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9072 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9073 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9074 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9075 | |
| 9076 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9077 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9078 | |
| 9079 | response = trans2.GetResponseInfo(); |
| 9080 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9081 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9082 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9083 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9084 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9085 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9086 | EXPECT_EQ("hello!", response_data); |
| 9087 | |
| 9088 | response = trans3.GetResponseInfo(); |
| 9089 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9090 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9091 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9092 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9093 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9094 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9095 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9096 | } |
| 9097 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9098 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9099 | session_deps_.use_alternate_protocols = true; |
| 9100 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9101 | |
| 9102 | HttpRequestInfo request; |
| 9103 | request.method = "GET"; |
| 9104 | request.url = GURL("http://www.google.com/"); |
| 9105 | request.load_flags = 0; |
| 9106 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9107 | std::string alternate_protocol_http_header = |
| 9108 | GetAlternateProtocolHttpHeader(); |
| 9109 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9110 | MockRead data_reads[] = { |
| 9111 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9112 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9113 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9114 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9115 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9116 | }; |
| 9117 | |
| 9118 | StaticSocketDataProvider first_transaction( |
| 9119 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9120 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9121 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9122 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9123 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9125 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9126 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9127 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9128 | NULL, 0, NULL, 0); |
| 9129 | hanging_alternate_protocol_socket.set_connect_data( |
| 9130 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9131 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9132 | &hanging_alternate_protocol_socket); |
| 9133 | |
| 9134 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9135 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9137 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9138 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9139 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9140 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9141 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9143 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9145 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9146 | |
| 9147 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9148 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9149 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9150 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9151 | |
| 9152 | std::string response_data; |
| 9153 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9154 | EXPECT_EQ("hello world", response_data); |
| 9155 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9156 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9158 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9160 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9161 | |
| 9162 | response = trans->GetResponseInfo(); |
| 9163 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9164 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9165 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9166 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9167 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9168 | |
| 9169 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9170 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9171 | } |
| 9172 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9173 | class CapturingProxyResolver : public ProxyResolver { |
| 9174 | public: |
| 9175 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9176 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9177 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9178 | int GetProxyForURL(const GURL& url, |
| 9179 | ProxyInfo* results, |
| 9180 | const CompletionCallback& callback, |
| 9181 | RequestHandle* request, |
| 9182 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9183 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9184 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9185 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9186 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9187 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9188 | } |
| 9189 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9190 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9191 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9192 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9193 | NOTREACHED(); |
| 9194 | return LOAD_STATE_IDLE; |
| 9195 | } |
| 9196 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9197 | void CancelSetPacScript() override { NOTREACHED(); } |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 9198 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9199 | int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
| 9200 | const CompletionCallback& /*callback*/) override { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9201 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9202 | } |
| 9203 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9204 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9205 | |
| 9206 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9207 | std::vector<GURL> resolved_; |
| 9208 | |
| 9209 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9210 | }; |
| 9211 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9212 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9213 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9214 | session_deps_.use_alternate_protocols = true; |
| 9215 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9216 | |
| 9217 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9218 | proxy_config.set_auto_detect(true); |
| 9219 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9220 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9221 | CapturingProxyResolver* capturing_proxy_resolver = |
| 9222 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9223 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9224 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 9225 | NULL)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9226 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9227 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9228 | |
| 9229 | HttpRequestInfo request; |
| 9230 | request.method = "GET"; |
| 9231 | request.url = GURL("http://www.google.com/"); |
| 9232 | request.load_flags = 0; |
| 9233 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9234 | std::string alternate_protocol_http_header = |
| 9235 | GetAlternateProtocolHttpHeader(); |
| 9236 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9237 | MockRead data_reads[] = { |
| 9238 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9239 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9240 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9241 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9242 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9243 | }; |
| 9244 | |
| 9245 | StaticSocketDataProvider first_transaction( |
| 9246 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9247 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9248 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9249 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9250 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9252 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9253 | scoped_ptr<SpdyFrame> req( |
| 9254 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9255 | MockWrite spdy_writes[] = { |
| 9256 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9257 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9258 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9259 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9260 | }; |
| 9261 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9262 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9263 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9264 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9265 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9266 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9267 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9268 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 9269 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9270 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9271 | }; |
| 9272 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9273 | OrderedSocketData spdy_data( |
| 9274 | spdy_reads, arraysize(spdy_reads), |
| 9275 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9276 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9277 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9278 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9279 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9280 | NULL, 0, NULL, 0); |
| 9281 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9282 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9283 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9284 | &hanging_non_alternate_protocol_socket); |
| 9285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9286 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9287 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9288 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9289 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9292 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9294 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9295 | |
| 9296 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9297 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9298 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9299 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9300 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9301 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9302 | |
| 9303 | std::string response_data; |
| 9304 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9305 | EXPECT_EQ("hello world", response_data); |
| 9306 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9307 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9309 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9311 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9312 | |
| 9313 | response = trans->GetResponseInfo(); |
| 9314 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9315 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9316 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9317 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9318 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9319 | |
| 9320 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9321 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9322 | ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9323 | EXPECT_EQ("http://www.google.com/", |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9324 | capturing_proxy_resolver->resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9325 | EXPECT_EQ("https://www.google.com/", |
| 9326 | capturing_proxy_resolver->resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9327 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9328 | LoadTimingInfo load_timing_info; |
| 9329 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9330 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9331 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9332 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9333 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9334 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9335 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9336 | session_deps_.use_alternate_protocols = true; |
| 9337 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9338 | |
| 9339 | HttpRequestInfo request; |
| 9340 | request.method = "GET"; |
| 9341 | request.url = GURL("http://www.google.com/"); |
| 9342 | request.load_flags = 0; |
| 9343 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9344 | std::string alternate_protocol_http_header = |
| 9345 | GetAlternateProtocolHttpHeader(); |
| 9346 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9347 | MockRead data_reads[] = { |
| 9348 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9349 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9350 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9351 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9352 | }; |
| 9353 | |
| 9354 | StaticSocketDataProvider first_transaction( |
| 9355 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9356 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9357 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9358 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9359 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9361 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9362 | scoped_ptr<SpdyFrame> req( |
| 9363 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9364 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9365 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9366 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9367 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9368 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9369 | CreateMockRead(*resp), |
| 9370 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9371 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9372 | }; |
| 9373 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9374 | DelayedSocketData spdy_data( |
| 9375 | 1, // wait for one write to finish before reading. |
| 9376 | spdy_reads, arraysize(spdy_reads), |
| 9377 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9378 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9379 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9380 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9381 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9382 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9383 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9384 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9387 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9388 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9389 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9390 | |
| 9391 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9392 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9393 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9394 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9395 | |
| 9396 | std::string response_data; |
| 9397 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9398 | EXPECT_EQ("hello world", response_data); |
| 9399 | |
| 9400 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9401 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9402 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9403 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9404 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9405 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9406 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9407 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9409 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9410 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9411 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9412 | |
| 9413 | response = trans->GetResponseInfo(); |
| 9414 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9415 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9416 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9417 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9418 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9419 | |
| 9420 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9421 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9422 | } |
| 9423 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9424 | // GenerateAuthToken is a mighty big test. |
| 9425 | // It tests all permutation of GenerateAuthToken behavior: |
| 9426 | // - Synchronous and Asynchronous completion. |
| 9427 | // - OK or error on completion. |
| 9428 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9429 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9430 | // - Non-authenticating and authenticating backend. |
| 9431 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9432 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9433 | // problems generating an auth token for an authenticating proxy, we don't |
| 9434 | // need to test all permutations of the backend server). |
| 9435 | // |
| 9436 | // The test proceeds by going over each of the configuration cases, and |
| 9437 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9438 | // specifies both the configuration for the test as well as the expectations |
| 9439 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9440 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9441 | static const char kServer[] = "http://www.example.com"; |
| 9442 | static const char kSecureServer[] = "https://www.example.com"; |
| 9443 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9444 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9445 | |
| 9446 | enum AuthTiming { |
| 9447 | AUTH_NONE, |
| 9448 | AUTH_SYNC, |
| 9449 | AUTH_ASYNC, |
| 9450 | }; |
| 9451 | |
| 9452 | const MockWrite kGet( |
| 9453 | "GET / HTTP/1.1\r\n" |
| 9454 | "Host: www.example.com\r\n" |
| 9455 | "Connection: keep-alive\r\n\r\n"); |
| 9456 | const MockWrite kGetProxy( |
| 9457 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9458 | "Host: www.example.com\r\n" |
| 9459 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9460 | const MockWrite kGetAuth( |
| 9461 | "GET / HTTP/1.1\r\n" |
| 9462 | "Host: www.example.com\r\n" |
| 9463 | "Connection: keep-alive\r\n" |
| 9464 | "Authorization: auth_token\r\n\r\n"); |
| 9465 | const MockWrite kGetProxyAuth( |
| 9466 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9467 | "Host: www.example.com\r\n" |
| 9468 | "Proxy-Connection: keep-alive\r\n" |
| 9469 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9470 | const MockWrite kGetAuthThroughProxy( |
| 9471 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9472 | "Host: www.example.com\r\n" |
| 9473 | "Proxy-Connection: keep-alive\r\n" |
| 9474 | "Authorization: auth_token\r\n\r\n"); |
| 9475 | const MockWrite kGetAuthWithProxyAuth( |
| 9476 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9477 | "Host: www.example.com\r\n" |
| 9478 | "Proxy-Connection: keep-alive\r\n" |
| 9479 | "Proxy-Authorization: auth_token\r\n" |
| 9480 | "Authorization: auth_token\r\n\r\n"); |
| 9481 | const MockWrite kConnect( |
| 9482 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9483 | "Host: www.example.com\r\n" |
| 9484 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9485 | const MockWrite kConnectProxyAuth( |
| 9486 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9487 | "Host: www.example.com\r\n" |
| 9488 | "Proxy-Connection: keep-alive\r\n" |
| 9489 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9490 | |
| 9491 | const MockRead kSuccess( |
| 9492 | "HTTP/1.1 200 OK\r\n" |
| 9493 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9494 | "Content-Length: 3\r\n\r\n" |
| 9495 | "Yes"); |
| 9496 | const MockRead kFailure( |
| 9497 | "Should not be called."); |
| 9498 | const MockRead kServerChallenge( |
| 9499 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9500 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9501 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9502 | "Content-Length: 14\r\n\r\n" |
| 9503 | "Unauthorized\r\n"); |
| 9504 | const MockRead kProxyChallenge( |
| 9505 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9506 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9507 | "Proxy-Connection: close\r\n" |
| 9508 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9509 | "Content-Length: 14\r\n\r\n" |
| 9510 | "Unauthorized\r\n"); |
| 9511 | const MockRead kProxyConnected( |
| 9512 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9513 | |
| 9514 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9515 | // no constructors, but the C++ compiler on Windows warns about |
| 9516 | // unspecified data in compound literals. So, moved to using constructors, |
| 9517 | // and TestRound's created with the default constructor should not be used. |
| 9518 | struct TestRound { |
| 9519 | TestRound() |
| 9520 | : expected_rv(ERR_UNEXPECTED), |
| 9521 | extra_write(NULL), |
| 9522 | extra_read(NULL) { |
| 9523 | } |
| 9524 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9525 | int expected_rv_arg) |
| 9526 | : write(write_arg), |
| 9527 | read(read_arg), |
| 9528 | expected_rv(expected_rv_arg), |
| 9529 | extra_write(NULL), |
| 9530 | extra_read(NULL) { |
| 9531 | } |
| 9532 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9533 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9534 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9535 | : write(write_arg), |
| 9536 | read(read_arg), |
| 9537 | expected_rv(expected_rv_arg), |
| 9538 | extra_write(extra_write_arg), |
| 9539 | extra_read(extra_read_arg) { |
| 9540 | } |
| 9541 | MockWrite write; |
| 9542 | MockRead read; |
| 9543 | int expected_rv; |
| 9544 | const MockWrite* extra_write; |
| 9545 | const MockRead* extra_read; |
| 9546 | }; |
| 9547 | |
| 9548 | static const int kNoSSL = 500; |
| 9549 | |
| 9550 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9551 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9552 | AuthTiming proxy_auth_timing; |
| 9553 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9554 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9555 | AuthTiming server_auth_timing; |
| 9556 | int server_auth_rv; |
| 9557 | int num_auth_rounds; |
| 9558 | int first_ssl_round; |
| 9559 | TestRound rounds[3]; |
| 9560 | } test_configs[] = { |
| 9561 | // Non-authenticating HTTP server with a direct connection. |
| 9562 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9563 | { TestRound(kGet, kSuccess, OK)}}, |
| 9564 | // Authenticating HTTP server with a direct connection. |
| 9565 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9566 | { TestRound(kGet, kServerChallenge, OK), |
| 9567 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9568 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9569 | { TestRound(kGet, kServerChallenge, OK), |
| 9570 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9571 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9572 | { TestRound(kGet, kServerChallenge, OK), |
| 9573 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9574 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9575 | { TestRound(kGet, kServerChallenge, OK), |
| 9576 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9577 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9578 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9579 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9580 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9581 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9582 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9583 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9584 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9585 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9586 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9587 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9588 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9589 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9590 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9591 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9592 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9593 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9594 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9595 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9596 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9597 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9598 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9599 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9600 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9601 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9602 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9603 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9604 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9605 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9606 | // Authenticating HTTP server through an authenticating proxy. |
| 9607 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9608 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9609 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9610 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9611 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9612 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9613 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9614 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9615 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9616 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9617 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9618 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9619 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9620 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9621 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9622 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9623 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9624 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9625 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9626 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9627 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9628 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9629 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9630 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9631 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9632 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9633 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9634 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9635 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9636 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9637 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9638 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9639 | // Non-authenticating HTTPS server with a direct connection. |
| 9640 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9641 | { TestRound(kGet, kSuccess, OK)}}, |
| 9642 | // Authenticating HTTPS server with a direct connection. |
| 9643 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9644 | { TestRound(kGet, kServerChallenge, OK), |
| 9645 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9646 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9647 | { TestRound(kGet, kServerChallenge, OK), |
| 9648 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9649 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9650 | { TestRound(kGet, kServerChallenge, OK), |
| 9651 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9652 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9653 | { TestRound(kGet, kServerChallenge, OK), |
| 9654 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9655 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9656 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9657 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9658 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9659 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9660 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9661 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9662 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9663 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9664 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9665 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9666 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9667 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9668 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9669 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9670 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9671 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9672 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9673 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9674 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9675 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9676 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9677 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9678 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9679 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9680 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9681 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9682 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9683 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9684 | // Authenticating HTTPS server through an authenticating proxy. |
| 9685 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9686 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9687 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9688 | &kGet, &kServerChallenge), |
| 9689 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9690 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9691 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9692 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9693 | &kGet, &kServerChallenge), |
| 9694 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9695 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9696 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9697 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9698 | &kGet, &kServerChallenge), |
| 9699 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9700 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9701 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9702 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9703 | &kGet, &kServerChallenge), |
| 9704 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9705 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9706 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9707 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9708 | &kGet, &kServerChallenge), |
| 9709 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9710 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9711 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9712 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9713 | &kGet, &kServerChallenge), |
| 9714 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9715 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9716 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9717 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9718 | &kGet, &kServerChallenge), |
| 9719 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9720 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9721 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9722 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9723 | &kGet, &kServerChallenge), |
| 9724 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9725 | }; |
| 9726 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9727 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9728 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9729 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9730 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9731 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9732 | |
| 9733 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9734 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9735 | for (int n = 0; n < 2; n++) { |
| 9736 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9737 | std::string auth_challenge = "Mock realm=proxy"; |
| 9738 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9739 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9740 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9741 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 9742 | origin, BoundNetLog()); |
| 9743 | auth_handler->SetGenerateExpectation( |
| 9744 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 9745 | test_config.proxy_auth_rv); |
| 9746 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9747 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9748 | } |
| 9749 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 9750 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9751 | std::string auth_challenge = "Mock realm=server"; |
| 9752 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9753 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9754 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9755 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9756 | origin, BoundNetLog()); |
| 9757 | auth_handler->SetGenerateExpectation( |
| 9758 | test_config.server_auth_timing == AUTH_ASYNC, |
| 9759 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9760 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9761 | } |
| 9762 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9763 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 9764 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9765 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9766 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9767 | } |
| 9768 | |
| 9769 | HttpRequestInfo request; |
| 9770 | request.method = "GET"; |
| 9771 | request.url = GURL(test_config.server_url); |
| 9772 | request.load_flags = 0; |
| 9773 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9774 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9775 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9776 | |
| 9777 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 9778 | const TestRound& read_write_round = test_config.rounds[round]; |
| 9779 | |
| 9780 | // Set up expected reads and writes. |
| 9781 | MockRead reads[2]; |
| 9782 | reads[0] = read_write_round.read; |
| 9783 | size_t length_reads = 1; |
| 9784 | if (read_write_round.extra_read) { |
| 9785 | reads[1] = *read_write_round.extra_read; |
| 9786 | length_reads = 2; |
| 9787 | } |
| 9788 | |
| 9789 | MockWrite writes[2]; |
| 9790 | writes[0] = read_write_round.write; |
| 9791 | size_t length_writes = 1; |
| 9792 | if (read_write_round.extra_write) { |
| 9793 | writes[1] = *read_write_round.extra_write; |
| 9794 | length_writes = 2; |
| 9795 | } |
| 9796 | StaticSocketDataProvider data_provider( |
| 9797 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9798 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9799 | |
| 9800 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9801 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9802 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9803 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9804 | &ssl_socket_data_provider); |
| 9805 | |
| 9806 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9807 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9808 | int rv; |
| 9809 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9810 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9811 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9812 | rv = trans.RestartWithAuth( |
| 9813 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9814 | } |
| 9815 | if (rv == ERR_IO_PENDING) |
| 9816 | rv = callback.WaitForResult(); |
| 9817 | |
| 9818 | // Compare results with expected data. |
| 9819 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9820 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9821 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9822 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9823 | } else { |
| 9824 | EXPECT_TRUE(response == NULL); |
| 9825 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 9826 | continue; |
| 9827 | } |
| 9828 | if (round + 1 < test_config.num_auth_rounds) { |
| 9829 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 9830 | } else { |
| 9831 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9832 | } |
| 9833 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 9834 | } |
| 9835 | } |
| 9836 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9837 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9838 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9839 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9840 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9841 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 9842 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 9843 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 9844 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9845 | |
| 9846 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9847 | auth_handler->set_connection_based(true); |
| 9848 | std::string auth_challenge = "Mock realm=server"; |
| 9849 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9850 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9851 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9852 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9853 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9854 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9855 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9856 | int rv = OK; |
| 9857 | const HttpResponseInfo* response = NULL; |
| 9858 | HttpRequestInfo request; |
| 9859 | request.method = "GET"; |
| 9860 | request.url = origin; |
| 9861 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9862 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9863 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9864 | |
| 9865 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 9866 | // to validate that the TCP socket is not released to the pool between |
| 9867 | // each round of multi-round authentication. |
| 9868 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9869 | ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); |
| 9870 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9871 | 50, // Max sockets for pool |
| 9872 | 1, // Max sockets per group |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9873 | &transport_pool_histograms, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9874 | session_deps_.host_resolver.get(), |
| 9875 | session_deps_.socket_factory.get(), |
| 9876 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9877 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 9878 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9879 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 9880 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9881 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9882 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9883 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9884 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9885 | |
| 9886 | const MockWrite kGet( |
| 9887 | "GET / HTTP/1.1\r\n" |
| 9888 | "Host: www.example.com\r\n" |
| 9889 | "Connection: keep-alive\r\n\r\n"); |
| 9890 | const MockWrite kGetAuth( |
| 9891 | "GET / HTTP/1.1\r\n" |
| 9892 | "Host: www.example.com\r\n" |
| 9893 | "Connection: keep-alive\r\n" |
| 9894 | "Authorization: auth_token\r\n\r\n"); |
| 9895 | |
| 9896 | const MockRead kServerChallenge( |
| 9897 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9898 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9899 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9900 | "Content-Length: 14\r\n\r\n" |
| 9901 | "Unauthorized\r\n"); |
| 9902 | const MockRead kSuccess( |
| 9903 | "HTTP/1.1 200 OK\r\n" |
| 9904 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9905 | "Content-Length: 3\r\n\r\n" |
| 9906 | "Yes"); |
| 9907 | |
| 9908 | MockWrite writes[] = { |
| 9909 | // First round |
| 9910 | kGet, |
| 9911 | // Second round |
| 9912 | kGetAuth, |
| 9913 | // Third round |
| 9914 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9915 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9916 | kGetAuth, |
| 9917 | // Competing request |
| 9918 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9919 | }; |
| 9920 | MockRead reads[] = { |
| 9921 | // First round |
| 9922 | kServerChallenge, |
| 9923 | // Second round |
| 9924 | kServerChallenge, |
| 9925 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9926 | kServerChallenge, |
| 9927 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9928 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9929 | // Competing response |
| 9930 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9931 | }; |
| 9932 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 9933 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9934 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9935 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9936 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9937 | |
| 9938 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9939 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9940 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9941 | if (rv == ERR_IO_PENDING) |
| 9942 | rv = callback.WaitForResult(); |
| 9943 | EXPECT_EQ(OK, rv); |
| 9944 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9945 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9946 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9947 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9948 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9949 | // In between rounds, another request comes in for the same domain. |
| 9950 | // It should not be able to grab the TCP socket that trans has already |
| 9951 | // claimed. |
| 9952 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9953 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9954 | TestCompletionCallback callback_compete; |
| 9955 | rv = trans_compete->Start( |
| 9956 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9957 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9958 | // callback_compete.WaitForResult at this point would stall forever, |
| 9959 | // since the HttpNetworkTransaction does not release the request back to |
| 9960 | // the pool until after authentication completes. |
| 9961 | |
| 9962 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9963 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9964 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9965 | if (rv == ERR_IO_PENDING) |
| 9966 | rv = callback.WaitForResult(); |
| 9967 | EXPECT_EQ(OK, rv); |
| 9968 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9969 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9970 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9971 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9972 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9973 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9974 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9975 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9976 | if (rv == ERR_IO_PENDING) |
| 9977 | rv = callback.WaitForResult(); |
| 9978 | EXPECT_EQ(OK, rv); |
| 9979 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9980 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 9981 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9982 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9983 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9984 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9985 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9986 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9987 | if (rv == ERR_IO_PENDING) |
| 9988 | rv = callback.WaitForResult(); |
| 9989 | EXPECT_EQ(OK, rv); |
| 9990 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9991 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 9992 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9993 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9994 | |
| 9995 | // Read the body since the fourth round was successful. This will also |
| 9996 | // release the socket back to the pool. |
| 9997 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9998 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 9999 | if (rv == ERR_IO_PENDING) |
| 10000 | rv = callback.WaitForResult(); |
| 10001 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10002 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10003 | EXPECT_EQ(0, rv); |
| 10004 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10005 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10006 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10007 | |
| 10008 | // The competing request can now finish. Wait for the headers and then |
| 10009 | // read the body. |
| 10010 | rv = callback_compete.WaitForResult(); |
| 10011 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10012 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10013 | if (rv == ERR_IO_PENDING) |
| 10014 | rv = callback.WaitForResult(); |
| 10015 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10016 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10017 | EXPECT_EQ(0, rv); |
| 10018 | |
| 10019 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10020 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10021 | } |
| 10022 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10023 | // This tests the case that a request is issued via http instead of spdy after |
| 10024 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10025 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10026 | session_deps_.use_alternate_protocols = true; |
| 10027 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10028 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10029 | session_deps_.next_protos = next_protos; |
| 10030 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10031 | HttpRequestInfo request; |
| 10032 | request.method = "GET"; |
| 10033 | request.url = GURL("https://www.google.com/"); |
| 10034 | request.load_flags = 0; |
| 10035 | |
| 10036 | MockWrite data_writes[] = { |
| 10037 | MockWrite("GET / HTTP/1.1\r\n" |
| 10038 | "Host: www.google.com\r\n" |
| 10039 | "Connection: keep-alive\r\n\r\n"), |
| 10040 | }; |
| 10041 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10042 | std::string alternate_protocol_http_header = |
| 10043 | GetAlternateProtocolHttpHeader(); |
| 10044 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10045 | MockRead data_reads[] = { |
| 10046 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10047 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10048 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10049 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10050 | }; |
| 10051 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10052 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10053 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 10054 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 10055 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10056 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10058 | |
| 10059 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10060 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10063 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10064 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10065 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10066 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10069 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10070 | |
| 10071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10072 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10073 | |
| 10074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10075 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10076 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10077 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10078 | |
| 10079 | std::string response_data; |
| 10080 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10081 | EXPECT_EQ("hello world", response_data); |
| 10082 | |
| 10083 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10084 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10085 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10086 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10087 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10088 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10089 | // followed by an immediate server closing of the socket. |
| 10090 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10091 | session_deps_.use_alternate_protocols = true; |
| 10092 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10093 | |
| 10094 | HttpRequestInfo request; |
| 10095 | request.method = "GET"; |
| 10096 | request.url = GURL("https://www.google.com/"); |
| 10097 | request.load_flags = 0; |
| 10098 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10099 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10100 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10102 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10103 | scoped_ptr<SpdyFrame> req( |
| 10104 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 10105 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10106 | |
| 10107 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10108 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10109 | }; |
| 10110 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10111 | DelayedSocketData spdy_data( |
| 10112 | 0, // don't wait in this case, immediate hangup. |
| 10113 | spdy_reads, arraysize(spdy_reads), |
| 10114 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10115 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10117 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10118 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10119 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10120 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10123 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10124 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10125 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10126 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10127 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10128 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10129 | // it gets it. This is needed since the auth handler may get destroyed |
| 10130 | // before we get a chance to query it. |
| 10131 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10132 | public: |
| 10133 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10134 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10135 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10136 | |
| 10137 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10138 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10139 | const HttpRequestInfo* request, |
| 10140 | const CompletionCallback& callback, |
| 10141 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10142 | *url_ = request->url; |
| 10143 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10144 | credentials, request, callback, auth_token); |
| 10145 | } |
| 10146 | |
| 10147 | private: |
| 10148 | GURL* url_; |
| 10149 | }; |
| 10150 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10151 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10152 | // This test ensures that the URL passed into the proxy is upgraded |
| 10153 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10154 | session_deps_.use_alternate_protocols = true; |
| 10155 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10156 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10157 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10158 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 10159 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10160 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10161 | GURL request_url; |
| 10162 | { |
| 10163 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10164 | new HttpAuthHandlerMock::Factory(); |
| 10165 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10166 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10167 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10168 | auth_factory->set_do_init_from_challenge(true); |
| 10169 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10170 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10171 | |
| 10172 | HttpRequestInfo request; |
| 10173 | request.method = "GET"; |
| 10174 | request.url = GURL("http://www.google.com"); |
| 10175 | request.load_flags = 0; |
| 10176 | |
| 10177 | // First round goes unauthenticated through the proxy. |
| 10178 | MockWrite data_writes_1[] = { |
| 10179 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10180 | "Host: www.google.com\r\n" |
| 10181 | "Proxy-Connection: keep-alive\r\n" |
| 10182 | "\r\n"), |
| 10183 | }; |
| 10184 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10185 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10186 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10187 | MockRead("Alternate-Protocol: 443:"), |
| 10188 | MockRead(GetAlternateProtocolFromParam()), |
| 10189 | MockRead("\r\n"), |
| 10190 | MockRead("Proxy-Connection: close\r\n"), |
| 10191 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10192 | }; |
| 10193 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10194 | data_writes_1, arraysize(data_writes_1)); |
| 10195 | |
| 10196 | // Second round tries to tunnel to www.google.com due to the |
| 10197 | // Alternate-Protocol announcement in the first round. It fails due |
| 10198 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10199 | // After the failure, a tunnel is established to www.google.com using |
| 10200 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10201 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10202 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10203 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10204 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10205 | // to obtain a new one. |
| 10206 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10207 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10208 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10209 | // establishment and SPDY framing issues. Alas, the |
| 10210 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10211 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10212 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10213 | scoped_ptr<SpdyFrame> req( |
| 10214 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10215 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10216 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10217 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10218 | MockWrite data_writes_2[] = { |
| 10219 | // First connection attempt without Proxy-Authorization. |
| 10220 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10221 | "Host: www.google.com\r\n" |
| 10222 | "Proxy-Connection: keep-alive\r\n" |
| 10223 | "\r\n"), |
| 10224 | |
| 10225 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10226 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10227 | "Host: www.google.com\r\n" |
| 10228 | "Proxy-Connection: keep-alive\r\n" |
| 10229 | "Proxy-Authorization: auth_token\r\n" |
| 10230 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10231 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10232 | // SPDY request |
| 10233 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10234 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10235 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10236 | "Proxy-Authenticate: Mock\r\n" |
| 10237 | "Proxy-Connection: close\r\n" |
| 10238 | "\r\n"); |
| 10239 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10240 | MockRead data_reads_2[] = { |
| 10241 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10242 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 10243 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10244 | arraysize(kRejectConnectResponse) - 1, 1), |
| 10245 | |
| 10246 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10247 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10248 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10249 | |
| 10250 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10251 | CreateMockRead(*resp.get(), 6), |
| 10252 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10253 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10254 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10255 | OrderedSocketData data_2( |
| 10256 | data_reads_2, arraysize(data_reads_2), |
| 10257 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10258 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10259 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10260 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10261 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10262 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10263 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10264 | NULL, 0, NULL, 0); |
| 10265 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10266 | never_finishing_connect); |
| 10267 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10268 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10269 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10271 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10272 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10273 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10274 | |
| 10275 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10276 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10277 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10279 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10280 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10281 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10282 | |
| 10283 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10284 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10285 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10287 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10288 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10289 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10290 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10291 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10292 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10293 | |
| 10294 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10295 | TestCompletionCallback callback_3; |
| 10296 | rv = trans_2->RestartWithAuth( |
| 10297 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10299 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10300 | |
| 10301 | // After all that work, these two lines (or actually, just the scheme) are |
| 10302 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10303 | EXPECT_EQ("https", request_url.scheme()); |
| 10304 | EXPECT_EQ("www.google.com", request_url.host()); |
| 10305 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10306 | LoadTimingInfo load_timing_info; |
| 10307 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10308 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10309 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10310 | } |
| 10311 | |
| 10312 | // Test that if we cancel the transaction as the connection is completing, that |
| 10313 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10314 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10315 | // Setup everything about the connection to complete synchronously, so that |
| 10316 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10317 | // for is the callback from the HttpStreamRequest. |
| 10318 | // Then cancel the transaction. |
| 10319 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10320 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10321 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10322 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10323 | MockRead(SYNCHRONOUS, "hello world"), |
| 10324 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10325 | }; |
| 10326 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10327 | HttpRequestInfo request; |
| 10328 | request.method = "GET"; |
| 10329 | request.url = GURL("http://www.google.com/"); |
| 10330 | request.load_flags = 0; |
| 10331 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10332 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10333 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10334 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10336 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10337 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10338 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10339 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10341 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10342 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10343 | CapturingBoundNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10344 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10345 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10346 | trans.reset(); // Cancel the transaction here. |
| 10347 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10348 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10349 | } |
| 10350 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10351 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10352 | // stream is drained properly and added back to the socket pool. The main |
| 10353 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10354 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10355 | // deleted. |
| 10356 | // See http://crbug.com/368418 |
| 10357 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10358 | MockRead data_reads[] = { |
| 10359 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10360 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10361 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10362 | MockRead(ASYNC, "1"), |
| 10363 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10364 | // HttpNetworkTransaction has been deleted. |
| 10365 | MockRead(ASYNC, "2"), |
| 10366 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10367 | }; |
| 10368 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10370 | |
| 10371 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10372 | |
| 10373 | { |
| 10374 | HttpRequestInfo request; |
| 10375 | request.method = "GET"; |
| 10376 | request.url = GURL("http://www.google.com/"); |
| 10377 | request.load_flags = 0; |
| 10378 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10380 | TestCompletionCallback callback; |
| 10381 | |
| 10382 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10383 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10384 | callback.WaitForResult(); |
| 10385 | |
| 10386 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10387 | ASSERT_TRUE(response != NULL); |
| 10388 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10389 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10390 | |
| 10391 | // The transaction and HttpRequestInfo are deleted. |
| 10392 | } |
| 10393 | |
| 10394 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10395 | base::MessageLoop::current()->RunUntilIdle(); |
| 10396 | |
| 10397 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10398 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10399 | } |
| 10400 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10401 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10402 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10403 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10404 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10405 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10406 | session_deps_.net_log = log.bound().net_log(); |
| 10407 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10408 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10409 | HttpRequestInfo request; |
| 10410 | request.method = "GET"; |
| 10411 | request.url = GURL("http://www.google.com/"); |
| 10412 | |
| 10413 | MockWrite data_writes1[] = { |
| 10414 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10415 | "Host: www.google.com\r\n" |
| 10416 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10417 | }; |
| 10418 | |
| 10419 | MockRead data_reads1[] = { |
| 10420 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10421 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10422 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10423 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10424 | }; |
| 10425 | |
| 10426 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10427 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10428 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10430 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10431 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10432 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10433 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10434 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10435 | trans->SetBeforeProxyHeadersSentCallback( |
| 10436 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10437 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10439 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10440 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10441 | |
| 10442 | rv = callback1.WaitForResult(); |
| 10443 | EXPECT_EQ(OK, rv); |
| 10444 | |
| 10445 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10446 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10447 | |
| 10448 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10449 | EXPECT_EQ(200, response->headers->response_code()); |
| 10450 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10451 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10452 | EXPECT_TRUE( |
| 10453 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10454 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10455 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10456 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10457 | |
| 10458 | LoadTimingInfo load_timing_info; |
| 10459 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10460 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10461 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10462 | } |
| 10463 | |
| 10464 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10465 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10466 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10467 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10468 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10469 | session_deps_.net_log = log.bound().net_log(); |
| 10470 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10471 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10472 | HttpRequestInfo request; |
| 10473 | request.method = "GET"; |
| 10474 | request.url = GURL("https://www.google.com/"); |
| 10475 | |
| 10476 | // Since we have proxy, should try to establish tunnel. |
| 10477 | MockWrite data_writes1[] = { |
| 10478 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10479 | "Host: www.google.com\r\n" |
| 10480 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10481 | |
| 10482 | MockWrite("GET / HTTP/1.1\r\n" |
| 10483 | "Host: www.google.com\r\n" |
| 10484 | "Connection: keep-alive\r\n\r\n"), |
| 10485 | }; |
| 10486 | |
| 10487 | MockRead data_reads1[] = { |
| 10488 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 10489 | |
| 10490 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10491 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10492 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10493 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10494 | }; |
| 10495 | |
| 10496 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10497 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10498 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10499 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10502 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10503 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10504 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10505 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10507 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10508 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10509 | |
| 10510 | rv = callback1.WaitForResult(); |
| 10511 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10512 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10513 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10514 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10515 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10516 | NetLog::PHASE_NONE); |
| 10517 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10518 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10519 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10520 | NetLog::PHASE_NONE); |
| 10521 | |
| 10522 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10523 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10524 | |
| 10525 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10526 | EXPECT_EQ(200, response->headers->response_code()); |
| 10527 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10528 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10529 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10530 | EXPECT_TRUE( |
| 10531 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10532 | |
| 10533 | LoadTimingInfo load_timing_info; |
| 10534 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10535 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10536 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10537 | } |
| 10538 | |
| 10539 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 10540 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10541 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10542 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10543 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10544 | session_deps_.net_log = log.bound().net_log(); |
| 10545 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10546 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10547 | HttpRequestInfo request; |
| 10548 | request.method = "GET"; |
| 10549 | request.url = GURL("https://www.google.com/"); |
| 10550 | |
| 10551 | // Since we have proxy, should try to establish tunnel. |
| 10552 | MockWrite data_writes1[] = { |
| 10553 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10554 | "Host: www.google.com\r\n" |
| 10555 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10556 | |
| 10557 | MockWrite("GET / HTTP/1.1\r\n" |
| 10558 | "Host: www.google.com\r\n" |
| 10559 | "Connection: keep-alive\r\n\r\n"), |
| 10560 | }; |
| 10561 | |
| 10562 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10563 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10564 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10565 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10566 | }; |
| 10567 | |
| 10568 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10569 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10570 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10571 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10574 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10575 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10576 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10577 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10579 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10581 | |
| 10582 | rv = callback1.WaitForResult(); |
| 10583 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10584 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10585 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10586 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10587 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10588 | NetLog::PHASE_NONE); |
| 10589 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10590 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10591 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10592 | NetLog::PHASE_NONE); |
| 10593 | } |
| 10594 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10595 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10596 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10597 | scoped_ptr<SpdyFrame> req( |
| 10598 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10599 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 10600 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10601 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10602 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10603 | MockRead spdy_reads[] = { |
| 10604 | CreateMockRead(*resp), |
| 10605 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10606 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10607 | }; |
| 10608 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10609 | DelayedSocketData spdy_data( |
| 10610 | 1, // wait for one write to finish before reading. |
| 10611 | spdy_reads, arraysize(spdy_reads), |
| 10612 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10613 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10614 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10615 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10616 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10618 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10619 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10620 | |
| 10621 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10622 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10623 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10624 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10625 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10626 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10627 | |
| 10628 | HttpRequestInfo request; |
| 10629 | request.method = "GET"; |
| 10630 | request.url = GURL("https://www.google.com/"); |
| 10631 | request.load_flags = 0; |
| 10632 | |
| 10633 | // This is the important line that marks this as a preconnect. |
| 10634 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10635 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10636 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10637 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10638 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10639 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10640 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10641 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10642 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10643 | } |
| 10644 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10645 | // Given a net error, cause that error to be returned from the first Write() |
| 10646 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10647 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10648 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10649 | net::HttpRequestInfo request_info; |
| 10650 | request_info.url = GURL("https://www.example.com/"); |
| 10651 | request_info.method = "GET"; |
| 10652 | request_info.load_flags = net::LOAD_NORMAL; |
| 10653 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10654 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10655 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10656 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10657 | }; |
| 10658 | net::StaticSocketDataProvider data(NULL, 0, |
| 10659 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10662 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10663 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10664 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10665 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10667 | TestCompletionCallback callback; |
| 10668 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10669 | if (rv == net::ERR_IO_PENDING) |
| 10670 | rv = callback.WaitForResult(); |
| 10671 | ASSERT_EQ(error, rv); |
| 10672 | } |
| 10673 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10674 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10675 | // Just check a grab bag of cert errors. |
| 10676 | static const int kErrors[] = { |
| 10677 | ERR_CERT_COMMON_NAME_INVALID, |
| 10678 | ERR_CERT_AUTHORITY_INVALID, |
| 10679 | ERR_CERT_DATE_INVALID, |
| 10680 | }; |
| 10681 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10682 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10683 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10684 | } |
| 10685 | } |
| 10686 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10687 | // Ensure that a client certificate is removed from the SSL client auth |
| 10688 | // cache when: |
| 10689 | // 1) No proxy is involved. |
| 10690 | // 2) TLS False Start is disabled. |
| 10691 | // 3) The initial TLS handshake requests a client certificate. |
| 10692 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10693 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10694 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10695 | net::HttpRequestInfo request_info; |
| 10696 | request_info.url = GURL("https://www.example.com/"); |
| 10697 | request_info.method = "GET"; |
| 10698 | request_info.load_flags = net::LOAD_NORMAL; |
| 10699 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10700 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10701 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10702 | |
| 10703 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 10704 | // CertificateRequest is received for the first time, the handshake will |
| 10705 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10706 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10707 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10709 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10710 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10711 | |
| 10712 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 10713 | // False Start is not being used, the result of the SSL handshake will be |
| 10714 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 10715 | // matches the result of a server sending a handshake_failure alert, |
| 10716 | // rather than a Finished message, because it requires a client |
| 10717 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10718 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10719 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10721 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10722 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10723 | |
| 10724 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 10725 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10726 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 10727 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10728 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10729 | // requiring a client certificate, this fallback handshake should also |
| 10730 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10731 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10732 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10734 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10735 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10736 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10737 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 10738 | // connection to a server fails during an SSL handshake, |
| 10739 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 10740 | // connection was attempted with TLSv1. This is transparent to the caller |
| 10741 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10742 | // requiring a client certificate, this fallback handshake should also |
| 10743 | // fail. |
| 10744 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10745 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10747 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10748 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10749 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10750 | // Need one more if TLSv1.2 is enabled. |
| 10751 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10752 | ssl_data5.cert_request_info = cert_request.get(); |
| 10753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10754 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 10755 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10756 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10757 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10758 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10759 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10760 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10761 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10762 | TestCompletionCallback callback; |
| 10763 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10764 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10765 | |
| 10766 | // Complete the SSL handshake, which should abort due to requiring a |
| 10767 | // client certificate. |
| 10768 | rv = callback.WaitForResult(); |
| 10769 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10770 | |
| 10771 | // Indicate that no certificate should be supplied. From the perspective |
| 10772 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10773 | // certificate, so this is the same as supply a |
| 10774 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10775 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10776 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10777 | |
| 10778 | // Ensure the certificate was added to the client auth cache before |
| 10779 | // allowing the connection to continue restarting. |
| 10780 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10781 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10782 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10783 | ASSERT_EQ(NULL, client_cert.get()); |
| 10784 | |
| 10785 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10786 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10787 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10788 | rv = callback.WaitForResult(); |
| 10789 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10790 | |
| 10791 | // Ensure that the client certificate is removed from the cache on a |
| 10792 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10793 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10794 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10795 | } |
| 10796 | |
| 10797 | // Ensure that a client certificate is removed from the SSL client auth |
| 10798 | // cache when: |
| 10799 | // 1) No proxy is involved. |
| 10800 | // 2) TLS False Start is enabled. |
| 10801 | // 3) The initial TLS handshake requests a client certificate. |
| 10802 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10803 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10804 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10805 | net::HttpRequestInfo request_info; |
| 10806 | request_info.url = GURL("https://www.example.com/"); |
| 10807 | request_info.method = "GET"; |
| 10808 | request_info.load_flags = net::LOAD_NORMAL; |
| 10809 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10810 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10811 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10812 | |
| 10813 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 10814 | // return successfully after reading up to the peer's Certificate message. |
| 10815 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 10816 | // enqueue application data to be sent in the same packet as the |
| 10817 | // ChangeCipherSpec and Finished messages. |
| 10818 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 10819 | // called, which expects to process the peer's ChangeCipherSpec and |
| 10820 | // Finished messages. If there was an error negotiating with the peer, |
| 10821 | // such as due to the peer requiring a client certificate when none was |
| 10822 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 10823 | // called. |
| 10824 | |
| 10825 | // Like the non-False Start case, when a client certificate is requested by |
| 10826 | // the peer, the handshake is aborted during the Connect() call. |
| 10827 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10828 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10829 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10831 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10832 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10833 | |
| 10834 | // When a client certificate is supplied, Connect() will not be aborted |
| 10835 | // when the peer requests the certificate. Instead, the handshake will |
| 10836 | // artificially succeed, allowing the caller to write the HTTP request to |
| 10837 | // the socket. The handshake messages are not processed until Read() is |
| 10838 | // called, which then detects that the handshake was aborted, due to the |
| 10839 | // peer sending a handshake_failure because it requires a client |
| 10840 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10841 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10842 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10844 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10845 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10846 | }; |
| 10847 | net::StaticSocketDataProvider data2( |
| 10848 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10849 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10850 | |
| 10851 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10852 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 10853 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10854 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10855 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10856 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10857 | net::StaticSocketDataProvider data3( |
| 10858 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10859 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10860 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10861 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 10862 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 10863 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 10864 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10866 | net::StaticSocketDataProvider data4( |
| 10867 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10868 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10869 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10870 | // Need one more if TLSv1.2 is enabled. |
| 10871 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 10872 | ssl_data5.cert_request_info = cert_request.get(); |
| 10873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10874 | net::StaticSocketDataProvider data5( |
| 10875 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 10876 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10877 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10878 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10879 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10881 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10882 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10883 | TestCompletionCallback callback; |
| 10884 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10885 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10886 | |
| 10887 | // Complete the SSL handshake, which should abort due to requiring a |
| 10888 | // client certificate. |
| 10889 | rv = callback.WaitForResult(); |
| 10890 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10891 | |
| 10892 | // Indicate that no certificate should be supplied. From the perspective |
| 10893 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10894 | // certificate, so this is the same as supply a |
| 10895 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10896 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10897 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10898 | |
| 10899 | // Ensure the certificate was added to the client auth cache before |
| 10900 | // allowing the connection to continue restarting. |
| 10901 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10902 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10903 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10904 | ASSERT_EQ(NULL, client_cert.get()); |
| 10905 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10906 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10907 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 10908 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10909 | rv = callback.WaitForResult(); |
| 10910 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 10911 | |
| 10912 | // Ensure that the client certificate is removed from the cache on a |
| 10913 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10914 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 10915 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10916 | } |
| 10917 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10918 | // Ensure that a client certificate is removed from the SSL client auth |
| 10919 | // cache when: |
| 10920 | // 1) An HTTPS proxy is involved. |
| 10921 | // 3) The HTTPS proxy requests a client certificate. |
| 10922 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 10923 | // proxy. |
| 10924 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 10925 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10926 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10927 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10928 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10929 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10930 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10931 | |
| 10932 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10933 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10934 | |
| 10935 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 10936 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 10937 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 10938 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10939 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10940 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10942 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10943 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10944 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10945 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10946 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10948 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10949 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10950 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10951 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 10952 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10953 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10954 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10956 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10957 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10958 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10959 | |
| 10960 | net::HttpRequestInfo requests[2]; |
| 10961 | requests[0].url = GURL("https://www.example.com/"); |
| 10962 | requests[0].method = "GET"; |
| 10963 | requests[0].load_flags = net::LOAD_NORMAL; |
| 10964 | |
| 10965 | requests[1].url = GURL("http://www.example.com/"); |
| 10966 | requests[1].method = "GET"; |
| 10967 | requests[1].load_flags = net::LOAD_NORMAL; |
| 10968 | |
| 10969 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10970 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 10971 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10972 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10974 | |
| 10975 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10976 | TestCompletionCallback callback; |
| 10977 | int rv = trans->Start( |
| 10978 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10979 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10980 | |
| 10981 | // Complete the SSL handshake, which should abort due to requiring a |
| 10982 | // client certificate. |
| 10983 | rv = callback.WaitForResult(); |
| 10984 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10985 | |
| 10986 | // Indicate that no certificate should be supplied. From the perspective |
| 10987 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10988 | // certificate, so this is the same as supply a |
| 10989 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10990 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10991 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10992 | |
| 10993 | // Ensure the certificate was added to the client auth cache before |
| 10994 | // allowing the connection to continue restarting. |
| 10995 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10996 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 10997 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 10998 | ASSERT_EQ(NULL, client_cert.get()); |
| 10999 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11000 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11001 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11002 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11003 | |
| 11004 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11005 | // then consume ssl_data3, which should also fail. The result code is |
| 11006 | // checked against what ssl_data3 should return. |
| 11007 | rv = callback.WaitForResult(); |
| 11008 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 11009 | |
| 11010 | // Now that the new handshake has failed, ensure that the client |
| 11011 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11012 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11013 | HostPortPair("proxy", 70), &client_cert)); |
| 11014 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11015 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11016 | } |
| 11017 | } |
| 11018 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11019 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 11020 | // TEST_P is a macro that expands directly to code that stringizes the |
| 11021 | // arguments. As a result, macros passed as parameters (such as prefix |
| 11022 | // or test_case_name) will not be expanded by the preprocessor. To |
| 11023 | // work around this, indirect the macro for TEST_P, so that the |
| 11024 | // pre-processor will expand macros such as MAYBE_test_name before |
| 11025 | // instantiating the test. |
| 11026 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 11027 | TEST_P(test_case_name, test_name) |
| 11028 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11029 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11030 | #if defined(OS_WIN) |
| 11031 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 11032 | #else |
| 11033 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 11034 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11035 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11036 | session_deps_.use_alternate_protocols = true; |
| 11037 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11038 | |
| 11039 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11040 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11041 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11042 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11043 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11044 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11045 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11046 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11048 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11049 | scoped_ptr<SpdyFrame> host1_req( |
| 11050 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11051 | scoped_ptr<SpdyFrame> host2_req( |
| 11052 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11053 | MockWrite spdy_writes[] = { |
| 11054 | CreateMockWrite(*host1_req, 1), |
| 11055 | CreateMockWrite(*host2_req, 4), |
| 11056 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11057 | scoped_ptr<SpdyFrame> host1_resp( |
| 11058 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11059 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11060 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11061 | scoped_ptr<SpdyFrame> host2_resp( |
| 11062 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11063 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11064 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11065 | MockRead spdy_reads[] = { |
| 11066 | CreateMockRead(*host1_resp, 2), |
| 11067 | CreateMockRead(*host1_resp_body, 3), |
| 11068 | CreateMockRead(*host2_resp, 5), |
| 11069 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11070 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11071 | }; |
| 11072 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11073 | IPAddressNumber ip; |
| 11074 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11075 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11076 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11077 | OrderedSocketData spdy_data( |
| 11078 | connect, |
| 11079 | spdy_reads, arraysize(spdy_reads), |
| 11080 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11081 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11082 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11083 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11084 | HttpRequestInfo request1; |
| 11085 | request1.method = "GET"; |
| 11086 | request1.url = GURL("https://www.google.com/"); |
| 11087 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11088 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11090 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11092 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11093 | |
| 11094 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11095 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11096 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11097 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11098 | |
| 11099 | std::string response_data; |
| 11100 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11101 | EXPECT_EQ("hello!", response_data); |
| 11102 | |
| 11103 | // Preload www.gmail.com into HostCache. |
| 11104 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11105 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11106 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11107 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11108 | DEFAULT_PRIORITY, |
| 11109 | &ignored, |
| 11110 | callback.callback(), |
| 11111 | NULL, |
| 11112 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11113 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11114 | rv = callback.WaitForResult(); |
| 11115 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11116 | |
| 11117 | HttpRequestInfo request2; |
| 11118 | request2.method = "GET"; |
| 11119 | request2.url = GURL("https://www.gmail.com/"); |
| 11120 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11121 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11123 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11124 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11125 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11126 | |
| 11127 | response = trans2.GetResponseInfo(); |
| 11128 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11129 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11130 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11131 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11132 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11133 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11134 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11135 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11136 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11137 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11138 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11139 | session_deps_.use_alternate_protocols = true; |
| 11140 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11141 | |
| 11142 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11143 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11144 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11145 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11146 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11147 | |
| 11148 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11149 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11150 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11151 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11152 | scoped_ptr<SpdyFrame> host1_req( |
| 11153 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11154 | scoped_ptr<SpdyFrame> host2_req( |
| 11155 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11156 | MockWrite spdy_writes[] = { |
| 11157 | CreateMockWrite(*host1_req, 1), |
| 11158 | CreateMockWrite(*host2_req, 4), |
| 11159 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11160 | scoped_ptr<SpdyFrame> host1_resp( |
| 11161 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11162 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11163 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11164 | scoped_ptr<SpdyFrame> host2_resp( |
| 11165 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11166 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11167 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11168 | MockRead spdy_reads[] = { |
| 11169 | CreateMockRead(*host1_resp, 2), |
| 11170 | CreateMockRead(*host1_resp_body, 3), |
| 11171 | CreateMockRead(*host2_resp, 5), |
| 11172 | CreateMockRead(*host2_resp_body, 6), |
| 11173 | MockRead(ASYNC, 0, 7), |
| 11174 | }; |
| 11175 | |
| 11176 | IPAddressNumber ip; |
| 11177 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11178 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11179 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11180 | OrderedSocketData spdy_data( |
| 11181 | connect, |
| 11182 | spdy_reads, arraysize(spdy_reads), |
| 11183 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11184 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11185 | |
| 11186 | TestCompletionCallback callback; |
| 11187 | HttpRequestInfo request1; |
| 11188 | request1.method = "GET"; |
| 11189 | request1.url = GURL("https://www.google.com/"); |
| 11190 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11191 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11192 | |
| 11193 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11194 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11195 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11196 | |
| 11197 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11198 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11199 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11200 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11201 | |
| 11202 | std::string response_data; |
| 11203 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11204 | EXPECT_EQ("hello!", response_data); |
| 11205 | |
| 11206 | HttpRequestInfo request2; |
| 11207 | request2.method = "GET"; |
| 11208 | request2.url = GURL("https://www.gmail.com/"); |
| 11209 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11210 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11211 | |
| 11212 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11214 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11215 | |
| 11216 | response = trans2.GetResponseInfo(); |
| 11217 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11218 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11219 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11220 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11221 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11222 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11223 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11224 | } |
| 11225 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11226 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 11227 | public: |
| 11228 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11229 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11230 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11231 | |
| 11232 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11233 | |
| 11234 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11235 | int Resolve(const RequestInfo& info, |
| 11236 | RequestPriority priority, |
| 11237 | AddressList* addresses, |
| 11238 | const CompletionCallback& callback, |
| 11239 | RequestHandle* out_req, |
| 11240 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11241 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11242 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11243 | } |
| 11244 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11245 | int ResolveFromCache(const RequestInfo& info, |
| 11246 | AddressList* addresses, |
| 11247 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11248 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11249 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11250 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11251 | return rv; |
| 11252 | } |
| 11253 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11254 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11255 | host_resolver_.CancelRequest(req); |
| 11256 | } |
| 11257 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11258 | MockCachingHostResolver* GetMockHostResolver() { |
| 11259 | return &host_resolver_; |
| 11260 | } |
| 11261 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11262 | private: |
| 11263 | MockCachingHostResolver host_resolver_; |
| 11264 | const HostPortPair host_port_; |
| 11265 | }; |
| 11266 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11267 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11268 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11269 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11270 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11271 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11272 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11273 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11274 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11275 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 11276 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11277 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 11278 | // prefix doesn't work with parametrized tests). |
| 11279 | #if defined(OS_WIN) |
| 11280 | return; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11281 | #else |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11282 | session_deps_.use_alternate_protocols = true; |
| 11283 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11284 | |
| 11285 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11286 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11287 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11288 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11289 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11290 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11291 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11292 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11293 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11294 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11295 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11297 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11298 | scoped_ptr<SpdyFrame> host1_req( |
| 11299 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11300 | scoped_ptr<SpdyFrame> host2_req( |
| 11301 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11302 | MockWrite spdy_writes[] = { |
| 11303 | CreateMockWrite(*host1_req, 1), |
| 11304 | CreateMockWrite(*host2_req, 4), |
| 11305 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11306 | scoped_ptr<SpdyFrame> host1_resp( |
| 11307 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11308 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11309 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11310 | scoped_ptr<SpdyFrame> host2_resp( |
| 11311 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11312 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11313 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11314 | MockRead spdy_reads[] = { |
| 11315 | CreateMockRead(*host1_resp, 2), |
| 11316 | CreateMockRead(*host1_resp_body, 3), |
| 11317 | CreateMockRead(*host2_resp, 5), |
| 11318 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11319 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11320 | }; |
| 11321 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11322 | IPAddressNumber ip; |
| 11323 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11324 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11325 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11326 | OrderedSocketData spdy_data( |
| 11327 | connect, |
| 11328 | spdy_reads, arraysize(spdy_reads), |
| 11329 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11330 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11331 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11332 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11333 | HttpRequestInfo request1; |
| 11334 | request1.method = "GET"; |
| 11335 | request1.url = GURL("https://www.google.com/"); |
| 11336 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11337 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11339 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11341 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11342 | |
| 11343 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11344 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11345 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11346 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11347 | |
| 11348 | std::string response_data; |
| 11349 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11350 | EXPECT_EQ("hello!", response_data); |
| 11351 | |
| 11352 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11353 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11354 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11355 | rv = host_resolver.Resolve(resolve_info, |
| 11356 | DEFAULT_PRIORITY, |
| 11357 | &ignored, |
| 11358 | callback.callback(), |
| 11359 | NULL, |
| 11360 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11361 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11362 | rv = callback.WaitForResult(); |
| 11363 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11364 | |
| 11365 | HttpRequestInfo request2; |
| 11366 | request2.method = "GET"; |
| 11367 | request2.url = GURL("https://www.gmail.com/"); |
| 11368 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11369 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11371 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11372 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11373 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11374 | |
| 11375 | response = trans2.GetResponseInfo(); |
| 11376 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11377 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11378 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11379 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11380 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11381 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11382 | EXPECT_EQ("hello!", response_data); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11383 | #endif |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11384 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11385 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11386 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11387 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11388 | const std::string https_url = "https://www.google.com:8080/"; |
| 11389 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11390 | |
| 11391 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11392 | scoped_ptr<SpdyFrame> req1( |
| 11393 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11394 | |
| 11395 | MockWrite writes1[] = { |
| 11396 | CreateMockWrite(*req1, 0), |
| 11397 | }; |
| 11398 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11399 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11400 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11401 | MockRead reads1[] = { |
| 11402 | CreateMockRead(*resp1, 1), |
| 11403 | CreateMockRead(*body1, 2), |
| 11404 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11405 | }; |
| 11406 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11407 | DelayedSocketData data1( |
| 11408 | 1, reads1, arraysize(reads1), |
| 11409 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11410 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11411 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11412 | |
| 11413 | // HTTP GET for the HTTP URL |
| 11414 | MockWrite writes2[] = { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11415 | MockWrite(ASYNC, 4, |
| 11416 | "GET / HTTP/1.1\r\n" |
| 11417 | "Host: www.google.com:8080\r\n" |
| 11418 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11419 | }; |
| 11420 | |
| 11421 | MockRead reads2[] = { |
| 11422 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11423 | MockRead(ASYNC, 6, "hello"), |
| 11424 | MockRead(ASYNC, 7, OK), |
| 11425 | }; |
| 11426 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11427 | DelayedSocketData data2( |
| 11428 | 1, reads2, arraysize(reads2), |
| 11429 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11430 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11431 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11432 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11434 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11435 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11436 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11437 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11438 | |
| 11439 | // Start the first transaction to set up the SpdySession |
| 11440 | HttpRequestInfo request1; |
| 11441 | request1.method = "GET"; |
| 11442 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11443 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11444 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11445 | TestCompletionCallback callback1; |
| 11446 | EXPECT_EQ(ERR_IO_PENDING, |
| 11447 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11448 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11449 | |
| 11450 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11451 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11452 | |
| 11453 | // Now, start the HTTP request |
| 11454 | HttpRequestInfo request2; |
| 11455 | request2.method = "GET"; |
| 11456 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11457 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11458 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11459 | TestCompletionCallback callback2; |
| 11460 | EXPECT_EQ(ERR_IO_PENDING, |
| 11461 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11462 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11463 | |
| 11464 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11465 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11466 | } |
| 11467 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11468 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11469 | const std::string https_url = "https://www.google.com:8080/"; |
| 11470 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11471 | |
| 11472 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11473 | const HostPortPair host_port_pair("www.google.com", 8080); |
| 11474 | scoped_ptr<SpdyFrame> connect( |
| 11475 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11476 | scoped_ptr<SpdyFrame> req1( |
| 11477 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11478 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 11479 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11480 | |
| 11481 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11482 | SpdyHeaderBlock req2_block; |
| 11483 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11484 | req2_block[spdy_util_.GetPathKey()] = "/"; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11485 | req2_block[spdy_util_.GetHostKey()] = "www.google.com:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11486 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 11487 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11488 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11489 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11490 | |
| 11491 | MockWrite writes1[] = { |
| 11492 | CreateMockWrite(*connect, 0), |
| 11493 | CreateMockWrite(*wrapped_req1, 2), |
| 11494 | CreateMockWrite(*req2, 5), |
| 11495 | }; |
| 11496 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11497 | scoped_ptr<SpdyFrame> conn_resp( |
| 11498 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11499 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11500 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11501 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 11502 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 11503 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 11504 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 11505 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11506 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11507 | MockRead reads1[] = { |
| 11508 | CreateMockRead(*conn_resp, 1), |
| 11509 | CreateMockRead(*wrapped_resp1, 3), |
| 11510 | CreateMockRead(*wrapped_body1, 4), |
| 11511 | CreateMockRead(*resp2, 6), |
| 11512 | CreateMockRead(*body2, 7), |
| 11513 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 11514 | }; |
| 11515 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11516 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 11517 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11518 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11519 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11520 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11521 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11522 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 11523 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11524 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11525 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11526 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11527 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11528 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11529 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11530 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11531 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11532 | |
| 11533 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11534 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11535 | |
| 11536 | // Start the first transaction to set up the SpdySession |
| 11537 | HttpRequestInfo request1; |
| 11538 | request1.method = "GET"; |
| 11539 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11540 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11541 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11542 | TestCompletionCallback callback1; |
| 11543 | EXPECT_EQ(ERR_IO_PENDING, |
| 11544 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11545 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11546 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11547 | |
| 11548 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11549 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11550 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11551 | LoadTimingInfo load_timing_info1; |
| 11552 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 11553 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 11554 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11555 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11556 | // Now, start the HTTP request |
| 11557 | HttpRequestInfo request2; |
| 11558 | request2.method = "GET"; |
| 11559 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11560 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11561 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11562 | TestCompletionCallback callback2; |
| 11563 | EXPECT_EQ(ERR_IO_PENDING, |
| 11564 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11565 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11566 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11567 | |
| 11568 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11569 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11570 | |
| 11571 | LoadTimingInfo load_timing_info2; |
| 11572 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 11573 | // The established SPDY sessions is considered reused by the HTTP request. |
| 11574 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 11575 | // HTTP requests over a SPDY session should have a different connection |
| 11576 | // socket_log_id than requests over a tunnel. |
| 11577 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11578 | } |
| 11579 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11580 | TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11581 | session_deps_.force_spdy_always = true; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11582 | const std::string https_url = "https://www.google.com:8080/"; |
| 11583 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11584 | |
| 11585 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11586 | scoped_ptr<SpdyFrame> req1( |
| 11587 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11588 | // SPDY GET for the HTTP URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11589 | scoped_ptr<SpdyFrame> req2( |
| 11590 | spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11591 | |
| 11592 | MockWrite writes[] = { |
| 11593 | CreateMockWrite(*req1, 1), |
| 11594 | CreateMockWrite(*req2, 4), |
| 11595 | }; |
| 11596 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11597 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11598 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11599 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11600 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11601 | MockRead reads[] = { |
| 11602 | CreateMockRead(*resp1, 2), |
| 11603 | CreateMockRead(*body1, 3), |
| 11604 | CreateMockRead(*resp2, 5), |
| 11605 | CreateMockRead(*body2, 6), |
| 11606 | MockRead(ASYNC, ERR_IO_PENDING, 7) |
| 11607 | }; |
| 11608 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11609 | OrderedSocketData data(reads, arraysize(reads), |
| 11610 | writes, arraysize(writes)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11611 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11612 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11613 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11616 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11617 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11618 | |
| 11619 | // Start the first transaction to set up the SpdySession |
| 11620 | HttpRequestInfo request1; |
| 11621 | request1.method = "GET"; |
| 11622 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11623 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11624 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11625 | TestCompletionCallback callback1; |
| 11626 | EXPECT_EQ(ERR_IO_PENDING, |
| 11627 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11628 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11629 | |
| 11630 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11631 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11632 | |
| 11633 | // Now, start the HTTP request |
| 11634 | HttpRequestInfo request2; |
| 11635 | request2.method = "GET"; |
| 11636 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11637 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11638 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11639 | TestCompletionCallback callback2; |
| 11640 | EXPECT_EQ(ERR_IO_PENDING, |
| 11641 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11642 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11643 | |
| 11644 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11645 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11646 | } |
| 11647 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11648 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11649 | // that we do not pool other origins that resolve to the same IP when |
| 11650 | // the certificate does not match the new origin. |
| 11651 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11652 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11653 | const std::string url1 = "http://www.google.com/"; |
| 11654 | const std::string url2 = "https://mail.google.com/"; |
| 11655 | const std::string ip_addr = "1.2.3.4"; |
| 11656 | |
| 11657 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11658 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11659 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11660 | scoped_ptr<SpdyFrame> req1( |
| 11661 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11662 | |
| 11663 | MockWrite writes1[] = { |
| 11664 | CreateMockWrite(*req1, 0), |
| 11665 | }; |
| 11666 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11667 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11668 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11669 | MockRead reads1[] = { |
| 11670 | CreateMockRead(*resp1, 1), |
| 11671 | CreateMockRead(*body1, 2), |
| 11672 | MockRead(ASYNC, OK, 3) // EOF |
| 11673 | }; |
| 11674 | |
| 11675 | scoped_ptr<DeterministicSocketData> data1( |
| 11676 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11677 | writes1, arraysize(writes1))); |
| 11678 | IPAddressNumber ip; |
| 11679 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11680 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11681 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11682 | data1->set_connect_data(connect_data1); |
| 11683 | |
| 11684 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11685 | scoped_ptr<SpdyFrame> req2( |
| 11686 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11687 | |
| 11688 | MockWrite writes2[] = { |
| 11689 | CreateMockWrite(*req2, 0), |
| 11690 | }; |
| 11691 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11692 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11693 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11694 | MockRead reads2[] = { |
| 11695 | CreateMockRead(*resp2, 1), |
| 11696 | CreateMockRead(*body2, 2), |
| 11697 | MockRead(ASYNC, OK, 3) // EOF |
| 11698 | }; |
| 11699 | |
| 11700 | scoped_ptr<DeterministicSocketData> data2( |
| 11701 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11702 | writes2, arraysize(writes2))); |
| 11703 | MockConnect connect_data2(ASYNC, OK); |
| 11704 | data2->set_connect_data(connect_data2); |
| 11705 | |
| 11706 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11707 | // all others direct. |
| 11708 | ProxyConfig proxy_config; |
| 11709 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 11710 | CapturingProxyResolver* capturing_proxy_resolver = |
| 11711 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11712 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11713 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 11714 | NULL)); |
| 11715 | |
| 11716 | // Load a valid cert. Note, that this does not need to |
| 11717 | // be valid for proxy because the MockSSLClientSocket does |
| 11718 | // not actually verify it. But SpdySession will use this |
| 11719 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11720 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11721 | scoped_refptr<X509Certificate> server_cert( |
| 11722 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11723 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11724 | |
| 11725 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11726 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11727 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11728 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11729 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11730 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11731 | |
| 11732 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11733 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11734 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11735 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11736 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11737 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11738 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11739 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11740 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11741 | |
| 11742 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11743 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11744 | |
| 11745 | // Start the first transaction to set up the SpdySession |
| 11746 | HttpRequestInfo request1; |
| 11747 | request1.method = "GET"; |
| 11748 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11749 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11750 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11751 | TestCompletionCallback callback1; |
| 11752 | ASSERT_EQ(ERR_IO_PENDING, |
| 11753 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11754 | data1->RunFor(3); |
| 11755 | |
| 11756 | ASSERT_TRUE(callback1.have_result()); |
| 11757 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11758 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11759 | |
| 11760 | // Now, start the HTTP request |
| 11761 | HttpRequestInfo request2; |
| 11762 | request2.method = "GET"; |
| 11763 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11764 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11765 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11766 | TestCompletionCallback callback2; |
| 11767 | EXPECT_EQ(ERR_IO_PENDING, |
| 11768 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11769 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11770 | data2->RunFor(3); |
| 11771 | |
| 11772 | ASSERT_TRUE(callback2.have_result()); |
| 11773 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11774 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11775 | } |
| 11776 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11777 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 11778 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 11779 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 11780 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11781 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11782 | const std::string https_url = "https://www.google.com/"; |
| 11783 | |
| 11784 | MockRead reads1[] = { |
| 11785 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 11786 | }; |
| 11787 | |
| 11788 | scoped_ptr<DeterministicSocketData> data1( |
| 11789 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 11790 | data1->SetStop(1); |
| 11791 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11792 | scoped_ptr<SpdyFrame> req2( |
| 11793 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11794 | MockWrite writes2[] = { |
| 11795 | CreateMockWrite(*req2, 0), |
| 11796 | }; |
| 11797 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11798 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11799 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11800 | MockRead reads2[] = { |
| 11801 | CreateMockRead(*resp2, 1), |
| 11802 | CreateMockRead(*body2, 2), |
| 11803 | MockRead(ASYNC, OK, 3) // EOF |
| 11804 | }; |
| 11805 | |
| 11806 | scoped_ptr<DeterministicSocketData> data2( |
| 11807 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11808 | writes2, arraysize(writes2))); |
| 11809 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11810 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11811 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11812 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11813 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11814 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11815 | |
| 11816 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11817 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11818 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11819 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11820 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11821 | |
| 11822 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11823 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11824 | |
| 11825 | // Start the first transaction to set up the SpdySession and verify that |
| 11826 | // connection was closed. |
| 11827 | HttpRequestInfo request1; |
| 11828 | request1.method = "GET"; |
| 11829 | request1.url = GURL(https_url); |
| 11830 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11831 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11832 | TestCompletionCallback callback1; |
| 11833 | EXPECT_EQ(ERR_IO_PENDING, |
| 11834 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11835 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11836 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 11837 | |
| 11838 | // Now, start the second request and make sure it succeeds. |
| 11839 | HttpRequestInfo request2; |
| 11840 | request2.method = "GET"; |
| 11841 | request2.url = GURL(https_url); |
| 11842 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11843 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11844 | TestCompletionCallback callback2; |
| 11845 | EXPECT_EQ(ERR_IO_PENDING, |
| 11846 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11847 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 11848 | data2->RunFor(3); |
| 11849 | |
| 11850 | ASSERT_TRUE(callback2.have_result()); |
| 11851 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11852 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11853 | } |
| 11854 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11855 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11856 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11857 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 11858 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11859 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 11860 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 11861 | |
| 11862 | // Use two different hosts with different IPs so they don't get pooled. |
| 11863 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 11864 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 11865 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11866 | |
| 11867 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11868 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11869 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11870 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11872 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11873 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11874 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11875 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 11876 | MockWrite spdy1_writes[] = { |
| 11877 | CreateMockWrite(*host1_req, 1), |
| 11878 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11879 | scoped_ptr<SpdyFrame> host1_resp( |
| 11880 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11881 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11882 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11883 | MockRead spdy1_reads[] = { |
| 11884 | CreateMockRead(*host1_resp, 2), |
| 11885 | CreateMockRead(*host1_resp_body, 3), |
| 11886 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11887 | }; |
| 11888 | |
| 11889 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 11890 | new OrderedSocketData( |
| 11891 | spdy1_reads, arraysize(spdy1_reads), |
| 11892 | spdy1_writes, arraysize(spdy1_writes))); |
| 11893 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 11894 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11895 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11896 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 11897 | MockWrite spdy2_writes[] = { |
| 11898 | CreateMockWrite(*host2_req, 1), |
| 11899 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11900 | scoped_ptr<SpdyFrame> host2_resp( |
| 11901 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11902 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11903 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11904 | MockRead spdy2_reads[] = { |
| 11905 | CreateMockRead(*host2_resp, 2), |
| 11906 | CreateMockRead(*host2_resp_body, 3), |
| 11907 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 11908 | }; |
| 11909 | |
| 11910 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 11911 | new OrderedSocketData( |
| 11912 | spdy2_reads, arraysize(spdy2_reads), |
| 11913 | spdy2_writes, arraysize(spdy2_writes))); |
| 11914 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 11915 | |
| 11916 | MockWrite http_write[] = { |
| 11917 | MockWrite("GET / HTTP/1.1\r\n" |
| 11918 | "Host: www.a.com\r\n" |
| 11919 | "Connection: keep-alive\r\n\r\n"), |
| 11920 | }; |
| 11921 | |
| 11922 | MockRead http_read[] = { |
| 11923 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11924 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11925 | MockRead("Content-Length: 6\r\n\r\n"), |
| 11926 | MockRead("hello!"), |
| 11927 | }; |
| 11928 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 11929 | http_write, arraysize(http_write)); |
| 11930 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11931 | |
| 11932 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11933 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11934 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11935 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11936 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11937 | |
| 11938 | TestCompletionCallback callback; |
| 11939 | HttpRequestInfo request1; |
| 11940 | request1.method = "GET"; |
| 11941 | request1.url = GURL("https://www.a.com/"); |
| 11942 | request1.load_flags = 0; |
| 11943 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11944 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11945 | |
| 11946 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 11947 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11948 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11949 | |
| 11950 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11951 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11952 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11953 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11954 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11955 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11956 | |
| 11957 | std::string response_data; |
| 11958 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11959 | EXPECT_EQ("hello!", response_data); |
| 11960 | trans.reset(); |
| 11961 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11962 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11963 | |
| 11964 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11965 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11966 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11967 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11968 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11969 | HttpRequestInfo request2; |
| 11970 | request2.method = "GET"; |
| 11971 | request2.url = GURL("https://www.b.com/"); |
| 11972 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11973 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11974 | |
| 11975 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 11976 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11977 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11978 | |
| 11979 | response = trans->GetResponseInfo(); |
| 11980 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11981 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11982 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11983 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11984 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11985 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11986 | EXPECT_EQ("hello!", response_data); |
| 11987 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11988 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11989 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11990 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11991 | |
| 11992 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11993 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11994 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11995 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11996 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 11997 | HttpRequestInfo request3; |
| 11998 | request3.method = "GET"; |
| 11999 | request3.url = GURL("http://www.a.com/"); |
| 12000 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12001 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12002 | |
| 12003 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 12004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12005 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12006 | |
| 12007 | response = trans->GetResponseInfo(); |
| 12008 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12009 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12010 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12011 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12012 | EXPECT_FALSE(response->was_npn_negotiated); |
| 12013 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12014 | EXPECT_EQ("hello!", response_data); |
| 12015 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12016 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12017 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12018 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12019 | } |
| 12020 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12021 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 12022 | HttpRequestInfo request; |
| 12023 | request.method = "GET"; |
| 12024 | request.url = GURL("http://www.google.com/"); |
| 12025 | request.load_flags = 0; |
| 12026 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12027 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12028 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12029 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12030 | |
| 12031 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 12032 | StaticSocketDataProvider data; |
| 12033 | data.set_connect_data(mock_connect); |
| 12034 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12035 | |
| 12036 | TestCompletionCallback callback; |
| 12037 | |
| 12038 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12039 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12040 | |
| 12041 | rv = callback.WaitForResult(); |
| 12042 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12043 | |
| 12044 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12045 | |
| 12046 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12047 | HttpRequestHeaders request_headers; |
| 12048 | trans->GetFullRequestHeaders(&request_headers); |
| 12049 | } |
| 12050 | |
| 12051 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 12052 | HttpRequestInfo request; |
| 12053 | request.method = "GET"; |
| 12054 | request.url = GURL("http://www.google.com/"); |
| 12055 | request.load_flags = 0; |
| 12056 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12057 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12058 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12059 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12060 | |
| 12061 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12062 | StaticSocketDataProvider data; |
| 12063 | data.set_connect_data(mock_connect); |
| 12064 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12065 | |
| 12066 | TestCompletionCallback callback; |
| 12067 | |
| 12068 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12070 | |
| 12071 | rv = callback.WaitForResult(); |
| 12072 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12073 | |
| 12074 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12075 | |
| 12076 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12077 | HttpRequestHeaders request_headers; |
| 12078 | trans->GetFullRequestHeaders(&request_headers); |
| 12079 | } |
| 12080 | |
| 12081 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12082 | HttpRequestInfo request; |
| 12083 | request.method = "GET"; |
| 12084 | request.url = GURL("http://www.google.com/"); |
| 12085 | request.load_flags = 0; |
| 12086 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12087 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12088 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12089 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12090 | |
| 12091 | MockWrite data_writes[] = { |
| 12092 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12093 | }; |
| 12094 | MockRead data_reads[] = { |
| 12095 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12096 | }; |
| 12097 | |
| 12098 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12099 | data_writes, arraysize(data_writes)); |
| 12100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12101 | |
| 12102 | TestCompletionCallback callback; |
| 12103 | |
| 12104 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12106 | |
| 12107 | rv = callback.WaitForResult(); |
| 12108 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12109 | |
| 12110 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12111 | |
| 12112 | HttpRequestHeaders request_headers; |
| 12113 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12114 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12115 | } |
| 12116 | |
| 12117 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12118 | HttpRequestInfo request; |
| 12119 | request.method = "GET"; |
| 12120 | request.url = GURL("http://www.google.com/"); |
| 12121 | request.load_flags = 0; |
| 12122 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12123 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12124 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12126 | |
| 12127 | MockWrite data_writes[] = { |
| 12128 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12129 | }; |
| 12130 | MockRead data_reads[] = { |
| 12131 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12132 | }; |
| 12133 | |
| 12134 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12135 | data_writes, arraysize(data_writes)); |
| 12136 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12137 | |
| 12138 | TestCompletionCallback callback; |
| 12139 | |
| 12140 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12141 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12142 | |
| 12143 | rv = callback.WaitForResult(); |
| 12144 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12145 | |
| 12146 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12147 | |
| 12148 | HttpRequestHeaders request_headers; |
| 12149 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12150 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12151 | } |
| 12152 | |
| 12153 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12154 | HttpRequestInfo request; |
| 12155 | request.method = "GET"; |
| 12156 | request.url = GURL("http://www.google.com/"); |
| 12157 | request.load_flags = 0; |
| 12158 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12159 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12160 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12161 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12162 | |
| 12163 | MockWrite data_writes[] = { |
| 12164 | MockWrite("GET / HTTP/1.1\r\n" |
| 12165 | "Host: www.google.com\r\n" |
| 12166 | "Connection: keep-alive\r\n\r\n"), |
| 12167 | }; |
| 12168 | MockRead data_reads[] = { |
| 12169 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12170 | }; |
| 12171 | |
| 12172 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12173 | data_writes, arraysize(data_writes)); |
| 12174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12175 | |
| 12176 | TestCompletionCallback callback; |
| 12177 | |
| 12178 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12179 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12180 | |
| 12181 | rv = callback.WaitForResult(); |
| 12182 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12183 | |
| 12184 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12185 | |
| 12186 | HttpRequestHeaders request_headers; |
| 12187 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12188 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12189 | } |
| 12190 | |
| 12191 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 12192 | HttpRequestInfo request; |
| 12193 | request.method = "GET"; |
| 12194 | request.url = GURL("http://www.google.com/"); |
| 12195 | request.load_flags = 0; |
| 12196 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12197 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12198 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12200 | |
| 12201 | MockWrite data_writes[] = { |
| 12202 | MockWrite("GET / HTTP/1.1\r\n" |
| 12203 | "Host: www.google.com\r\n" |
| 12204 | "Connection: keep-alive\r\n\r\n"), |
| 12205 | }; |
| 12206 | MockRead data_reads[] = { |
| 12207 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 12208 | }; |
| 12209 | |
| 12210 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12211 | data_writes, arraysize(data_writes)); |
| 12212 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12213 | |
| 12214 | TestCompletionCallback callback; |
| 12215 | |
| 12216 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12217 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12218 | |
| 12219 | rv = callback.WaitForResult(); |
| 12220 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12221 | |
| 12222 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12223 | |
| 12224 | HttpRequestHeaders request_headers; |
| 12225 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12226 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12227 | } |
| 12228 | |
| 12229 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 12230 | HttpRequestInfo request; |
| 12231 | request.method = "GET"; |
| 12232 | request.url = GURL("http://www.google.com/"); |
| 12233 | request.load_flags = 0; |
| 12234 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 12235 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12236 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12237 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12239 | |
| 12240 | MockWrite data_writes[] = { |
| 12241 | MockWrite("GET / HTTP/1.1\r\n" |
| 12242 | "Host: www.google.com\r\n" |
| 12243 | "Connection: keep-alive\r\n" |
| 12244 | "X-Foo: bar\r\n\r\n"), |
| 12245 | }; |
| 12246 | MockRead data_reads[] = { |
| 12247 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12248 | "Content-Length: 5\r\n\r\n" |
| 12249 | "hello"), |
| 12250 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 12251 | }; |
| 12252 | |
| 12253 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12254 | data_writes, arraysize(data_writes)); |
| 12255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12256 | |
| 12257 | TestCompletionCallback callback; |
| 12258 | |
| 12259 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12261 | |
| 12262 | rv = callback.WaitForResult(); |
| 12263 | EXPECT_EQ(OK, rv); |
| 12264 | |
| 12265 | HttpRequestHeaders request_headers; |
| 12266 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12267 | std::string foo; |
| 12268 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 12269 | EXPECT_EQ("bar", foo); |
| 12270 | } |
| 12271 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12272 | namespace { |
| 12273 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12274 | // Fake HttpStream that simply records calls to SetPriority(). |
| 12275 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12276 | public base::SupportsWeakPtr<FakeStream> { |
| 12277 | public: |
| 12278 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12279 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12280 | |
| 12281 | RequestPriority priority() const { return priority_; } |
| 12282 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12283 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12284 | RequestPriority priority, |
| 12285 | const BoundNetLog& net_log, |
| 12286 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12287 | return ERR_IO_PENDING; |
| 12288 | } |
| 12289 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12290 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12291 | HttpResponseInfo* response, |
| 12292 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12293 | ADD_FAILURE(); |
| 12294 | return ERR_UNEXPECTED; |
| 12295 | } |
| 12296 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12297 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12298 | ADD_FAILURE(); |
| 12299 | return ERR_UNEXPECTED; |
| 12300 | } |
| 12301 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12302 | int ReadResponseBody(IOBuffer* buf, |
| 12303 | int buf_len, |
| 12304 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12305 | ADD_FAILURE(); |
| 12306 | return ERR_UNEXPECTED; |
| 12307 | } |
| 12308 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12309 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12310 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12311 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12312 | ADD_FAILURE(); |
| 12313 | return false; |
| 12314 | } |
| 12315 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12316 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12317 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12318 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12319 | ADD_FAILURE(); |
| 12320 | return false; |
| 12321 | } |
| 12322 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12323 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12324 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12325 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12326 | ADD_FAILURE(); |
| 12327 | return false; |
| 12328 | } |
| 12329 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12330 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 12331 | ADD_FAILURE(); |
| 12332 | return 0; |
| 12333 | } |
| 12334 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12335 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12336 | ADD_FAILURE(); |
| 12337 | return false; |
| 12338 | } |
| 12339 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12340 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 12341 | |
| 12342 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12343 | ADD_FAILURE(); |
| 12344 | } |
| 12345 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12346 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12347 | ADD_FAILURE(); |
| 12348 | return false; |
| 12349 | } |
| 12350 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12351 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12352 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12353 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12354 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12355 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 12356 | |
| 12357 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 12358 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12359 | private: |
| 12360 | RequestPriority priority_; |
| 12361 | |
| 12362 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 12363 | }; |
| 12364 | |
| 12365 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 12366 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12367 | class FakeStreamRequest : public HttpStreamRequest, |
| 12368 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 12369 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12370 | FakeStreamRequest(RequestPriority priority, |
| 12371 | HttpStreamRequest::Delegate* delegate) |
| 12372 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12373 | delegate_(delegate), |
| 12374 | websocket_stream_create_helper_(NULL) {} |
| 12375 | |
| 12376 | FakeStreamRequest(RequestPriority priority, |
| 12377 | HttpStreamRequest::Delegate* delegate, |
| 12378 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 12379 | : priority_(priority), |
| 12380 | delegate_(delegate), |
| 12381 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12382 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12383 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12384 | |
| 12385 | RequestPriority priority() const { return priority_; } |
| 12386 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12387 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 12388 | websocket_stream_create_helper() const { |
| 12389 | return websocket_stream_create_helper_; |
| 12390 | } |
| 12391 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12392 | // Create a new FakeStream and pass it to the request's |
| 12393 | // delegate. Returns a weak pointer to the FakeStream. |
| 12394 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 12395 | FakeStream* fake_stream = new FakeStream(priority_); |
| 12396 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 12397 | // immediately delete |fake_stream|. |
| 12398 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 12399 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 12400 | return weak_stream; |
| 12401 | } |
| 12402 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12403 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12404 | ADD_FAILURE(); |
| 12405 | return ERR_UNEXPECTED; |
| 12406 | } |
| 12407 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12408 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12409 | ADD_FAILURE(); |
| 12410 | return LoadState(); |
| 12411 | } |
| 12412 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12413 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12414 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12415 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12416 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12417 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12418 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12419 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12420 | |
| 12421 | private: |
| 12422 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12423 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12424 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12425 | |
| 12426 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 12427 | }; |
| 12428 | |
| 12429 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 12430 | class FakeStreamFactory : public HttpStreamFactory { |
| 12431 | public: |
| 12432 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12433 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12434 | |
| 12435 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 12436 | // RequestStream() (which may be NULL if it was destroyed already). |
| 12437 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 12438 | return last_stream_request_; |
| 12439 | } |
| 12440 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12441 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 12442 | RequestPriority priority, |
| 12443 | const SSLConfig& server_ssl_config, |
| 12444 | const SSLConfig& proxy_ssl_config, |
| 12445 | HttpStreamRequest::Delegate* delegate, |
| 12446 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12447 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12448 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12449 | return fake_request; |
| 12450 | } |
| 12451 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12452 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12453 | const HttpRequestInfo& info, |
| 12454 | RequestPriority priority, |
| 12455 | const SSLConfig& server_ssl_config, |
| 12456 | const SSLConfig& proxy_ssl_config, |
| 12457 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 12458 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12459 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12460 | FakeStreamRequest* fake_request = |
| 12461 | new FakeStreamRequest(priority, delegate, create_helper); |
| 12462 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12463 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12464 | } |
| 12465 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12466 | void PreconnectStreams(int num_streams, |
| 12467 | const HttpRequestInfo& info, |
| 12468 | RequestPriority priority, |
| 12469 | const SSLConfig& server_ssl_config, |
| 12470 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12471 | ADD_FAILURE(); |
| 12472 | } |
| 12473 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12474 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12475 | ADD_FAILURE(); |
| 12476 | return NULL; |
| 12477 | } |
| 12478 | |
| 12479 | private: |
| 12480 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 12481 | |
| 12482 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 12483 | }; |
| 12484 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12485 | // TODO(ricea): Maybe unify this with the one in |
| 12486 | // url_request_http_job_unittest.cc ? |
| 12487 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 12488 | public: |
| 12489 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 12490 | bool using_proxy) |
| 12491 | : state_(connection.release(), using_proxy) {} |
| 12492 | |
| 12493 | // Fake implementation of HttpStreamBase methods. |
| 12494 | // This ends up being quite "real" because this object has to really send data |
| 12495 | // on the mock socket. It might be easier to use the real implementation, but |
| 12496 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 12497 | // difficult. |
| 12498 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12499 | RequestPriority priority, |
| 12500 | const BoundNetLog& net_log, |
| 12501 | const CompletionCallback& callback) override { |
| 12502 | state_.Initialize(request_info, priority, net_log, callback); |
| 12503 | return OK; |
| 12504 | } |
| 12505 | |
| 12506 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12507 | HttpResponseInfo* response, |
| 12508 | const CompletionCallback& callback) override { |
| 12509 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 12510 | response, callback); |
| 12511 | } |
| 12512 | |
| 12513 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 12514 | return parser()->ReadResponseHeaders(callback); |
| 12515 | } |
| 12516 | |
| 12517 | int ReadResponseBody(IOBuffer* buf, |
| 12518 | int buf_len, |
| 12519 | const CompletionCallback& callback) override { |
| 12520 | NOTREACHED(); |
| 12521 | return ERR_IO_PENDING; |
| 12522 | } |
| 12523 | |
| 12524 | void Close(bool not_reusable) override { |
| 12525 | if (parser()) |
| 12526 | parser()->Close(true); |
| 12527 | } |
| 12528 | |
| 12529 | bool IsResponseBodyComplete() const override { |
| 12530 | NOTREACHED(); |
| 12531 | return false; |
| 12532 | } |
| 12533 | |
| 12534 | bool CanFindEndOfResponse() const override { |
| 12535 | return parser()->CanFindEndOfResponse(); |
| 12536 | } |
| 12537 | |
| 12538 | bool IsConnectionReused() const override { |
| 12539 | NOTREACHED(); |
| 12540 | return false; |
| 12541 | } |
| 12542 | void SetConnectionReused() override { NOTREACHED(); } |
| 12543 | |
| 12544 | bool IsConnectionReusable() const override { |
| 12545 | NOTREACHED(); |
| 12546 | return false; |
| 12547 | } |
| 12548 | |
| 12549 | int64 GetTotalReceivedBytes() const override { |
| 12550 | NOTREACHED(); |
| 12551 | return 0; |
| 12552 | } |
| 12553 | |
| 12554 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 12555 | NOTREACHED(); |
| 12556 | return false; |
| 12557 | } |
| 12558 | |
| 12559 | void GetSSLInfo(SSLInfo* ssl_info) override { NOTREACHED(); } |
| 12560 | |
| 12561 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 12562 | NOTREACHED(); |
| 12563 | } |
| 12564 | |
| 12565 | bool IsSpdyHttpStream() const override { |
| 12566 | NOTREACHED(); |
| 12567 | return false; |
| 12568 | } |
| 12569 | |
| 12570 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 12571 | |
| 12572 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 12573 | |
| 12574 | UploadProgress GetUploadProgress() const override { |
| 12575 | NOTREACHED(); |
| 12576 | return UploadProgress(); |
| 12577 | } |
| 12578 | |
| 12579 | HttpStream* RenewStreamForAuth() override { |
| 12580 | NOTREACHED(); |
| 12581 | return nullptr; |
| 12582 | } |
| 12583 | |
| 12584 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 12585 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 12586 | NOTREACHED(); |
| 12587 | return scoped_ptr<WebSocketStream>(); |
| 12588 | } |
| 12589 | |
| 12590 | private: |
| 12591 | HttpStreamParser* parser() const { return state_.parser(); } |
| 12592 | HttpBasicState state_; |
| 12593 | |
| 12594 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 12595 | }; |
| 12596 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12597 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 12598 | // worth doing. |
| 12599 | class FakeWebSocketStreamCreateHelper : |
| 12600 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 12601 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12602 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 12603 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12604 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12605 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 12606 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12607 | } |
| 12608 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12609 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12610 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12611 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12612 | NOTREACHED(); |
| 12613 | return NULL; |
| 12614 | }; |
| 12615 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12616 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12617 | |
| 12618 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 12619 | NOTREACHED(); |
| 12620 | return scoped_ptr<WebSocketStream>(); |
| 12621 | } |
| 12622 | }; |
| 12623 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12624 | } // namespace |
| 12625 | |
| 12626 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 12627 | // stream request on start. |
| 12628 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 12629 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12630 | HttpNetworkSessionPeer peer(session); |
| 12631 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12632 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12633 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12634 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12635 | |
| 12636 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 12637 | |
| 12638 | HttpRequestInfo request; |
| 12639 | TestCompletionCallback callback; |
| 12640 | EXPECT_EQ(ERR_IO_PENDING, |
| 12641 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12642 | |
| 12643 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12644 | fake_factory->last_stream_request(); |
| 12645 | ASSERT_TRUE(fake_request != NULL); |
| 12646 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12647 | } |
| 12648 | |
| 12649 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12650 | // updates to its stream request. |
| 12651 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 12652 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12653 | HttpNetworkSessionPeer peer(session); |
| 12654 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12655 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12656 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12657 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12658 | |
| 12659 | HttpRequestInfo request; |
| 12660 | TestCompletionCallback callback; |
| 12661 | EXPECT_EQ(ERR_IO_PENDING, |
| 12662 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12663 | |
| 12664 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12665 | fake_factory->last_stream_request(); |
| 12666 | ASSERT_TRUE(fake_request != NULL); |
| 12667 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12668 | |
| 12669 | trans.SetPriority(LOWEST); |
| 12670 | ASSERT_TRUE(fake_request != NULL); |
| 12671 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 12672 | } |
| 12673 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12674 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12675 | // updates to its stream. |
| 12676 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 12677 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12678 | HttpNetworkSessionPeer peer(session); |
| 12679 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12680 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12681 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12682 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12683 | |
| 12684 | HttpRequestInfo request; |
| 12685 | TestCompletionCallback callback; |
| 12686 | EXPECT_EQ(ERR_IO_PENDING, |
| 12687 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12688 | |
| 12689 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12690 | fake_factory->last_stream_request(); |
| 12691 | ASSERT_TRUE(fake_request != NULL); |
| 12692 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 12693 | ASSERT_TRUE(fake_stream != NULL); |
| 12694 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 12695 | |
| 12696 | trans.SetPriority(LOWEST); |
| 12697 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 12698 | } |
| 12699 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12700 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 12701 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 12702 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 12703 | // that the different schemes work. |
| 12704 | std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"}; |
| 12705 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 12706 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12707 | HttpNetworkSessionPeer peer(session); |
| 12708 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12709 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 12710 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12711 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 12712 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12713 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12714 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 12715 | &websocket_stream_create_helper); |
| 12716 | |
| 12717 | HttpRequestInfo request; |
| 12718 | TestCompletionCallback callback; |
| 12719 | request.method = "GET"; |
| 12720 | request.url = GURL(test_cases[i]); |
| 12721 | |
| 12722 | EXPECT_EQ(ERR_IO_PENDING, |
| 12723 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12724 | |
| 12725 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12726 | fake_factory->last_stream_request(); |
| 12727 | ASSERT_TRUE(fake_request != NULL); |
| 12728 | EXPECT_EQ(&websocket_stream_create_helper, |
| 12729 | fake_request->websocket_stream_create_helper()); |
| 12730 | } |
| 12731 | } |
| 12732 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12733 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 12734 | // if the transport socket pool is stalled on the global socket limit. |
| 12735 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 12736 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12737 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12738 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12739 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12740 | |
| 12741 | // Set up SSL request. |
| 12742 | |
| 12743 | HttpRequestInfo ssl_request; |
| 12744 | ssl_request.method = "GET"; |
| 12745 | ssl_request.url = GURL("https://www.google.com/"); |
| 12746 | |
| 12747 | MockWrite ssl_writes[] = { |
| 12748 | MockWrite("GET / HTTP/1.1\r\n" |
| 12749 | "Host: www.google.com\r\n" |
| 12750 | "Connection: keep-alive\r\n\r\n"), |
| 12751 | }; |
| 12752 | MockRead ssl_reads[] = { |
| 12753 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12754 | MockRead("Content-Length: 11\r\n\r\n"), |
| 12755 | MockRead("hello world"), |
| 12756 | MockRead(SYNCHRONOUS, OK), |
| 12757 | }; |
| 12758 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 12759 | ssl_writes, arraysize(ssl_writes)); |
| 12760 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12761 | |
| 12762 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12764 | |
| 12765 | // Set up HTTP request. |
| 12766 | |
| 12767 | HttpRequestInfo http_request; |
| 12768 | http_request.method = "GET"; |
| 12769 | http_request.url = GURL("http://www.google.com/"); |
| 12770 | |
| 12771 | MockWrite http_writes[] = { |
| 12772 | MockWrite("GET / HTTP/1.1\r\n" |
| 12773 | "Host: www.google.com\r\n" |
| 12774 | "Connection: keep-alive\r\n\r\n"), |
| 12775 | }; |
| 12776 | MockRead http_reads[] = { |
| 12777 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12778 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12779 | MockRead("falafel"), |
| 12780 | MockRead(SYNCHRONOUS, OK), |
| 12781 | }; |
| 12782 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12783 | http_writes, arraysize(http_writes)); |
| 12784 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12785 | |
| 12786 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12787 | |
| 12788 | // Start the SSL request. |
| 12789 | TestCompletionCallback ssl_callback; |
| 12790 | scoped_ptr<HttpTransaction> ssl_trans( |
| 12791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12792 | ASSERT_EQ(ERR_IO_PENDING, |
| 12793 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 12794 | BoundNetLog())); |
| 12795 | |
| 12796 | // Start the HTTP request. Pool should stall. |
| 12797 | TestCompletionCallback http_callback; |
| 12798 | scoped_ptr<HttpTransaction> http_trans( |
| 12799 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12800 | ASSERT_EQ(ERR_IO_PENDING, |
| 12801 | http_trans->Start(&http_request, http_callback.callback(), |
| 12802 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12803 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12804 | |
| 12805 | // Wait for response from SSL request. |
| 12806 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 12807 | std::string response_data; |
| 12808 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 12809 | EXPECT_EQ("hello world", response_data); |
| 12810 | |
| 12811 | // The SSL socket should automatically be closed, so the HTTP request can |
| 12812 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12813 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 12814 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12815 | |
| 12816 | // The HTTP request can now complete. |
| 12817 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12818 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12819 | EXPECT_EQ("falafel", response_data); |
| 12820 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12821 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12822 | } |
| 12823 | |
| 12824 | // Tests that when a SSL connection is established but there's no corresponding |
| 12825 | // request that needs it, the new socket is closed if the transport socket pool |
| 12826 | // is stalled on the global socket limit. |
| 12827 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 12828 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12829 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12830 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12831 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12832 | |
| 12833 | // Set up an ssl request. |
| 12834 | |
| 12835 | HttpRequestInfo ssl_request; |
| 12836 | ssl_request.method = "GET"; |
| 12837 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 12838 | |
| 12839 | // No data will be sent on the SSL socket. |
| 12840 | StaticSocketDataProvider ssl_data; |
| 12841 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12842 | |
| 12843 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12844 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12845 | |
| 12846 | // Set up HTTP request. |
| 12847 | |
| 12848 | HttpRequestInfo http_request; |
| 12849 | http_request.method = "GET"; |
| 12850 | http_request.url = GURL("http://www.google.com/"); |
| 12851 | |
| 12852 | MockWrite http_writes[] = { |
| 12853 | MockWrite("GET / HTTP/1.1\r\n" |
| 12854 | "Host: www.google.com\r\n" |
| 12855 | "Connection: keep-alive\r\n\r\n"), |
| 12856 | }; |
| 12857 | MockRead http_reads[] = { |
| 12858 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12859 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12860 | MockRead("falafel"), |
| 12861 | MockRead(SYNCHRONOUS, OK), |
| 12862 | }; |
| 12863 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12864 | http_writes, arraysize(http_writes)); |
| 12865 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12866 | |
| 12867 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12868 | |
| 12869 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 12870 | // cancelled when a normal transaction is cancelled. |
| 12871 | net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 12872 | net::SSLConfig ssl_config; |
| 12873 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 12874 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 12875 | ssl_config, ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12876 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12877 | |
| 12878 | // Start the HTTP request. Pool should stall. |
| 12879 | TestCompletionCallback http_callback; |
| 12880 | scoped_ptr<HttpTransaction> http_trans( |
| 12881 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12882 | ASSERT_EQ(ERR_IO_PENDING, |
| 12883 | http_trans->Start(&http_request, http_callback.callback(), |
| 12884 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12885 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12886 | |
| 12887 | // The SSL connection will automatically be closed once the connection is |
| 12888 | // established, to let the HTTP request start. |
| 12889 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 12890 | std::string response_data; |
| 12891 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 12892 | EXPECT_EQ("falafel", response_data); |
| 12893 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12894 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12895 | } |
| 12896 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12897 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 12898 | ScopedVector<UploadElementReader> element_readers; |
| 12899 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12900 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12901 | |
| 12902 | HttpRequestInfo request; |
| 12903 | request.method = "POST"; |
| 12904 | request.url = GURL("http://www.foo.com/"); |
| 12905 | request.upload_data_stream = &upload_data_stream; |
| 12906 | request.load_flags = 0; |
| 12907 | |
| 12908 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12909 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12910 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12911 | // Send headers successfully, but get an error while sending the body. |
| 12912 | MockWrite data_writes[] = { |
| 12913 | MockWrite("POST / HTTP/1.1\r\n" |
| 12914 | "Host: www.foo.com\r\n" |
| 12915 | "Connection: keep-alive\r\n" |
| 12916 | "Content-Length: 3\r\n\r\n"), |
| 12917 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12918 | }; |
| 12919 | |
| 12920 | MockRead data_reads[] = { |
| 12921 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 12922 | MockRead("hello world"), |
| 12923 | MockRead(SYNCHRONOUS, OK), |
| 12924 | }; |
| 12925 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12926 | arraysize(data_writes)); |
| 12927 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12928 | |
| 12929 | TestCompletionCallback callback; |
| 12930 | |
| 12931 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12932 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12933 | |
| 12934 | rv = callback.WaitForResult(); |
| 12935 | EXPECT_EQ(OK, rv); |
| 12936 | |
| 12937 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12938 | ASSERT_TRUE(response != NULL); |
| 12939 | |
| 12940 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12941 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 12942 | |
| 12943 | std::string response_data; |
| 12944 | rv = ReadTransaction(trans.get(), &response_data); |
| 12945 | EXPECT_EQ(OK, rv); |
| 12946 | EXPECT_EQ("hello world", response_data); |
| 12947 | } |
| 12948 | |
| 12949 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 12950 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 12951 | TEST_P(HttpNetworkTransactionTest, |
| 12952 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 12953 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12954 | MockWrite data_writes[] = { |
| 12955 | MockWrite("GET / HTTP/1.1\r\n" |
| 12956 | "Host: www.foo.com\r\n" |
| 12957 | "Connection: keep-alive\r\n\r\n"), |
| 12958 | MockWrite("POST / HTTP/1.1\r\n" |
| 12959 | "Host: www.foo.com\r\n" |
| 12960 | "Connection: keep-alive\r\n" |
| 12961 | "Content-Length: 3\r\n\r\n"), |
| 12962 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12963 | }; |
| 12964 | |
| 12965 | MockRead data_reads[] = { |
| 12966 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 12967 | "Content-Length: 14\r\n\r\n"), |
| 12968 | MockRead("first response"), |
| 12969 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 12970 | "Content-Length: 15\r\n\r\n"), |
| 12971 | MockRead("second response"), |
| 12972 | MockRead(SYNCHRONOUS, OK), |
| 12973 | }; |
| 12974 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 12975 | arraysize(data_writes)); |
| 12976 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12977 | |
| 12978 | TestCompletionCallback callback; |
| 12979 | HttpRequestInfo request1; |
| 12980 | request1.method = "GET"; |
| 12981 | request1.url = GURL("http://www.foo.com/"); |
| 12982 | request1.load_flags = 0; |
| 12983 | |
| 12984 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 12986 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 12987 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12988 | |
| 12989 | rv = callback.WaitForResult(); |
| 12990 | EXPECT_EQ(OK, rv); |
| 12991 | |
| 12992 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12993 | ASSERT_TRUE(response1 != NULL); |
| 12994 | |
| 12995 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 12996 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 12997 | |
| 12998 | std::string response_data1; |
| 12999 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 13000 | EXPECT_EQ(OK, rv); |
| 13001 | EXPECT_EQ("first response", response_data1); |
| 13002 | // Delete the transaction to release the socket back into the socket pool. |
| 13003 | trans1.reset(); |
| 13004 | |
| 13005 | ScopedVector<UploadElementReader> element_readers; |
| 13006 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13007 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13008 | |
| 13009 | HttpRequestInfo request2; |
| 13010 | request2.method = "POST"; |
| 13011 | request2.url = GURL("http://www.foo.com/"); |
| 13012 | request2.upload_data_stream = &upload_data_stream; |
| 13013 | request2.load_flags = 0; |
| 13014 | |
| 13015 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13016 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13017 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 13018 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13019 | |
| 13020 | rv = callback.WaitForResult(); |
| 13021 | EXPECT_EQ(OK, rv); |
| 13022 | |
| 13023 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 13024 | ASSERT_TRUE(response2 != NULL); |
| 13025 | |
| 13026 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 13027 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 13028 | |
| 13029 | std::string response_data2; |
| 13030 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 13031 | EXPECT_EQ(OK, rv); |
| 13032 | EXPECT_EQ("second response", response_data2); |
| 13033 | } |
| 13034 | |
| 13035 | TEST_P(HttpNetworkTransactionTest, |
| 13036 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 13037 | ScopedVector<UploadElementReader> element_readers; |
| 13038 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13039 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13040 | |
| 13041 | HttpRequestInfo request; |
| 13042 | request.method = "POST"; |
| 13043 | request.url = GURL("http://www.foo.com/"); |
| 13044 | request.upload_data_stream = &upload_data_stream; |
| 13045 | request.load_flags = 0; |
| 13046 | |
| 13047 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13048 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13049 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13050 | // Send headers successfully, but get an error while sending the body. |
| 13051 | MockWrite data_writes[] = { |
| 13052 | MockWrite("POST / HTTP/1.1\r\n" |
| 13053 | "Host: www.foo.com\r\n" |
| 13054 | "Connection: keep-alive\r\n" |
| 13055 | "Content-Length: 3\r\n\r\n" |
| 13056 | "fo"), |
| 13057 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13058 | }; |
| 13059 | |
| 13060 | MockRead data_reads[] = { |
| 13061 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13062 | MockRead("hello world"), |
| 13063 | MockRead(SYNCHRONOUS, OK), |
| 13064 | }; |
| 13065 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13066 | arraysize(data_writes)); |
| 13067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13068 | |
| 13069 | TestCompletionCallback callback; |
| 13070 | |
| 13071 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13072 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13073 | |
| 13074 | rv = callback.WaitForResult(); |
| 13075 | EXPECT_EQ(OK, rv); |
| 13076 | |
| 13077 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13078 | ASSERT_TRUE(response != NULL); |
| 13079 | |
| 13080 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13081 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13082 | |
| 13083 | std::string response_data; |
| 13084 | rv = ReadTransaction(trans.get(), &response_data); |
| 13085 | EXPECT_EQ(OK, rv); |
| 13086 | EXPECT_EQ("hello world", response_data); |
| 13087 | } |
| 13088 | |
| 13089 | // This tests the more common case than the previous test, where headers and |
| 13090 | // body are not merged into a single request. |
| 13091 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 13092 | ScopedVector<UploadElementReader> element_readers; |
| 13093 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13094 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13095 | |
| 13096 | HttpRequestInfo request; |
| 13097 | request.method = "POST"; |
| 13098 | request.url = GURL("http://www.foo.com/"); |
| 13099 | request.upload_data_stream = &upload_data_stream; |
| 13100 | request.load_flags = 0; |
| 13101 | |
| 13102 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13103 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13104 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13105 | // Send headers successfully, but get an error while sending the body. |
| 13106 | MockWrite data_writes[] = { |
| 13107 | MockWrite("POST / HTTP/1.1\r\n" |
| 13108 | "Host: www.foo.com\r\n" |
| 13109 | "Connection: keep-alive\r\n" |
| 13110 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 13111 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13112 | }; |
| 13113 | |
| 13114 | MockRead data_reads[] = { |
| 13115 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13116 | MockRead("hello world"), |
| 13117 | MockRead(SYNCHRONOUS, OK), |
| 13118 | }; |
| 13119 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13120 | arraysize(data_writes)); |
| 13121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13122 | |
| 13123 | TestCompletionCallback callback; |
| 13124 | |
| 13125 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13126 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13127 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 13128 | // they can't be merged with the body in a single send. Not currently |
| 13129 | // necessary since a chunked body is never merged with headers, but this makes |
| 13130 | // the test more future proof. |
| 13131 | base::RunLoop().RunUntilIdle(); |
| 13132 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13133 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13134 | |
| 13135 | rv = callback.WaitForResult(); |
| 13136 | EXPECT_EQ(OK, rv); |
| 13137 | |
| 13138 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13139 | ASSERT_TRUE(response != NULL); |
| 13140 | |
| 13141 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13142 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13143 | |
| 13144 | std::string response_data; |
| 13145 | rv = ReadTransaction(trans.get(), &response_data); |
| 13146 | EXPECT_EQ(OK, rv); |
| 13147 | EXPECT_EQ("hello world", response_data); |
| 13148 | } |
| 13149 | |
| 13150 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 13151 | ScopedVector<UploadElementReader> element_readers; |
| 13152 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13153 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13154 | |
| 13155 | HttpRequestInfo request; |
| 13156 | request.method = "POST"; |
| 13157 | request.url = GURL("http://www.foo.com/"); |
| 13158 | request.upload_data_stream = &upload_data_stream; |
| 13159 | request.load_flags = 0; |
| 13160 | |
| 13161 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13162 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13163 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13164 | |
| 13165 | MockWrite data_writes[] = { |
| 13166 | MockWrite("POST / HTTP/1.1\r\n" |
| 13167 | "Host: www.foo.com\r\n" |
| 13168 | "Connection: keep-alive\r\n" |
| 13169 | "Content-Length: 3\r\n\r\n"), |
| 13170 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13171 | }; |
| 13172 | |
| 13173 | MockRead data_reads[] = { |
| 13174 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13175 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13176 | MockRead("hello world"), |
| 13177 | MockRead(SYNCHRONOUS, OK), |
| 13178 | }; |
| 13179 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13180 | arraysize(data_writes)); |
| 13181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13182 | |
| 13183 | TestCompletionCallback callback; |
| 13184 | |
| 13185 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13186 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13187 | |
| 13188 | rv = callback.WaitForResult(); |
| 13189 | EXPECT_EQ(OK, rv); |
| 13190 | |
| 13191 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13192 | ASSERT_TRUE(response != NULL); |
| 13193 | |
| 13194 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13195 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13196 | |
| 13197 | std::string response_data; |
| 13198 | rv = ReadTransaction(trans.get(), &response_data); |
| 13199 | EXPECT_EQ(OK, rv); |
| 13200 | EXPECT_EQ("hello world", response_data); |
| 13201 | } |
| 13202 | |
| 13203 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 13204 | ScopedVector<UploadElementReader> element_readers; |
| 13205 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13206 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13207 | |
| 13208 | HttpRequestInfo request; |
| 13209 | request.method = "POST"; |
| 13210 | request.url = GURL("http://www.foo.com/"); |
| 13211 | request.upload_data_stream = &upload_data_stream; |
| 13212 | request.load_flags = 0; |
| 13213 | |
| 13214 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13215 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13216 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13217 | // Send headers successfully, but get an error while sending the body. |
| 13218 | MockWrite data_writes[] = { |
| 13219 | MockWrite("POST / HTTP/1.1\r\n" |
| 13220 | "Host: www.foo.com\r\n" |
| 13221 | "Connection: keep-alive\r\n" |
| 13222 | "Content-Length: 3\r\n\r\n"), |
| 13223 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13224 | }; |
| 13225 | |
| 13226 | MockRead data_reads[] = { |
| 13227 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 13228 | MockRead("hello world"), |
| 13229 | MockRead(SYNCHRONOUS, OK), |
| 13230 | }; |
| 13231 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13232 | arraysize(data_writes)); |
| 13233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13234 | |
| 13235 | TestCompletionCallback callback; |
| 13236 | |
| 13237 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13238 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13239 | |
| 13240 | rv = callback.WaitForResult(); |
| 13241 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13242 | |
| 13243 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13244 | EXPECT_TRUE(response == NULL); |
| 13245 | } |
| 13246 | |
| 13247 | TEST_P(HttpNetworkTransactionTest, |
| 13248 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 13249 | ScopedVector<UploadElementReader> element_readers; |
| 13250 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13251 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13252 | |
| 13253 | HttpRequestInfo request; |
| 13254 | request.method = "POST"; |
| 13255 | request.url = GURL("http://www.foo.com/"); |
| 13256 | request.upload_data_stream = &upload_data_stream; |
| 13257 | request.load_flags = 0; |
| 13258 | |
| 13259 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13260 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13262 | // Send headers successfully, but get an error while sending the body. |
| 13263 | MockWrite data_writes[] = { |
| 13264 | MockWrite("POST / HTTP/1.1\r\n" |
| 13265 | "Host: www.foo.com\r\n" |
| 13266 | "Connection: keep-alive\r\n" |
| 13267 | "Content-Length: 3\r\n\r\n"), |
| 13268 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13269 | }; |
| 13270 | |
| 13271 | MockRead data_reads[] = { |
| 13272 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13273 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 13274 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 13275 | MockRead("Content-Length: 0\r\n\r\n"), |
| 13276 | MockRead(SYNCHRONOUS, OK), |
| 13277 | }; |
| 13278 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13279 | arraysize(data_writes)); |
| 13280 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13281 | |
| 13282 | TestCompletionCallback callback; |
| 13283 | |
| 13284 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13285 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13286 | |
| 13287 | rv = callback.WaitForResult(); |
| 13288 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13289 | |
| 13290 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13291 | EXPECT_TRUE(response == NULL); |
| 13292 | } |
| 13293 | |
| 13294 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 13295 | ScopedVector<UploadElementReader> element_readers; |
| 13296 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13297 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13298 | |
| 13299 | HttpRequestInfo request; |
| 13300 | request.method = "POST"; |
| 13301 | request.url = GURL("http://www.foo.com/"); |
| 13302 | request.upload_data_stream = &upload_data_stream; |
| 13303 | request.load_flags = 0; |
| 13304 | |
| 13305 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13306 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13308 | // Send headers successfully, but get an error while sending the body. |
| 13309 | MockWrite data_writes[] = { |
| 13310 | MockWrite("POST / HTTP/1.1\r\n" |
| 13311 | "Host: www.foo.com\r\n" |
| 13312 | "Connection: keep-alive\r\n" |
| 13313 | "Content-Length: 3\r\n\r\n"), |
| 13314 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13315 | }; |
| 13316 | |
| 13317 | MockRead data_reads[] = { |
| 13318 | MockRead("HTTP 0.9 rocks!"), |
| 13319 | MockRead(SYNCHRONOUS, OK), |
| 13320 | }; |
| 13321 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13322 | arraysize(data_writes)); |
| 13323 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13324 | |
| 13325 | TestCompletionCallback callback; |
| 13326 | |
| 13327 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13329 | |
| 13330 | rv = callback.WaitForResult(); |
| 13331 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13332 | |
| 13333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13334 | EXPECT_TRUE(response == NULL); |
| 13335 | } |
| 13336 | |
| 13337 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 13338 | ScopedVector<UploadElementReader> element_readers; |
| 13339 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13340 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13341 | |
| 13342 | HttpRequestInfo request; |
| 13343 | request.method = "POST"; |
| 13344 | request.url = GURL("http://www.foo.com/"); |
| 13345 | request.upload_data_stream = &upload_data_stream; |
| 13346 | request.load_flags = 0; |
| 13347 | |
| 13348 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13349 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13351 | // Send headers successfully, but get an error while sending the body. |
| 13352 | MockWrite data_writes[] = { |
| 13353 | MockWrite("POST / HTTP/1.1\r\n" |
| 13354 | "Host: www.foo.com\r\n" |
| 13355 | "Connection: keep-alive\r\n" |
| 13356 | "Content-Length: 3\r\n\r\n"), |
| 13357 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13358 | }; |
| 13359 | |
| 13360 | MockRead data_reads[] = { |
| 13361 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 13362 | MockRead(SYNCHRONOUS, OK), |
| 13363 | }; |
| 13364 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13365 | arraysize(data_writes)); |
| 13366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13367 | |
| 13368 | TestCompletionCallback callback; |
| 13369 | |
| 13370 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13372 | |
| 13373 | rv = callback.WaitForResult(); |
| 13374 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13375 | |
| 13376 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13377 | EXPECT_TRUE(response == NULL); |
| 13378 | } |
| 13379 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13380 | // Verify that proxy headers are not sent to the destination server when |
| 13381 | // establishing a tunnel for a secure WebSocket connection. |
| 13382 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 13383 | HttpRequestInfo request; |
| 13384 | request.method = "GET"; |
| 13385 | request.url = GURL("wss://www.google.com/"); |
| 13386 | AddWebSocketHeaders(&request.extra_headers); |
| 13387 | |
| 13388 | // Configure against proxy server "myproxy:70". |
| 13389 | session_deps_.proxy_service.reset( |
| 13390 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 13391 | |
| 13392 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13393 | |
| 13394 | // Since a proxy is configured, try to establish a tunnel. |
| 13395 | MockWrite data_writes[] = { |
| 13396 | MockWrite( |
| 13397 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 13398 | "Host: www.google.com\r\n" |
| 13399 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13400 | |
| 13401 | // After calling trans->RestartWithAuth(), this is the request we should |
| 13402 | // be issuing -- the final header line contains the credentials. |
| 13403 | MockWrite( |
| 13404 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 13405 | "Host: www.google.com\r\n" |
| 13406 | "Proxy-Connection: keep-alive\r\n" |
| 13407 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 13408 | |
| 13409 | MockWrite( |
| 13410 | "GET / HTTP/1.1\r\n" |
| 13411 | "Host: www.google.com\r\n" |
| 13412 | "Connection: Upgrade\r\n" |
| 13413 | "Upgrade: websocket\r\n" |
| 13414 | "Origin: http://www.google.com\r\n" |
| 13415 | "Sec-WebSocket-Version: 13\r\n" |
| 13416 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 13417 | }; |
| 13418 | |
| 13419 | // The proxy responds to the connect with a 407, using a persistent |
| 13420 | // connection. |
| 13421 | MockRead data_reads[] = { |
| 13422 | // No credentials. |
| 13423 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 13424 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 13425 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 13426 | |
| 13427 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13428 | |
| 13429 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 13430 | MockRead("Upgrade: websocket\r\n"), |
| 13431 | MockRead("Connection: Upgrade\r\n"), |
| 13432 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 13433 | }; |
| 13434 | |
| 13435 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13436 | arraysize(data_writes)); |
| 13437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13438 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13440 | |
| 13441 | scoped_ptr<HttpTransaction> trans( |
| 13442 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13443 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 13444 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 13445 | &websocket_stream_create_helper); |
| 13446 | |
| 13447 | { |
| 13448 | TestCompletionCallback callback; |
| 13449 | |
| 13450 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13451 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13452 | |
| 13453 | rv = callback.WaitForResult(); |
| 13454 | EXPECT_EQ(OK, rv); |
| 13455 | } |
| 13456 | |
| 13457 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13458 | ASSERT_TRUE(response); |
| 13459 | ASSERT_TRUE(response->headers.get()); |
| 13460 | EXPECT_EQ(407, response->headers->response_code()); |
| 13461 | |
| 13462 | { |
| 13463 | TestCompletionCallback callback; |
| 13464 | |
| 13465 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 13466 | callback.callback()); |
| 13467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13468 | |
| 13469 | rv = callback.WaitForResult(); |
| 13470 | EXPECT_EQ(OK, rv); |
| 13471 | } |
| 13472 | |
| 13473 | response = trans->GetResponseInfo(); |
| 13474 | ASSERT_TRUE(response); |
| 13475 | ASSERT_TRUE(response->headers.get()); |
| 13476 | |
| 13477 | EXPECT_EQ(101, response->headers->response_code()); |
| 13478 | |
| 13479 | trans.reset(); |
| 13480 | session->CloseAllConnections(); |
| 13481 | } |
| 13482 | |
| 13483 | // Verify that proxy headers are not sent to the destination server when |
| 13484 | // establishing a tunnel for an insecure WebSocket connection. |
| 13485 | // This requires the authentication info to be injected into the auth cache |
| 13486 | // due to crbug.com/395064 |
| 13487 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 13488 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 13489 | HttpRequestInfo request; |
| 13490 | request.method = "GET"; |
| 13491 | request.url = GURL("ws://www.google.com/"); |
| 13492 | AddWebSocketHeaders(&request.extra_headers); |
| 13493 | |
| 13494 | // Configure against proxy server "myproxy:70". |
| 13495 | session_deps_.proxy_service.reset( |
| 13496 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 13497 | |
| 13498 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13499 | |
| 13500 | MockWrite data_writes[] = { |
| 13501 | // Try to establish a tunnel for the WebSocket connection, with |
| 13502 | // credentials. Because WebSockets have a separate set of socket pools, |
| 13503 | // they cannot and will not use the same TCP/IP connection as the |
| 13504 | // preflight HTTP request. |
| 13505 | MockWrite( |
| 13506 | "CONNECT www.google.com:80 HTTP/1.1\r\n" |
| 13507 | "Host: www.google.com\r\n" |
| 13508 | "Proxy-Connection: keep-alive\r\n" |
| 13509 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 13510 | |
| 13511 | MockWrite( |
| 13512 | "GET / HTTP/1.1\r\n" |
| 13513 | "Host: www.google.com\r\n" |
| 13514 | "Connection: Upgrade\r\n" |
| 13515 | "Upgrade: websocket\r\n" |
| 13516 | "Origin: http://www.google.com\r\n" |
| 13517 | "Sec-WebSocket-Version: 13\r\n" |
| 13518 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 13519 | }; |
| 13520 | |
| 13521 | MockRead data_reads[] = { |
| 13522 | // HTTP CONNECT with credentials. |
| 13523 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13524 | |
| 13525 | // WebSocket connection established inside tunnel. |
| 13526 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 13527 | MockRead("Upgrade: websocket\r\n"), |
| 13528 | MockRead("Connection: Upgrade\r\n"), |
| 13529 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 13530 | }; |
| 13531 | |
| 13532 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13533 | arraysize(data_writes)); |
| 13534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13535 | |
| 13536 | session->http_auth_cache()->Add( |
| 13537 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 13538 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 13539 | |
| 13540 | scoped_ptr<HttpTransaction> trans( |
| 13541 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13542 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 13543 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 13544 | &websocket_stream_create_helper); |
| 13545 | |
| 13546 | TestCompletionCallback callback; |
| 13547 | |
| 13548 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13549 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13550 | |
| 13551 | rv = callback.WaitForResult(); |
| 13552 | EXPECT_EQ(OK, rv); |
| 13553 | |
| 13554 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13555 | ASSERT_TRUE(response); |
| 13556 | ASSERT_TRUE(response->headers.get()); |
| 13557 | |
| 13558 | EXPECT_EQ(101, response->headers->response_code()); |
| 13559 | |
| 13560 | trans.reset(); |
| 13561 | session->CloseAllConnections(); |
| 13562 | } |
| 13563 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 13564 | } // namespace net |