[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. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame^] | 2375 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 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 | |
| 2382 | // Configure against proxy server "myproxy:70". |
| 2383 | session_deps_.proxy_service.reset( |
| 2384 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 2385 | CapturingBoundNetLog log; |
| 2386 | session_deps_.net_log = log.bound().net_log(); |
| 2387 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2388 | |
| 2389 | // Since we have proxy, should try to establish tunnel. |
| 2390 | MockWrite data_writes1[] = { |
| 2391 | MockWrite( |
| 2392 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2393 | "Host: www.google.com\r\n" |
| 2394 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2395 | |
| 2396 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2397 | // be issuing -- the final header line contains the credentials. |
| 2398 | MockWrite( |
| 2399 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2400 | "Host: www.google.com\r\n" |
| 2401 | "Proxy-Connection: keep-alive\r\n" |
| 2402 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2403 | |
| 2404 | MockWrite( |
| 2405 | "GET / HTTP/1.1\r\n" |
| 2406 | "Host: www.google.com\r\n" |
| 2407 | "Connection: keep-alive\r\n\r\n"), |
| 2408 | }; |
| 2409 | |
| 2410 | // The proxy responds to the connect with a 407, using a persistent |
| 2411 | // connection. |
| 2412 | MockRead data_reads1[] = { |
| 2413 | // No credentials. |
| 2414 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2415 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 2416 | |
| 2417 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2418 | |
| 2419 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2421 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2422 | MockRead(SYNCHRONOUS, "hello"), |
| 2423 | }; |
| 2424 | |
| 2425 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2426 | data_writes1, arraysize(data_writes1)); |
| 2427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2428 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2430 | |
| 2431 | TestCompletionCallback callback1; |
| 2432 | |
| 2433 | scoped_ptr<HttpTransaction> trans( |
| 2434 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2435 | |
| 2436 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2437 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2438 | |
| 2439 | rv = callback1.WaitForResult(); |
| 2440 | EXPECT_EQ(OK, rv); |
| 2441 | net::CapturingNetLog::CapturedEntryList entries; |
| 2442 | log.GetEntries(&entries); |
| 2443 | size_t pos = ExpectLogContainsSomewhere( |
| 2444 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2445 | NetLog::PHASE_NONE); |
| 2446 | ExpectLogContainsSomewhere( |
| 2447 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2448 | NetLog::PHASE_NONE); |
| 2449 | |
| 2450 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2451 | ASSERT_TRUE(response != NULL); |
| 2452 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2453 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2454 | EXPECT_EQ(407, response->headers->response_code()); |
| 2455 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2456 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2457 | |
| 2458 | LoadTimingInfo load_timing_info; |
| 2459 | // CONNECT requests and responses are handled at the connect job level, so |
| 2460 | // the transaction does not yet have a connection. |
| 2461 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2462 | |
| 2463 | TestCompletionCallback callback2; |
| 2464 | |
| 2465 | rv = |
| 2466 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2468 | |
| 2469 | rv = callback2.WaitForResult(); |
| 2470 | EXPECT_EQ(OK, rv); |
| 2471 | |
| 2472 | response = trans->GetResponseInfo(); |
| 2473 | ASSERT_TRUE(response != NULL); |
| 2474 | |
| 2475 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2476 | EXPECT_EQ(200, response->headers->response_code()); |
| 2477 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2478 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2479 | |
| 2480 | // The password prompt info should not be set. |
| 2481 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2482 | |
| 2483 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2484 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2485 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2486 | |
| 2487 | trans.reset(); |
| 2488 | session->CloseAllConnections(); |
| 2489 | } |
| 2490 | |
| 2491 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2492 | // that requires a restart when setting up an SSL tunnel. |
| 2493 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2494 | HttpRequestInfo request; |
| 2495 | request.method = "GET"; |
| 2496 | request.url = GURL("https://www.google.com/"); |
| 2497 | // when the no authentication data flag is set. |
| 2498 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2499 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2500 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2501 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2502 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2503 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2504 | session_deps_.net_log = log.bound().net_log(); |
| 2505 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2506 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2507 | // Since we have proxy, should try to establish tunnel. |
| 2508 | MockWrite data_writes1[] = { |
| 2509 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2510 | "Host: www.google.com\r\n" |
| 2511 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2512 | |
| 2513 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2514 | // be issuing -- the final header line contains the credentials. |
| 2515 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2516 | "Host: www.google.com\r\n" |
| 2517 | "Proxy-Connection: keep-alive\r\n" |
| 2518 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2519 | |
| 2520 | MockWrite("GET / HTTP/1.1\r\n" |
| 2521 | "Host: www.google.com\r\n" |
| 2522 | "Connection: keep-alive\r\n\r\n"), |
| 2523 | }; |
| 2524 | |
| 2525 | // The proxy responds to the connect with a 407, using a persistent |
| 2526 | // connection. |
| 2527 | MockRead data_reads1[] = { |
| 2528 | // No credentials. |
| 2529 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2530 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2531 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2532 | |
| 2533 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2534 | |
| 2535 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2536 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2537 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2538 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2539 | }; |
| 2540 | |
| 2541 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2542 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2543 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2544 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2547 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2548 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2549 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2550 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2552 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2553 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2554 | |
| 2555 | rv = callback1.WaitForResult(); |
| 2556 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2557 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2558 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2559 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2560 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2561 | NetLog::PHASE_NONE); |
| 2562 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2563 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2564 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2565 | NetLog::PHASE_NONE); |
| 2566 | |
| 2567 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2568 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame^] | 2569 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2570 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2571 | EXPECT_EQ(407, response->headers->response_code()); |
| 2572 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2573 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2574 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2575 | LoadTimingInfo load_timing_info; |
| 2576 | // CONNECT requests and responses are handled at the connect job level, so |
| 2577 | // the transaction does not yet have a connection. |
| 2578 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2580 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2582 | rv = trans->RestartWithAuth( |
| 2583 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2584 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2585 | |
| 2586 | rv = callback2.WaitForResult(); |
| 2587 | EXPECT_EQ(OK, rv); |
| 2588 | |
| 2589 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2590 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2591 | |
| 2592 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2593 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2594 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2595 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2596 | |
| 2597 | // The password prompt info should not be set. |
| 2598 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2599 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2600 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2601 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2602 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2603 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2604 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2605 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2606 | } |
| 2607 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2608 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame^] | 2609 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2610 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2611 | HttpRequestInfo request; |
| 2612 | request.method = "GET"; |
| 2613 | request.url = GURL("https://www.google.com/"); |
| 2614 | // Ensure that proxy authentication is attempted even |
| 2615 | // when the no authentication data flag is set. |
| 2616 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2617 | |
| 2618 | // Configure against proxy server "myproxy:70". |
| 2619 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2620 | CapturingBoundNetLog log; |
| 2621 | session_deps_.net_log = log.bound().net_log(); |
| 2622 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2623 | |
| 2624 | scoped_ptr<HttpTransaction> trans( |
| 2625 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2626 | |
| 2627 | // Since we have proxy, should try to establish tunnel. |
| 2628 | MockWrite data_writes1[] = { |
| 2629 | MockWrite( |
| 2630 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2631 | "Host: www.google.com\r\n" |
| 2632 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2633 | |
| 2634 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2635 | // be issuing -- the final header line contains the credentials. |
| 2636 | MockWrite( |
| 2637 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2638 | "Host: www.google.com\r\n" |
| 2639 | "Proxy-Connection: keep-alive\r\n" |
| 2640 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2641 | }; |
| 2642 | |
| 2643 | // The proxy responds to the connect with a 407, using a persistent |
| 2644 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2645 | MockRead data_reads1[] = { |
| 2646 | // No credentials. |
| 2647 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2648 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2649 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2650 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2651 | MockRead("0123456789"), |
| 2652 | |
| 2653 | // Wrong credentials (wrong password). |
| 2654 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2655 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2656 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2657 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2658 | // No response body because the test stops reading here. |
| 2659 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2660 | }; |
| 2661 | |
| 2662 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2663 | data_writes1, arraysize(data_writes1)); |
| 2664 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2665 | |
| 2666 | TestCompletionCallback callback1; |
| 2667 | |
| 2668 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2669 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2670 | |
| 2671 | rv = callback1.WaitForResult(); |
| 2672 | EXPECT_EQ(OK, rv); |
| 2673 | net::CapturingNetLog::CapturedEntryList entries; |
| 2674 | log.GetEntries(&entries); |
| 2675 | size_t pos = ExpectLogContainsSomewhere( |
| 2676 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2677 | NetLog::PHASE_NONE); |
| 2678 | ExpectLogContainsSomewhere( |
| 2679 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2680 | NetLog::PHASE_NONE); |
| 2681 | |
| 2682 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2683 | ASSERT_TRUE(response); |
| 2684 | ASSERT_TRUE(response->headers); |
| 2685 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2686 | EXPECT_EQ(407, response->headers->response_code()); |
| 2687 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2688 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2689 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2690 | |
| 2691 | TestCompletionCallback callback2; |
| 2692 | |
| 2693 | // Wrong password (should be "bar"). |
| 2694 | rv = |
| 2695 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2696 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2697 | |
| 2698 | rv = callback2.WaitForResult(); |
| 2699 | EXPECT_EQ(OK, rv); |
| 2700 | |
| 2701 | response = trans->GetResponseInfo(); |
| 2702 | ASSERT_TRUE(response); |
| 2703 | ASSERT_TRUE(response->headers); |
| 2704 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2705 | EXPECT_EQ(407, response->headers->response_code()); |
| 2706 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2707 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2708 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2709 | |
| 2710 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2711 | // out of scope. |
| 2712 | session->CloseAllConnections(); |
| 2713 | } |
| 2714 | |
| 2715 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2716 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2717 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2718 | HttpRequestInfo request; |
| 2719 | request.method = "GET"; |
| 2720 | request.url = GURL("https://www.google.com/"); |
| 2721 | // Ensure that proxy authentication is attempted even |
| 2722 | // when the no authentication data flag is set. |
| 2723 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2724 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2725 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2726 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2727 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2728 | session_deps_.net_log = log.bound().net_log(); |
| 2729 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2730 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2731 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2732 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2733 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | // Since we have proxy, should try to establish tunnel. |
| 2735 | MockWrite data_writes1[] = { |
| 2736 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2737 | "Host: www.google.com\r\n" |
| 2738 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | |
| 2740 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2741 | // be issuing -- the final header line contains the credentials. |
| 2742 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2743 | "Host: www.google.com\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2744 | "Proxy-Connection: keep-alive\r\n" |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2745 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2746 | }; |
| 2747 | |
| 2748 | // The proxy responds to the connect with a 407, using a persistent |
| 2749 | // connection. |
| 2750 | MockRead data_reads1[] = { |
| 2751 | // No credentials. |
| 2752 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2753 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2754 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2755 | MockRead("0123456789"), |
| 2756 | |
| 2757 | // Wrong credentials (wrong password). |
| 2758 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2759 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2760 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2761 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2762 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2763 | }; |
| 2764 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2765 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2766 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2767 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2769 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2770 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2771 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2773 | |
| 2774 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2775 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 2776 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2777 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2778 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2779 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2780 | NetLog::PHASE_NONE); |
| 2781 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2782 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2783 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2784 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2785 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2786 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2787 | ASSERT_TRUE(response); |
| 2788 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2789 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2790 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame^] | 2791 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2792 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2793 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2795 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | |
| 2797 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2798 | rv = trans->RestartWithAuth( |
| 2799 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2800 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2801 | |
| 2802 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2803 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | |
| 2805 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2806 | ASSERT_TRUE(response); |
| 2807 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2808 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2809 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame^] | 2810 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2811 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2812 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2813 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2814 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2815 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2816 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2817 | } |
| 2818 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2819 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2820 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2821 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2822 | HttpRequestInfo request; |
| 2823 | request.method = "GET"; |
| 2824 | request.url = GURL("https://www.google.com/"); |
| 2825 | request.load_flags = 0; |
| 2826 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2827 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2828 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2829 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2830 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2831 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2832 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2833 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2834 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2835 | // Since we have proxy, should try to establish tunnel. |
| 2836 | MockWrite data_writes[] = { |
| 2837 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 2838 | "Host: www.google.com\r\n" |
| 2839 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2840 | }; |
| 2841 | |
| 2842 | // The proxy responds to the connect with a 407. |
| 2843 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2844 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2845 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2846 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2847 | MockRead("0123456789"), // Should not be reached. |
| 2848 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2849 | }; |
| 2850 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2851 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2852 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2853 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2855 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2857 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2858 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2859 | |
| 2860 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2861 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2862 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2863 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2864 | ASSERT_TRUE(response); |
| 2865 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2866 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2867 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2868 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2869 | |
| 2870 | std::string response_data; |
| 2871 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2872 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2873 | |
| 2874 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2875 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2876 | } |
| 2877 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2878 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 2879 | // caller when the proxy responds to CONNECT with 407. |
| 2880 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 2881 | HttpRequestInfo request; |
| 2882 | request.method = "GET"; |
| 2883 | request.url = GURL("https://www.google.com/"); |
| 2884 | request.load_flags = 0; |
| 2885 | |
| 2886 | // Configure against proxy server "myproxy:70". |
| 2887 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2888 | |
| 2889 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2890 | |
| 2891 | scoped_ptr<HttpTransaction> trans( |
| 2892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2893 | |
| 2894 | // Since we have proxy, should try to establish tunnel. |
| 2895 | MockWrite data_writes[] = { |
| 2896 | MockWrite( |
| 2897 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 2898 | "Host: www.google.com\r\n" |
| 2899 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2900 | }; |
| 2901 | |
| 2902 | // The proxy responds to the connect with a 407. |
| 2903 | MockRead data_reads[] = { |
| 2904 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2905 | MockRead("X-Foo: bar\r\n"), |
| 2906 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 2907 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2908 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2909 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2910 | }; |
| 2911 | |
| 2912 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2913 | arraysize(data_writes)); |
| 2914 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2915 | |
| 2916 | TestCompletionCallback callback; |
| 2917 | |
| 2918 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2920 | |
| 2921 | rv = callback.WaitForResult(); |
| 2922 | EXPECT_EQ(OK, rv); |
| 2923 | |
| 2924 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2925 | ASSERT_TRUE(response); |
| 2926 | ASSERT_TRUE(response->headers); |
| 2927 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2928 | EXPECT_EQ(407, response->headers->response_code()); |
| 2929 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2930 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 2931 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 2932 | |
| 2933 | std::string response_data; |
| 2934 | rv = ReadTransaction(trans.get(), &response_data); |
| 2935 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 2936 | |
| 2937 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 2938 | session->CloseAllConnections(); |
| 2939 | } |
| 2940 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2941 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2942 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2943 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2944 | HttpRequestInfo request; |
| 2945 | request.method = "GET"; |
| 2946 | request.url = GURL("http://www.google.com/"); |
| 2947 | request.load_flags = 0; |
| 2948 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2949 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2950 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2951 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2952 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2953 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2954 | MockWrite data_writes1[] = { |
| 2955 | MockWrite("GET / HTTP/1.1\r\n" |
| 2956 | "Host: www.google.com\r\n" |
| 2957 | "Connection: keep-alive\r\n\r\n"), |
| 2958 | }; |
| 2959 | |
| 2960 | MockRead data_reads1[] = { |
| 2961 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2962 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2963 | // Large content-length -- won't matter, as connection will be reset. |
| 2964 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2965 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2966 | }; |
| 2967 | |
| 2968 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2969 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2970 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2972 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2974 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2976 | |
| 2977 | rv = callback.WaitForResult(); |
| 2978 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 2979 | } |
| 2980 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2981 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 2982 | // through a non-authenticating proxy. The request should fail with |
| 2983 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 2984 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 2985 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 2986 | // response came from the proxy or the server, so it is treated as if the proxy |
| 2987 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2988 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 2989 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2990 | HttpRequestInfo request; |
| 2991 | request.method = "GET"; |
| 2992 | request.url = GURL("https://www.google.com/"); |
| 2993 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2994 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 2995 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2996 | session_deps_.net_log = log.bound().net_log(); |
| 2997 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2998 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 2999 | // Since we have proxy, should try to establish tunnel. |
| 3000 | MockWrite data_writes1[] = { |
| 3001 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 3002 | "Host: www.google.com\r\n" |
| 3003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3004 | |
| 3005 | MockWrite("GET / HTTP/1.1\r\n" |
| 3006 | "Host: www.google.com\r\n" |
| 3007 | "Connection: keep-alive\r\n\r\n"), |
| 3008 | }; |
| 3009 | |
| 3010 | MockRead data_reads1[] = { |
| 3011 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3012 | |
| 3013 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3014 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3015 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3016 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3017 | }; |
| 3018 | |
| 3019 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3020 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3021 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3022 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3023 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3025 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3026 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3027 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3028 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3030 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3032 | |
| 3033 | rv = callback1.WaitForResult(); |
| 3034 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3035 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3036 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3037 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3038 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3039 | NetLog::PHASE_NONE); |
| 3040 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3041 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3042 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3043 | NetLog::PHASE_NONE); |
| 3044 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3045 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3046 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3047 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3048 | HttpRequestInfo request1; |
| 3049 | request1.method = "GET"; |
| 3050 | request1.url = GURL("https://www.google.com/1"); |
| 3051 | |
| 3052 | HttpRequestInfo request2; |
| 3053 | request2.method = "GET"; |
| 3054 | request2.url = GURL("https://www.google.com/2"); |
| 3055 | |
| 3056 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3057 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3058 | ProxyService::CreateFixed("PROXY myproxy:70")); |
| 3059 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3060 | session_deps_.net_log = log.bound().net_log(); |
| 3061 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3062 | |
| 3063 | // Since we have proxy, should try to establish tunnel. |
| 3064 | MockWrite data_writes1[] = { |
| 3065 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 3066 | "Host: www.google.com\r\n" |
| 3067 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3068 | |
| 3069 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3070 | "Host: www.google.com\r\n" |
| 3071 | "Connection: keep-alive\r\n\r\n"), |
| 3072 | |
| 3073 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3074 | "Host: www.google.com\r\n" |
| 3075 | "Connection: keep-alive\r\n\r\n"), |
| 3076 | }; |
| 3077 | |
| 3078 | // The proxy responds to the connect with a 407, using a persistent |
| 3079 | // connection. |
| 3080 | MockRead data_reads1[] = { |
| 3081 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3082 | |
| 3083 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3084 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3085 | MockRead(SYNCHRONOUS, "1"), |
| 3086 | |
| 3087 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3088 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3089 | MockRead(SYNCHRONOUS, "22"), |
| 3090 | }; |
| 3091 | |
| 3092 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3093 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3094 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3095 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3097 | |
| 3098 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3099 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3100 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3101 | |
| 3102 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3104 | |
| 3105 | rv = callback1.WaitForResult(); |
| 3106 | EXPECT_EQ(OK, rv); |
| 3107 | |
| 3108 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3109 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3110 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3111 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3112 | |
| 3113 | LoadTimingInfo load_timing_info1; |
| 3114 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3115 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3116 | |
| 3117 | trans1.reset(); |
| 3118 | |
| 3119 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3120 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3122 | |
| 3123 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3124 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3125 | |
| 3126 | rv = callback2.WaitForResult(); |
| 3127 | EXPECT_EQ(OK, rv); |
| 3128 | |
| 3129 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3130 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3131 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3132 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3133 | |
| 3134 | LoadTimingInfo load_timing_info2; |
| 3135 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3136 | TestLoadTimingReused(load_timing_info2); |
| 3137 | |
| 3138 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3139 | |
| 3140 | trans2.reset(); |
| 3141 | session->CloseAllConnections(); |
| 3142 | } |
| 3143 | |
| 3144 | // 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] | 3145 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3146 | HttpRequestInfo request1; |
| 3147 | request1.method = "GET"; |
| 3148 | request1.url = GURL("https://www.google.com/1"); |
| 3149 | |
| 3150 | HttpRequestInfo request2; |
| 3151 | request2.method = "GET"; |
| 3152 | request2.url = GURL("https://www.google.com/2"); |
| 3153 | |
| 3154 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3155 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3156 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 3157 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3158 | session_deps_.net_log = log.bound().net_log(); |
| 3159 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3160 | |
| 3161 | // Since we have proxy, should try to establish tunnel. |
| 3162 | MockWrite data_writes1[] = { |
| 3163 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 3164 | "Host: www.google.com\r\n" |
| 3165 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3166 | |
| 3167 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3168 | "Host: www.google.com\r\n" |
| 3169 | "Connection: keep-alive\r\n\r\n"), |
| 3170 | |
| 3171 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3172 | "Host: www.google.com\r\n" |
| 3173 | "Connection: keep-alive\r\n\r\n"), |
| 3174 | }; |
| 3175 | |
| 3176 | // The proxy responds to the connect with a 407, using a persistent |
| 3177 | // connection. |
| 3178 | MockRead data_reads1[] = { |
| 3179 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3180 | |
| 3181 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3182 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3183 | MockRead(SYNCHRONOUS, "1"), |
| 3184 | |
| 3185 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3186 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3187 | MockRead(SYNCHRONOUS, "22"), |
| 3188 | }; |
| 3189 | |
| 3190 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3191 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3192 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3193 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3195 | |
| 3196 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3197 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3198 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3199 | |
| 3200 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3201 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3202 | |
| 3203 | rv = callback1.WaitForResult(); |
| 3204 | EXPECT_EQ(OK, rv); |
| 3205 | |
| 3206 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3207 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3208 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3209 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3210 | |
| 3211 | LoadTimingInfo load_timing_info1; |
| 3212 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3213 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3214 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3215 | |
| 3216 | trans1.reset(); |
| 3217 | |
| 3218 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3219 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3221 | |
| 3222 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3223 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3224 | |
| 3225 | rv = callback2.WaitForResult(); |
| 3226 | EXPECT_EQ(OK, rv); |
| 3227 | |
| 3228 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3229 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3230 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3231 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3232 | |
| 3233 | LoadTimingInfo load_timing_info2; |
| 3234 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3235 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3236 | |
| 3237 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3238 | |
| 3239 | trans2.reset(); |
| 3240 | session->CloseAllConnections(); |
| 3241 | } |
| 3242 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3243 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3244 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3245 | HttpRequestInfo request; |
| 3246 | request.method = "GET"; |
| 3247 | request.url = GURL("http://www.google.com/"); |
| 3248 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3249 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3250 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3251 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3252 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3253 | session_deps_.net_log = log.bound().net_log(); |
| 3254 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3255 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3256 | // Since we have proxy, should use full url |
| 3257 | MockWrite data_writes1[] = { |
| 3258 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 3259 | "Host: www.google.com\r\n" |
| 3260 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3261 | }; |
| 3262 | |
| 3263 | MockRead data_reads1[] = { |
| 3264 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3265 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3266 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3267 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3268 | }; |
| 3269 | |
| 3270 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3271 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3272 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3273 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3276 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3277 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3278 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3279 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3281 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3282 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3283 | |
| 3284 | rv = callback1.WaitForResult(); |
| 3285 | EXPECT_EQ(OK, rv); |
| 3286 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3287 | LoadTimingInfo load_timing_info; |
| 3288 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3289 | TestLoadTimingNotReused(load_timing_info, |
| 3290 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3291 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3292 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3293 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3294 | |
| 3295 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3296 | EXPECT_EQ(200, response->headers->response_code()); |
| 3297 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3298 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3299 | |
| 3300 | // The password prompt info should not be set. |
| 3301 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3302 | } |
| 3303 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3304 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3305 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3306 | HttpRequestInfo request; |
| 3307 | request.method = "GET"; |
| 3308 | request.url = GURL("http://www.google.com/"); |
| 3309 | request.load_flags = 0; |
| 3310 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3311 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3312 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3313 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3314 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3315 | session_deps_.net_log = log.bound().net_log(); |
| 3316 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3317 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3318 | // fetch http://www.google.com/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3319 | scoped_ptr<SpdyFrame> req( |
| 3320 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3321 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 3322 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3323 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3324 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3325 | MockRead spdy_reads[] = { |
| 3326 | CreateMockRead(*resp), |
| 3327 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3328 | MockRead(ASYNC, 0, 0), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3329 | }; |
| 3330 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3331 | DelayedSocketData spdy_data( |
| 3332 | 1, // wait for one write to finish before reading. |
| 3333 | spdy_reads, arraysize(spdy_reads), |
| 3334 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3335 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3336 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3337 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3338 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3341 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3342 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3343 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3344 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3346 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3347 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3348 | |
| 3349 | rv = callback1.WaitForResult(); |
| 3350 | EXPECT_EQ(OK, rv); |
| 3351 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3352 | LoadTimingInfo load_timing_info; |
| 3353 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3354 | TestLoadTimingNotReused(load_timing_info, |
| 3355 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3356 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3358 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3359 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3360 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3361 | |
| 3362 | std::string response_data; |
| 3363 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3364 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3365 | } |
| 3366 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3367 | // Verifies that a session which races and wins against the owning transaction |
| 3368 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3369 | // Regression test for crbug.com/334413. |
| 3370 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3371 | HttpRequestInfo request; |
| 3372 | request.method = "GET"; |
| 3373 | request.url = GURL("http://www.google.com/"); |
| 3374 | request.load_flags = 0; |
| 3375 | |
| 3376 | // Configure SPDY proxy server "proxy:70". |
| 3377 | session_deps_.proxy_service.reset( |
| 3378 | ProxyService::CreateFixed("https://proxy:70")); |
| 3379 | CapturingBoundNetLog log; |
| 3380 | session_deps_.net_log = log.bound().net_log(); |
| 3381 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3382 | |
| 3383 | // Fetch http://www.google.com/ through the SPDY proxy. |
| 3384 | scoped_ptr<SpdyFrame> req( |
| 3385 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
| 3386 | MockWrite spdy_writes[] = {CreateMockWrite(*req)}; |
| 3387 | |
| 3388 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3389 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3390 | MockRead spdy_reads[] = { |
| 3391 | CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0), |
| 3392 | }; |
| 3393 | |
| 3394 | DelayedSocketData spdy_data( |
| 3395 | 1, // wait for one write to finish before reading. |
| 3396 | spdy_reads, |
| 3397 | arraysize(spdy_reads), |
| 3398 | spdy_writes, |
| 3399 | arraysize(spdy_writes)); |
| 3400 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3401 | |
| 3402 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3403 | ssl.SetNextProto(GetParam()); |
| 3404 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3405 | |
| 3406 | TestCompletionCallback callback1; |
| 3407 | |
| 3408 | scoped_ptr<HttpTransaction> trans( |
| 3409 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3410 | |
| 3411 | // Stall the hostname resolution begun by the transaction. |
| 3412 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3413 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3414 | |
| 3415 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3416 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3417 | |
| 3418 | // Race a session to the proxy, which completes first. |
| 3419 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3420 | SpdySessionKey key( |
| 3421 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3422 | base::WeakPtr<SpdySession> spdy_session = |
| 3423 | CreateSecureSpdySession(session, key, log.bound()); |
| 3424 | |
| 3425 | // Unstall the resolution begun by the transaction. |
| 3426 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3427 | session_deps_.host_resolver->ResolveAllPending(); |
| 3428 | |
| 3429 | EXPECT_FALSE(callback1.have_result()); |
| 3430 | rv = callback1.WaitForResult(); |
| 3431 | EXPECT_EQ(OK, rv); |
| 3432 | |
| 3433 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3434 | ASSERT_TRUE(response != NULL); |
| 3435 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3436 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3437 | |
| 3438 | std::string response_data; |
| 3439 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3440 | EXPECT_EQ(kUploadData, response_data); |
| 3441 | } |
| 3442 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3443 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3444 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3445 | HttpRequestInfo request; |
| 3446 | request.method = "GET"; |
| 3447 | request.url = GURL("http://www.google.com/"); |
| 3448 | request.load_flags = 0; |
| 3449 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3450 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3451 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3452 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3453 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3454 | session_deps_.net_log = log.bound().net_log(); |
| 3455 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3456 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3457 | // The first request will be a bare GET, the second request will be a |
| 3458 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3459 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3460 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3461 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3462 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3463 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3464 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3465 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3466 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3467 | false, |
| 3468 | 3, |
| 3469 | LOWEST, |
| 3470 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3471 | MockWrite spdy_writes[] = { |
| 3472 | CreateMockWrite(*req_get, 1), |
| 3473 | CreateMockWrite(*req_get_authorization, 4), |
| 3474 | }; |
| 3475 | |
| 3476 | // The first response is a 407 proxy authentication challenge, and the second |
| 3477 | // response will be a 200 response since the second request includes a valid |
| 3478 | // Authorization header. |
| 3479 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3480 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3481 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3482 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3483 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3484 | "407 Proxy Authentication Required", |
| 3485 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3486 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3487 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3488 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3489 | scoped_ptr<SpdyFrame> resp_data( |
| 3490 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3491 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3492 | MockRead spdy_reads[] = { |
| 3493 | CreateMockRead(*resp_authentication, 2), |
| 3494 | CreateMockRead(*body_authentication, 3), |
| 3495 | CreateMockRead(*resp_data, 5), |
| 3496 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3497 | MockRead(ASYNC, 0, 7), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3498 | }; |
| 3499 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3500 | OrderedSocketData data( |
| 3501 | spdy_reads, arraysize(spdy_reads), |
| 3502 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3503 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3504 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3505 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3506 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3507 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3508 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3509 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3510 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3511 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3514 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3516 | |
| 3517 | rv = callback1.WaitForResult(); |
| 3518 | EXPECT_EQ(OK, rv); |
| 3519 | |
| 3520 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3521 | |
| 3522 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3523 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3524 | EXPECT_EQ(407, response->headers->response_code()); |
| 3525 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3526 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3528 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3530 | rv = trans->RestartWithAuth( |
| 3531 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3532 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3533 | |
| 3534 | rv = callback2.WaitForResult(); |
| 3535 | EXPECT_EQ(OK, rv); |
| 3536 | |
| 3537 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3538 | |
| 3539 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3540 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3541 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3542 | // The password prompt info should not be set. |
| 3543 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3544 | } |
| 3545 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3546 | // 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] | 3547 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3548 | HttpRequestInfo request; |
| 3549 | request.method = "GET"; |
| 3550 | request.url = GURL("https://www.google.com/"); |
| 3551 | request.load_flags = 0; |
| 3552 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3553 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3554 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3555 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3556 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3557 | session_deps_.net_log = log.bound().net_log(); |
| 3558 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3559 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3560 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3561 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3562 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3563 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3564 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3565 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3566 | // fetch https://www.google.com/ via HTTP |
| 3567 | |
| 3568 | const char get[] = "GET / HTTP/1.1\r\n" |
| 3569 | "Host: www.google.com\r\n" |
| 3570 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3571 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3572 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3573 | scoped_ptr<SpdyFrame> conn_resp( |
| 3574 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3575 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3576 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3577 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3578 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3579 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3580 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3581 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3582 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3583 | |
| 3584 | MockWrite spdy_writes[] = { |
| 3585 | CreateMockWrite(*connect, 1), |
| 3586 | CreateMockWrite(*wrapped_get, 3), |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3587 | CreateMockWrite(*window_update, 5), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3588 | }; |
| 3589 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3590 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3591 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3592 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3593 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3594 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 3595 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3596 | }; |
| 3597 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3598 | OrderedSocketData spdy_data( |
| 3599 | spdy_reads, arraysize(spdy_reads), |
| 3600 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3601 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3602 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3603 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3604 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3606 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3607 | ssl2.was_npn_negotiated = false; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 3608 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3611 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3613 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3614 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3615 | |
| 3616 | rv = callback1.WaitForResult(); |
| 3617 | EXPECT_EQ(OK, rv); |
| 3618 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3619 | LoadTimingInfo load_timing_info; |
| 3620 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3621 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3622 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3624 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3625 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3626 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3627 | |
| 3628 | std::string response_data; |
| 3629 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3630 | EXPECT_EQ("1234567890", response_data); |
| 3631 | } |
| 3632 | |
| 3633 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3634 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3635 | HttpRequestInfo request; |
| 3636 | request.method = "GET"; |
| 3637 | request.url = GURL("https://www.google.com/"); |
| 3638 | request.load_flags = 0; |
| 3639 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3640 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3641 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3642 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3643 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3644 | session_deps_.net_log = log.bound().net_log(); |
| 3645 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3646 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3647 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3648 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3649 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3650 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3651 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3652 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3653 | // fetch https://www.google.com/ via SPDY |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 3654 | const char kMyUrl[] = "https://www.google.com/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3655 | scoped_ptr<SpdyFrame> get( |
| 3656 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3657 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3658 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3659 | scoped_ptr<SpdyFrame> conn_resp( |
| 3660 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3661 | scoped_ptr<SpdyFrame> get_resp( |
| 3662 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3663 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3664 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3665 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3666 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3667 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3668 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3669 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3670 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3671 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3672 | |
| 3673 | MockWrite spdy_writes[] = { |
| 3674 | CreateMockWrite(*connect, 1), |
| 3675 | CreateMockWrite(*wrapped_get, 3), |
| 3676 | CreateMockWrite(*window_update_get_resp, 5), |
| 3677 | CreateMockWrite(*window_update_body, 7), |
| 3678 | }; |
| 3679 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3680 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3681 | CreateMockRead(*conn_resp, 2, ASYNC), |
| 3682 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
| 3683 | CreateMockRead(*wrapped_body, 6, ASYNC), |
| 3684 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3685 | }; |
| 3686 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3687 | OrderedSocketData spdy_data( |
| 3688 | spdy_reads, arraysize(spdy_reads), |
| 3689 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3690 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3691 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3692 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3693 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3694 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3695 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3696 | ssl2.SetNextProto(GetParam()); |
| 3697 | ssl2.protocol_negotiated = GetParam(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3700 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3702 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3704 | |
| 3705 | rv = callback1.WaitForResult(); |
| 3706 | EXPECT_EQ(OK, rv); |
| 3707 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3708 | LoadTimingInfo load_timing_info; |
| 3709 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3710 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3711 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3712 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3713 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3714 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3715 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3716 | |
| 3717 | std::string response_data; |
| 3718 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3719 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3723 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3724 | HttpRequestInfo request; |
| 3725 | request.method = "GET"; |
| 3726 | request.url = GURL("https://www.google.com/"); |
| 3727 | request.load_flags = 0; |
| 3728 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3729 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3730 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3731 | "https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3732 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3733 | session_deps_.net_log = log.bound().net_log(); |
| 3734 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3735 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3736 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3737 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3738 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3739 | // CONNECT to www.google.com:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3740 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
| 3741 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3742 | scoped_ptr<SpdyFrame> get( |
| 3743 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3744 | |
| 3745 | MockWrite spdy_writes[] = { |
| 3746 | CreateMockWrite(*connect, 1), |
| 3747 | CreateMockWrite(*get, 3), |
| 3748 | }; |
| 3749 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3750 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3751 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3752 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3753 | CreateMockRead(*resp, 2, ASYNC), |
| 3754 | MockRead(ASYNC, 0, 4), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3755 | }; |
| 3756 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3757 | OrderedSocketData spdy_data( |
| 3758 | spdy_reads, arraysize(spdy_reads), |
| 3759 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3760 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3761 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3762 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3763 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3765 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3766 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3767 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3769 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3770 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3771 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3773 | |
| 3774 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3775 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3776 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3777 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3778 | } |
| 3779 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3780 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3781 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3782 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3783 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3784 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3785 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3786 | "https://proxy:70")); |
| 3787 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3788 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3789 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3790 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3791 | |
| 3792 | HttpRequestInfo request1; |
| 3793 | request1.method = "GET"; |
| 3794 | request1.url = GURL("https://www.google.com/"); |
| 3795 | request1.load_flags = 0; |
| 3796 | |
| 3797 | HttpRequestInfo request2; |
| 3798 | request2.method = "GET"; |
| 3799 | request2.url = GURL("https://news.google.com/"); |
| 3800 | request2.load_flags = 0; |
| 3801 | |
| 3802 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3803 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3804 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3805 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3806 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3807 | |
| 3808 | // Fetch https://www.google.com/ via HTTP. |
| 3809 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3810 | "Host: www.google.com\r\n" |
| 3811 | "Connection: keep-alive\r\n\r\n"; |
| 3812 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3813 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3814 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3815 | "Content-Length: 1\r\n\r\n"; |
| 3816 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3817 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3818 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3819 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3820 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3821 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3822 | |
| 3823 | // CONNECT to news.google.com:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3824 | SpdyHeaderBlock connect2_block; |
| 3825 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 3826 | connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443"; |
| 3827 | connect2_block[spdy_util_.GetHostKey()] = "news.google.com"; |
| 3828 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3829 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3830 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3831 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3832 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3833 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3834 | |
| 3835 | // Fetch https://news.google.com/ via HTTP. |
| 3836 | const char get2[] = "GET / HTTP/1.1\r\n" |
| 3837 | "Host: news.google.com\r\n" |
| 3838 | "Connection: keep-alive\r\n\r\n"; |
| 3839 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3840 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3841 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3842 | "Content-Length: 2\r\n\r\n"; |
| 3843 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3844 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3845 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3846 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3847 | |
| 3848 | MockWrite spdy_writes[] = { |
| 3849 | CreateMockWrite(*connect1, 0), |
| 3850 | CreateMockWrite(*wrapped_get1, 2), |
| 3851 | CreateMockWrite(*connect2, 5), |
| 3852 | CreateMockWrite(*wrapped_get2, 7), |
| 3853 | }; |
| 3854 | |
| 3855 | MockRead spdy_reads[] = { |
| 3856 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3857 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3858 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3859 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3860 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3861 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3862 | MockRead(ASYNC, 0, 10), |
| 3863 | }; |
| 3864 | |
| 3865 | DeterministicSocketData spdy_data( |
| 3866 | spdy_reads, arraysize(spdy_reads), |
| 3867 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3868 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3869 | |
| 3870 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3871 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3872 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3873 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 3874 | ssl2.was_npn_negotiated = false; |
| 3875 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3876 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3877 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 3878 | ssl3.was_npn_negotiated = false; |
| 3879 | ssl3.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3880 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3881 | |
| 3882 | TestCompletionCallback callback; |
| 3883 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3884 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3885 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3886 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 3887 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3888 | // The first connect and request, each of their responses, and the body. |
| 3889 | spdy_data.RunFor(5); |
| 3890 | |
| 3891 | rv = callback.WaitForResult(); |
| 3892 | EXPECT_EQ(OK, rv); |
| 3893 | |
| 3894 | LoadTimingInfo load_timing_info; |
| 3895 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3896 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3897 | |
| 3898 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3899 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3900 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3901 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3902 | |
| 3903 | std::string response_data; |
| 3904 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3905 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3906 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3907 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3908 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3909 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 3910 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3911 | |
| 3912 | // The second connect and request, each of their responses, and the body. |
| 3913 | spdy_data.RunFor(5); |
| 3914 | rv = callback.WaitForResult(); |
| 3915 | EXPECT_EQ(OK, rv); |
| 3916 | |
| 3917 | LoadTimingInfo load_timing_info2; |
| 3918 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3919 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3920 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3921 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3922 | |
| 3923 | // The requests should have different IDs, since they each are using their own |
| 3924 | // separate stream. |
| 3925 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3926 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3927 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3931 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3932 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3933 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3934 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3935 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3936 | "https://proxy:70")); |
| 3937 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3938 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3939 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3940 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3941 | |
| 3942 | HttpRequestInfo request1; |
| 3943 | request1.method = "GET"; |
| 3944 | request1.url = GURL("https://www.google.com/"); |
| 3945 | request1.load_flags = 0; |
| 3946 | |
| 3947 | HttpRequestInfo request2; |
| 3948 | request2.method = "GET"; |
| 3949 | request2.url = GURL("https://www.google.com/2"); |
| 3950 | request2.load_flags = 0; |
| 3951 | |
| 3952 | // CONNECT to www.google.com:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3953 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
| 3954 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3955 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3956 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3957 | |
| 3958 | // Fetch https://www.google.com/ via HTTP. |
| 3959 | const char get1[] = "GET / HTTP/1.1\r\n" |
| 3960 | "Host: www.google.com\r\n" |
| 3961 | "Connection: keep-alive\r\n\r\n"; |
| 3962 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3963 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3964 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3965 | "Content-Length: 1\r\n\r\n"; |
| 3966 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3967 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3968 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3969 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3970 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3971 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3972 | |
| 3973 | // Fetch https://www.google.com/2 via HTTP. |
| 3974 | const char get2[] = "GET /2 HTTP/1.1\r\n" |
| 3975 | "Host: www.google.com\r\n" |
| 3976 | "Connection: keep-alive\r\n\r\n"; |
| 3977 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3978 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3979 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3980 | "Content-Length: 2\r\n\r\n"; |
| 3981 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3982 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3983 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3984 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3985 | |
| 3986 | MockWrite spdy_writes[] = { |
| 3987 | CreateMockWrite(*connect1, 0), |
| 3988 | CreateMockWrite(*wrapped_get1, 2), |
| 3989 | CreateMockWrite(*wrapped_get2, 5), |
| 3990 | }; |
| 3991 | |
| 3992 | MockRead spdy_reads[] = { |
| 3993 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3994 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3995 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3996 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 3997 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 3998 | MockRead(ASYNC, 0, 8), |
| 3999 | }; |
| 4000 | |
| 4001 | DeterministicSocketData spdy_data( |
| 4002 | spdy_reads, arraysize(spdy_reads), |
| 4003 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4004 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4005 | |
| 4006 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4007 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4008 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4009 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 4010 | ssl2.was_npn_negotiated = false; |
| 4011 | ssl2.protocol_negotiated = kProtoUnknown; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4012 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4013 | |
| 4014 | TestCompletionCallback callback; |
| 4015 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4016 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4018 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4019 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4020 | // The first connect and request, each of their responses, and the body. |
| 4021 | spdy_data.RunFor(5); |
| 4022 | |
| 4023 | rv = callback.WaitForResult(); |
| 4024 | EXPECT_EQ(OK, rv); |
| 4025 | |
| 4026 | LoadTimingInfo load_timing_info; |
| 4027 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4028 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4029 | |
| 4030 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4031 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4032 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4033 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4034 | |
| 4035 | std::string response_data; |
| 4036 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4037 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4038 | trans.reset(); |
| 4039 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4040 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4041 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4042 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4044 | |
| 4045 | // The second request, response, and body. There should not be a second |
| 4046 | // connect. |
| 4047 | spdy_data.RunFor(3); |
| 4048 | rv = callback.WaitForResult(); |
| 4049 | EXPECT_EQ(OK, rv); |
| 4050 | |
| 4051 | LoadTimingInfo load_timing_info2; |
| 4052 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4053 | TestLoadTimingReused(load_timing_info2); |
| 4054 | |
| 4055 | // The requests should have the same ID. |
| 4056 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4057 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4058 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4062 | // Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4063 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4064 | HttpsProxySpdyLoadTimingTwoHttpRequests) { |
| 4065 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4066 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4067 | "https://proxy:70")); |
| 4068 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4069 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4070 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4071 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4072 | |
| 4073 | HttpRequestInfo request1; |
| 4074 | request1.method = "GET"; |
| 4075 | request1.url = GURL("http://www.google.com/"); |
| 4076 | request1.load_flags = 0; |
| 4077 | |
| 4078 | HttpRequestInfo request2; |
| 4079 | request2.method = "GET"; |
| 4080 | request2.url = GURL("http://news.google.com/"); |
| 4081 | request2.load_flags = 0; |
| 4082 | |
| 4083 | // http://www.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4084 | scoped_ptr<SpdyHeaderBlock> headers( |
| 4085 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4086 | scoped_ptr<SpdyFrame> get1( |
| 4087 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4088 | scoped_ptr<SpdyFrame> get_resp1( |
| 4089 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4090 | scoped_ptr<SpdyFrame> body1( |
| 4091 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4092 | |
| 4093 | // http://news.google.com/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4094 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 4095 | spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4096 | scoped_ptr<SpdyFrame> get2( |
| 4097 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4098 | scoped_ptr<SpdyFrame> get_resp2( |
| 4099 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4100 | scoped_ptr<SpdyFrame> body2( |
| 4101 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4102 | |
| 4103 | MockWrite spdy_writes[] = { |
| 4104 | CreateMockWrite(*get1, 0), |
| 4105 | CreateMockWrite(*get2, 3), |
| 4106 | }; |
| 4107 | |
| 4108 | MockRead spdy_reads[] = { |
| 4109 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4110 | CreateMockRead(*body1, 2, ASYNC), |
| 4111 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4112 | CreateMockRead(*body2, 5, ASYNC), |
| 4113 | MockRead(ASYNC, 0, 6), |
| 4114 | }; |
| 4115 | |
| 4116 | DeterministicSocketData spdy_data( |
| 4117 | spdy_reads, arraysize(spdy_reads), |
| 4118 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4119 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4120 | |
| 4121 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4122 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4123 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4124 | |
| 4125 | TestCompletionCallback callback; |
| 4126 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4127 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4128 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4129 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4130 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4131 | spdy_data.RunFor(2); |
| 4132 | |
| 4133 | rv = callback.WaitForResult(); |
| 4134 | EXPECT_EQ(OK, rv); |
| 4135 | |
| 4136 | LoadTimingInfo load_timing_info; |
| 4137 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4138 | TestLoadTimingNotReused(load_timing_info, |
| 4139 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4140 | |
| 4141 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4142 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4143 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4144 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4145 | |
| 4146 | std::string response_data; |
| 4147 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4148 | EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4149 | spdy_data.RunFor(1); |
| 4150 | EXPECT_EQ(1, callback.WaitForResult()); |
| 4151 | // Delete the first request, so the second one can reuse the socket. |
| 4152 | trans.reset(); |
| 4153 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4154 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4156 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4157 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4158 | |
| 4159 | spdy_data.RunFor(2); |
| 4160 | rv = callback.WaitForResult(); |
| 4161 | EXPECT_EQ(OK, rv); |
| 4162 | |
| 4163 | LoadTimingInfo load_timing_info2; |
| 4164 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4165 | TestLoadTimingReused(load_timing_info2); |
| 4166 | |
| 4167 | // The requests should have the same ID. |
| 4168 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4169 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4170 | EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4171 | spdy_data.RunFor(1); |
| 4172 | EXPECT_EQ(2, callback.WaitForResult()); |
| 4173 | } |
| 4174 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4175 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4176 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4177 | HttpRequestInfo request; |
| 4178 | request.method = "GET"; |
| 4179 | request.url = GURL("http://www.google.com/"); |
| 4180 | // when the no authentication data flag is set. |
| 4181 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 4182 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4183 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4184 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4185 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 4186 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4187 | session_deps_.net_log = log.bound().net_log(); |
| 4188 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4189 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4190 | // Since we have proxy, should use full url |
| 4191 | MockWrite data_writes1[] = { |
| 4192 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4193 | "Host: www.google.com\r\n" |
| 4194 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4195 | |
| 4196 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4197 | // be issuing -- the final header line contains the credentials. |
| 4198 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4199 | "Host: www.google.com\r\n" |
| 4200 | "Proxy-Connection: keep-alive\r\n" |
| 4201 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4202 | }; |
| 4203 | |
| 4204 | // The proxy responds to the GET with a 407, using a persistent |
| 4205 | // connection. |
| 4206 | MockRead data_reads1[] = { |
| 4207 | // No credentials. |
| 4208 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4209 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4210 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4211 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4212 | |
| 4213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4214 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4215 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4217 | }; |
| 4218 | |
| 4219 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4220 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4221 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4222 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4225 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4226 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4227 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4230 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4232 | |
| 4233 | rv = callback1.WaitForResult(); |
| 4234 | EXPECT_EQ(OK, rv); |
| 4235 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4236 | LoadTimingInfo load_timing_info; |
| 4237 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4238 | TestLoadTimingNotReused(load_timing_info, |
| 4239 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4240 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4241 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4242 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4243 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4244 | EXPECT_EQ(407, response->headers->response_code()); |
| 4245 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4246 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4248 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4250 | rv = trans->RestartWithAuth( |
| 4251 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4253 | |
| 4254 | rv = callback2.WaitForResult(); |
| 4255 | EXPECT_EQ(OK, rv); |
| 4256 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4257 | load_timing_info = LoadTimingInfo(); |
| 4258 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4259 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4260 | TestLoadTimingReused(load_timing_info); |
| 4261 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4262 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4263 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4264 | |
| 4265 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4266 | EXPECT_EQ(200, response->headers->response_code()); |
| 4267 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4268 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4269 | |
| 4270 | // The password prompt info should not be set. |
| 4271 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4272 | } |
| 4273 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4274 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4275 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4276 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4277 | request.method = "GET"; |
| 4278 | request.url = GURL("https://www.google.com/"); |
| 4279 | request.load_flags = 0; |
| 4280 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4281 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4282 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4283 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4284 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4285 | // Since we have proxy, should try to establish tunnel. |
| 4286 | MockWrite data_writes[] = { |
| 4287 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 4288 | "Host: www.google.com\r\n" |
| 4289 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4290 | }; |
| 4291 | |
| 4292 | MockRead data_reads[] = { |
| 4293 | status, |
| 4294 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4295 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4296 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4297 | }; |
| 4298 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4299 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4300 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4301 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4303 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4304 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4305 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4306 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4308 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4309 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4310 | |
| 4311 | rv = callback.WaitForResult(); |
| 4312 | EXPECT_EQ(expected_status, rv); |
| 4313 | } |
| 4314 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4315 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4316 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4317 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4318 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4319 | } |
| 4320 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4321 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4322 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 4323 | } |
| 4324 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4325 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4326 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 4327 | } |
| 4328 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4329 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4330 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 4331 | } |
| 4332 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4333 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4334 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 4335 | } |
| 4336 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4337 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4338 | ConnectStatusHelper( |
| 4339 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 4340 | } |
| 4341 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4342 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4343 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 4344 | } |
| 4345 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4346 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4347 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 4348 | } |
| 4349 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4350 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4351 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 4352 | } |
| 4353 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4354 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4355 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 4356 | } |
| 4357 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4358 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4359 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 4360 | } |
| 4361 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4362 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4363 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 4364 | } |
| 4365 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4366 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4367 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 4368 | } |
| 4369 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4370 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4371 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 4372 | } |
| 4373 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4374 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4375 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 4376 | } |
| 4377 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4378 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4379 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 4380 | } |
| 4381 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4382 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4383 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 4384 | } |
| 4385 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 4386 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 4387 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 4388 | } |
| 4389 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4390 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4391 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 4392 | } |
| 4393 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4394 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4395 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 4396 | } |
| 4397 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4398 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4399 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 4400 | } |
| 4401 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4402 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4403 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 4404 | } |
| 4405 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4406 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4407 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 4408 | } |
| 4409 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4410 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4411 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 4412 | } |
| 4413 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4414 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4415 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 4416 | } |
| 4417 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4418 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4419 | ConnectStatusHelperWithExpectedStatus( |
| 4420 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 4421 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4422 | } |
| 4423 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4424 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4425 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 4426 | } |
| 4427 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4428 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4429 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 4430 | } |
| 4431 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4432 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4433 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 4434 | } |
| 4435 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4436 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4437 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 4438 | } |
| 4439 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4440 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4441 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 4442 | } |
| 4443 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4444 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4445 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 4446 | } |
| 4447 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4448 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4449 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 4450 | } |
| 4451 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4452 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4453 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 4454 | } |
| 4455 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4456 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4457 | ConnectStatusHelper( |
| 4458 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 4459 | } |
| 4460 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4461 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4462 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 4463 | } |
| 4464 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4465 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4466 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 4467 | } |
| 4468 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4469 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4470 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 4471 | } |
| 4472 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4473 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4474 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 4475 | } |
| 4476 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4477 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4478 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 4479 | } |
| 4480 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4481 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4482 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 4483 | } |
| 4484 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4485 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4486 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 4487 | } |
| 4488 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4489 | // Test the flow when both the proxy server AND origin server require |
| 4490 | // authentication. Again, this uses basic auth for both since that is |
| 4491 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4492 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4493 | HttpRequestInfo request; |
| 4494 | request.method = "GET"; |
| 4495 | request.url = GURL("http://www.google.com/"); |
| 4496 | request.load_flags = 0; |
| 4497 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4498 | // Configure against proxy server "myproxy:70". |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4499 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 4500 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4501 | |
| 4502 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4503 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4504 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4505 | MockWrite data_writes1[] = { |
| 4506 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4507 | "Host: www.google.com\r\n" |
| 4508 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4509 | }; |
| 4510 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4511 | MockRead data_reads1[] = { |
| 4512 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4513 | // Give a couple authenticate options (only the middle one is actually |
| 4514 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4515 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4516 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4517 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4518 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4519 | // Large content-length -- won't matter, as connection will be reset. |
| 4520 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4521 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4522 | }; |
| 4523 | |
| 4524 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4525 | // request we should be issuing -- the final header line contains the |
| 4526 | // proxy's credentials. |
| 4527 | MockWrite data_writes2[] = { |
| 4528 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4529 | "Host: www.google.com\r\n" |
| 4530 | "Proxy-Connection: keep-alive\r\n" |
| 4531 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4532 | }; |
| 4533 | |
| 4534 | // Now the proxy server lets the request pass through to origin server. |
| 4535 | // The origin server responds with a 401. |
| 4536 | MockRead data_reads2[] = { |
| 4537 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4538 | // Note: We are using the same realm-name as the proxy server. This is |
| 4539 | // completely valid, as realms are unique across hosts. |
| 4540 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4541 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4542 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4543 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4544 | }; |
| 4545 | |
| 4546 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4547 | // the credentials for both the proxy and origin server. |
| 4548 | MockWrite data_writes3[] = { |
| 4549 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 4550 | "Host: www.google.com\r\n" |
| 4551 | "Proxy-Connection: keep-alive\r\n" |
| 4552 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4553 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4554 | }; |
| 4555 | |
| 4556 | // Lastly we get the desired content. |
| 4557 | MockRead data_reads3[] = { |
| 4558 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4559 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4560 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4561 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4562 | }; |
| 4563 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4564 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4565 | data_writes1, arraysize(data_writes1)); |
| 4566 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4567 | data_writes2, arraysize(data_writes2)); |
| 4568 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4569 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4570 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4571 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4572 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4574 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4576 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4577 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4578 | |
| 4579 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4580 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4581 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4582 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4583 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4584 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4586 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4588 | rv = trans->RestartWithAuth( |
| 4589 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4590 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4591 | |
| 4592 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4593 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4594 | |
| 4595 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4596 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4597 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4599 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4601 | rv = trans->RestartWithAuth( |
| 4602 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4603 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4604 | |
| 4605 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4606 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4607 | |
| 4608 | response = trans->GetResponseInfo(); |
| 4609 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4610 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4611 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4612 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4613 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4614 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4615 | // authorization headers. |
| 4616 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4617 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4618 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4619 | // bytes in the debugger. |
| 4620 | |
| 4621 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4622 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4623 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4624 | request.method = "GET"; |
| 4625 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4626 | |
| 4627 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4628 | // to other auth schemes. |
| 4629 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4630 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4631 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4632 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4633 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4634 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4635 | MockWrite data_writes1[] = { |
| 4636 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4637 | "Host: 172.22.68.17\r\n" |
| 4638 | "Connection: keep-alive\r\n\r\n"), |
| 4639 | }; |
| 4640 | |
| 4641 | MockRead data_reads1[] = { |
| 4642 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4643 | // Negotiate and NTLM are often requested together. However, we only want |
| 4644 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4645 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4646 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4647 | MockRead("Connection: close\r\n"), |
| 4648 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4649 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4650 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4651 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4652 | }; |
| 4653 | |
| 4654 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4655 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4656 | // request we should be issuing -- the final header line contains a Type |
| 4657 | // 1 message. |
| 4658 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4659 | "Host: 172.22.68.17\r\n" |
| 4660 | "Connection: keep-alive\r\n" |
| 4661 | "Authorization: NTLM " |
| 4662 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4663 | |
| 4664 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4665 | // (the credentials for the origin server). The second request continues |
| 4666 | // on the same connection. |
| 4667 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4668 | "Host: 172.22.68.17\r\n" |
| 4669 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4670 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4671 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4672 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4673 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4674 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4675 | }; |
| 4676 | |
| 4677 | MockRead data_reads2[] = { |
| 4678 | // The origin server responds with a Type 2 message. |
| 4679 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4680 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4681 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4682 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4683 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4684 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4685 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4686 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4687 | "BtAAAAAAA=\r\n"), |
| 4688 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4689 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4690 | MockRead("You are not authorized to view this page\r\n"), |
| 4691 | |
| 4692 | // Lastly we get the desired content. |
| 4693 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4694 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4695 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4696 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4697 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4698 | }; |
| 4699 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4700 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4701 | data_writes1, arraysize(data_writes1)); |
| 4702 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4703 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4704 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4705 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4707 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4708 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4709 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4710 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4712 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4713 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4714 | |
| 4715 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4716 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4717 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4718 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4719 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4720 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4721 | ASSERT_FALSE(response == NULL); |
| 4722 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4724 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4725 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4726 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4727 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4728 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4729 | |
| 4730 | rv = callback2.WaitForResult(); |
| 4731 | EXPECT_EQ(OK, rv); |
| 4732 | |
| 4733 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4734 | |
| 4735 | response = trans->GetResponseInfo(); |
| 4736 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4737 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4739 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4741 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4743 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4744 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4745 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4746 | |
| 4747 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4748 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4749 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4750 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4751 | } |
| 4752 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4753 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4754 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4755 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4756 | request.method = "GET"; |
| 4757 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4758 | request.load_flags = 0; |
| 4759 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4760 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4761 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4762 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4763 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4764 | MockWrite data_writes1[] = { |
| 4765 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4766 | "Host: 172.22.68.17\r\n" |
| 4767 | "Connection: keep-alive\r\n\r\n"), |
| 4768 | }; |
| 4769 | |
| 4770 | MockRead data_reads1[] = { |
| 4771 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4772 | // Negotiate and NTLM are often requested together. However, we only want |
| 4773 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4774 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4775 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4776 | MockRead("Connection: close\r\n"), |
| 4777 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4778 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4779 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4780 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4781 | }; |
| 4782 | |
| 4783 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4784 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4785 | // request we should be issuing -- the final header line contains a Type |
| 4786 | // 1 message. |
| 4787 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4788 | "Host: 172.22.68.17\r\n" |
| 4789 | "Connection: keep-alive\r\n" |
| 4790 | "Authorization: NTLM " |
| 4791 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4792 | |
| 4793 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4794 | // (the credentials for the origin server). The second request continues |
| 4795 | // on the same connection. |
| 4796 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4797 | "Host: 172.22.68.17\r\n" |
| 4798 | "Connection: keep-alive\r\n" |
| 4799 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4800 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4801 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4802 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4803 | "4Ww7b7E=\r\n\r\n"), |
| 4804 | }; |
| 4805 | |
| 4806 | MockRead data_reads2[] = { |
| 4807 | // The origin server responds with a Type 2 message. |
| 4808 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4809 | MockRead("WWW-Authenticate: NTLM " |
| 4810 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4811 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4812 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4813 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4814 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4815 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4816 | "BtAAAAAAA=\r\n"), |
| 4817 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4818 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4819 | MockRead("You are not authorized to view this page\r\n"), |
| 4820 | |
| 4821 | // Wrong password. |
| 4822 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4823 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4824 | MockRead("Connection: close\r\n"), |
| 4825 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4826 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4827 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4828 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4829 | }; |
| 4830 | |
| 4831 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4832 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4833 | // request we should be issuing -- the final header line contains a Type |
| 4834 | // 1 message. |
| 4835 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4836 | "Host: 172.22.68.17\r\n" |
| 4837 | "Connection: keep-alive\r\n" |
| 4838 | "Authorization: NTLM " |
| 4839 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4840 | |
| 4841 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4842 | // (the credentials for the origin server). The second request continues |
| 4843 | // on the same connection. |
| 4844 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4845 | "Host: 172.22.68.17\r\n" |
| 4846 | "Connection: keep-alive\r\n" |
| 4847 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4848 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4849 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4850 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4851 | "+4MUm7c=\r\n\r\n"), |
| 4852 | }; |
| 4853 | |
| 4854 | MockRead data_reads3[] = { |
| 4855 | // The origin server responds with a Type 2 message. |
| 4856 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4857 | MockRead("WWW-Authenticate: NTLM " |
| 4858 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4859 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4860 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4861 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4862 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4863 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4864 | "BtAAAAAAA=\r\n"), |
| 4865 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4866 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4867 | MockRead("You are not authorized to view this page\r\n"), |
| 4868 | |
| 4869 | // Lastly we get the desired content. |
| 4870 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4871 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4872 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4873 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4874 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4875 | }; |
| 4876 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4877 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4878 | data_writes1, arraysize(data_writes1)); |
| 4879 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4880 | data_writes2, arraysize(data_writes2)); |
| 4881 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4882 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4884 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4885 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4887 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4888 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4889 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4892 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4893 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4894 | |
| 4895 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4896 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4897 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4898 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4899 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4900 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4901 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4902 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4904 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4905 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4906 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4907 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4908 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4909 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4910 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4911 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4912 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4913 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4914 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4915 | TestCompletionCallback callback3; |
| 4916 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4917 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4918 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4919 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4920 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4921 | |
| 4922 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4923 | ASSERT_FALSE(response == NULL); |
| 4924 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4926 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4927 | |
| 4928 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4929 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4930 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4931 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4932 | |
| 4933 | rv = callback4.WaitForResult(); |
| 4934 | EXPECT_EQ(OK, rv); |
| 4935 | |
| 4936 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4938 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4939 | |
| 4940 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4941 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4943 | |
| 4944 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4945 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4946 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4947 | response = trans->GetResponseInfo(); |
| 4948 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4949 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4950 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4951 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4952 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4953 | // Test reading a server response which has only headers, and no body. |
| 4954 | // After some maximum number of bytes is consumed, the transaction should |
| 4955 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4956 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4957 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4958 | request.method = "GET"; |
| 4959 | request.url = GURL("http://www.google.com/"); |
| 4960 | request.load_flags = 0; |
| 4961 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4962 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4963 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4964 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4965 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4966 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4967 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4968 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4969 | |
| 4970 | MockRead data_reads[] = { |
| 4971 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4972 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4973 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4974 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4975 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4977 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4979 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4981 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4983 | |
| 4984 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4985 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4986 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4988 | EXPECT_TRUE(response == NULL); |
| 4989 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 4990 | |
| 4991 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 4992 | // establish tunnel. |
| 4993 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4994 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4995 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4996 | HttpRequestInfo request; |
| 4997 | request.method = "GET"; |
| 4998 | request.url = GURL("https://www.google.com/"); |
| 4999 | request.load_flags = 0; |
| 5000 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5001 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5002 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5003 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5004 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5005 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5006 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5007 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5008 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5009 | // Since we have proxy, should try to establish tunnel. |
| 5010 | MockWrite data_writes1[] = { |
| 5011 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 5012 | "Host: www.google.com\r\n" |
| 5013 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5014 | }; |
| 5015 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5016 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5017 | // connection. Usually a proxy would return 501 (not implemented), |
| 5018 | // or 200 (tunnel established). |
| 5019 | MockRead data_reads1[] = { |
| 5020 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5021 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5022 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5023 | }; |
| 5024 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5025 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5026 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5027 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5029 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5031 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5033 | |
| 5034 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5035 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5036 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5037 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5038 | EXPECT_TRUE(response == NULL); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5039 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5040 | // Empty the current queue. This is necessary because idle sockets are |
| 5041 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5042 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5043 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5044 | // We now check to make sure the TCPClientSocket was not added back to |
| 5045 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5046 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5047 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5048 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5049 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5050 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5051 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5052 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5053 | // 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] | 5054 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5055 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5056 | request.method = "GET"; |
| 5057 | request.url = GURL("http://www.google.com/"); |
| 5058 | request.load_flags = 0; |
| 5059 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5060 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5061 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5062 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5064 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5065 | MockRead data_reads[] = { |
| 5066 | // A part of the response body is received with the response headers. |
| 5067 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5068 | // The rest of the response body is received in two parts. |
| 5069 | MockRead("lo"), |
| 5070 | MockRead(" world"), |
| 5071 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5072 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5073 | }; |
| 5074 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5075 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5078 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5080 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5082 | |
| 5083 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5084 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5085 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5086 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5087 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5088 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5089 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5090 | std::string status_line = response->headers->GetStatusLine(); |
| 5091 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5092 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5093 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5094 | |
| 5095 | std::string response_data; |
| 5096 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5097 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5098 | EXPECT_EQ("hello world", response_data); |
| 5099 | |
| 5100 | // Empty the current queue. This is necessary because idle sockets are |
| 5101 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5102 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5103 | |
| 5104 | // 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] | 5105 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5106 | } |
| 5107 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5108 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5109 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5110 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5111 | HttpRequestInfo request; |
| 5112 | request.method = "GET"; |
| 5113 | request.url = GURL("https://www.google.com/"); |
| 5114 | request.load_flags = 0; |
| 5115 | |
| 5116 | MockWrite data_writes[] = { |
| 5117 | MockWrite("GET / HTTP/1.1\r\n" |
| 5118 | "Host: www.google.com\r\n" |
| 5119 | "Connection: keep-alive\r\n\r\n"), |
| 5120 | }; |
| 5121 | |
| 5122 | MockRead data_reads[] = { |
| 5123 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5124 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5125 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5126 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5127 | }; |
| 5128 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5129 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5130 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5131 | |
| 5132 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5133 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5135 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5136 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5137 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5138 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5139 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5140 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5142 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5143 | |
| 5144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5145 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5146 | |
| 5147 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5148 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5149 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5150 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5151 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5152 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5153 | |
| 5154 | std::string response_data; |
| 5155 | rv = ReadTransaction(trans.get(), &response_data); |
| 5156 | EXPECT_EQ(OK, rv); |
| 5157 | EXPECT_EQ("hello world", response_data); |
| 5158 | |
| 5159 | // Empty the current queue. This is necessary because idle sockets are |
| 5160 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5161 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5162 | |
| 5163 | // 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] | 5164 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5168 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5169 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5170 | HttpRequestInfo request; |
| 5171 | request.method = "GET"; |
| 5172 | request.url = GURL("https://www.google.com/"); |
| 5173 | request.load_flags = 0; |
| 5174 | |
| 5175 | MockWrite data_writes[] = { |
| 5176 | MockWrite("GET / HTTP/1.1\r\n" |
| 5177 | "Host: www.google.com\r\n" |
| 5178 | "Connection: keep-alive\r\n\r\n"), |
| 5179 | MockWrite("GET / HTTP/1.1\r\n" |
| 5180 | "Host: www.google.com\r\n" |
| 5181 | "Connection: keep-alive\r\n\r\n"), |
| 5182 | }; |
| 5183 | |
| 5184 | MockRead data_reads[] = { |
| 5185 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5186 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5187 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5188 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5189 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5190 | }; |
| 5191 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5192 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5193 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5196 | |
| 5197 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5198 | data_writes, arraysize(data_writes)); |
| 5199 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5200 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5204 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5205 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5206 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5207 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5210 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5211 | |
| 5212 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5213 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5214 | |
| 5215 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5216 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5217 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5218 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5219 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5220 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5221 | |
| 5222 | std::string response_data; |
| 5223 | rv = ReadTransaction(trans.get(), &response_data); |
| 5224 | EXPECT_EQ(OK, rv); |
| 5225 | EXPECT_EQ("hello world", response_data); |
| 5226 | |
| 5227 | // Empty the current queue. This is necessary because idle sockets are |
| 5228 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5229 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5230 | |
| 5231 | // 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] | 5232 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5233 | |
| 5234 | // Now start the second transaction, which should reuse the previous socket. |
| 5235 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5236 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5238 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5239 | |
| 5240 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5241 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5242 | |
| 5243 | response = trans->GetResponseInfo(); |
| 5244 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5245 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5246 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5247 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5248 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5249 | |
| 5250 | rv = ReadTransaction(trans.get(), &response_data); |
| 5251 | EXPECT_EQ(OK, rv); |
| 5252 | EXPECT_EQ("hello world", response_data); |
| 5253 | |
| 5254 | // Empty the current queue. This is necessary because idle sockets are |
| 5255 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5256 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5257 | |
| 5258 | // 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] | 5259 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5260 | } |
| 5261 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5262 | // Make sure that we recycle a socket after a zero-length response. |
| 5263 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5264 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5265 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5266 | request.method = "GET"; |
| 5267 | request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 5268 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5269 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5270 | "rt=prt.2642,ol.2649,xjs.2951"); |
| 5271 | request.load_flags = 0; |
| 5272 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5273 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5274 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5275 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5276 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5277 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5278 | MockRead data_reads[] = { |
| 5279 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5280 | "Content-Length: 0\r\n" |
| 5281 | "Content-Type: text/html\r\n\r\n"), |
| 5282 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5283 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5284 | }; |
| 5285 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5286 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5289 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5291 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5293 | |
| 5294 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5295 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5296 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5297 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5298 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5299 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5300 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5301 | std::string status_line = response->headers->GetStatusLine(); |
| 5302 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5303 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5304 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5305 | |
| 5306 | std::string response_data; |
| 5307 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5308 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5309 | EXPECT_EQ("", response_data); |
| 5310 | |
| 5311 | // Empty the current queue. This is necessary because idle sockets are |
| 5312 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5313 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5314 | |
| 5315 | // 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] | 5316 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5317 | } |
| 5318 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5319 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5320 | ScopedVector<UploadElementReader> element_readers; |
| 5321 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5322 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5323 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5324 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5325 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5326 | // after use. |
| 5327 | request[0].method = "GET"; |
| 5328 | request[0].url = GURL("http://www.google.com/"); |
| 5329 | request[0].load_flags = 0; |
| 5330 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5331 | // transaction 1. The first attempts fails when writing the POST data. |
| 5332 | // This causes the transaction to retry with a new socket. The second |
| 5333 | // attempt succeeds. |
| 5334 | request[1].method = "POST"; |
| 5335 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5336 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5337 | request[1].load_flags = 0; |
| 5338 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5339 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5340 | |
| 5341 | // The first socket is used for transaction 1 and the first attempt of |
| 5342 | // transaction 2. |
| 5343 | |
| 5344 | // The response of transaction 1. |
| 5345 | MockRead data_reads1[] = { |
| 5346 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5347 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5349 | }; |
| 5350 | // The mock write results of transaction 1 and the first attempt of |
| 5351 | // transaction 2. |
| 5352 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5353 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5354 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5355 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5356 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5357 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5358 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5359 | |
| 5360 | // The second socket is used for the second attempt of transaction 2. |
| 5361 | |
| 5362 | // The response of transaction 2. |
| 5363 | MockRead data_reads2[] = { |
| 5364 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5365 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5366 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5367 | }; |
| 5368 | // The mock write results of the second attempt of transaction 2. |
| 5369 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5370 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5371 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5372 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5373 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5374 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5375 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5376 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5377 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5378 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5379 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5380 | "hello world", "welcome" |
| 5381 | }; |
| 5382 | |
| 5383 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5384 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5387 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5389 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5390 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5391 | |
| 5392 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5393 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5394 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5395 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5396 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5397 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5398 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5399 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5400 | |
| 5401 | std::string response_data; |
| 5402 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5403 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5404 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5405 | } |
| 5406 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5407 | |
| 5408 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5409 | // 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] | 5410 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5411 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5412 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5413 | request.method = "GET"; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5414 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5415 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5416 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5417 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5418 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5419 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5420 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5421 | // The password contains an escaped character -- for this test to pass it |
| 5422 | // will need to be unescaped by HttpNetworkTransaction. |
| 5423 | EXPECT_EQ("b%40r", request.url.password()); |
| 5424 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5425 | MockWrite data_writes1[] = { |
| 5426 | MockWrite("GET / HTTP/1.1\r\n" |
| 5427 | "Host: www.google.com\r\n" |
| 5428 | "Connection: keep-alive\r\n\r\n"), |
| 5429 | }; |
| 5430 | |
| 5431 | MockRead data_reads1[] = { |
| 5432 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5433 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5434 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5435 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5436 | }; |
| 5437 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5438 | // After the challenge above, the transaction will be restarted using the |
| 5439 | // identity from the url (foo, b@r) to answer the challenge. |
| 5440 | MockWrite data_writes2[] = { |
| 5441 | MockWrite("GET / HTTP/1.1\r\n" |
| 5442 | "Host: www.google.com\r\n" |
| 5443 | "Connection: keep-alive\r\n" |
| 5444 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
| 5445 | }; |
| 5446 | |
| 5447 | MockRead data_reads2[] = { |
| 5448 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5449 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5450 | MockRead(SYNCHRONOUS, OK), |
| 5451 | }; |
| 5452 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5453 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5454 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5455 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5456 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5457 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5458 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5460 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5461 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5463 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5464 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5465 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5466 | |
| 5467 | TestCompletionCallback callback2; |
| 5468 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5469 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5470 | rv = callback2.WaitForResult(); |
| 5471 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5472 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5473 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5474 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5475 | ASSERT_TRUE(response != NULL); |
| 5476 | |
| 5477 | // There is no challenge info, since the identity in URL worked. |
| 5478 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5479 | |
| 5480 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5481 | |
| 5482 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5483 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5487 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5488 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5489 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5490 | HttpRequestInfo request; |
| 5491 | request.method = "GET"; |
| 5492 | // Note: the URL has a username:password in it. The password "baz" is |
| 5493 | // wrong (should be "bar"). |
| 5494 | request.url = GURL("http://foo:[email protected]/"); |
| 5495 | |
| 5496 | request.load_flags = LOAD_NORMAL; |
| 5497 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5498 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5499 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5501 | |
| 5502 | MockWrite data_writes1[] = { |
| 5503 | MockWrite("GET / HTTP/1.1\r\n" |
| 5504 | "Host: www.google.com\r\n" |
| 5505 | "Connection: keep-alive\r\n\r\n"), |
| 5506 | }; |
| 5507 | |
| 5508 | MockRead data_reads1[] = { |
| 5509 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5510 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5511 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5512 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5513 | }; |
| 5514 | |
| 5515 | // After the challenge above, the transaction will be restarted using the |
| 5516 | // identity from the url (foo, baz) to answer the challenge. |
| 5517 | MockWrite data_writes2[] = { |
| 5518 | MockWrite("GET / HTTP/1.1\r\n" |
| 5519 | "Host: www.google.com\r\n" |
| 5520 | "Connection: keep-alive\r\n" |
| 5521 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 5522 | }; |
| 5523 | |
| 5524 | MockRead data_reads2[] = { |
| 5525 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5526 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5527 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5528 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5529 | }; |
| 5530 | |
| 5531 | // After the challenge above, the transaction will be restarted using the |
| 5532 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5533 | MockWrite data_writes3[] = { |
| 5534 | MockWrite("GET / HTTP/1.1\r\n" |
| 5535 | "Host: www.google.com\r\n" |
| 5536 | "Connection: keep-alive\r\n" |
| 5537 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5538 | }; |
| 5539 | |
| 5540 | MockRead data_reads3[] = { |
| 5541 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5542 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5543 | MockRead(SYNCHRONOUS, OK), |
| 5544 | }; |
| 5545 | |
| 5546 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5547 | data_writes1, arraysize(data_writes1)); |
| 5548 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5549 | data_writes2, arraysize(data_writes2)); |
| 5550 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5551 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5552 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5553 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5554 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5555 | |
| 5556 | TestCompletionCallback callback1; |
| 5557 | |
| 5558 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5559 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5560 | |
| 5561 | rv = callback1.WaitForResult(); |
| 5562 | EXPECT_EQ(OK, rv); |
| 5563 | |
| 5564 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5565 | TestCompletionCallback callback2; |
| 5566 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5567 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5568 | rv = callback2.WaitForResult(); |
| 5569 | EXPECT_EQ(OK, rv); |
| 5570 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5571 | |
| 5572 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5573 | ASSERT_TRUE(response != NULL); |
| 5574 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5575 | |
| 5576 | TestCompletionCallback callback3; |
| 5577 | rv = trans->RestartWithAuth( |
| 5578 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5579 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5580 | rv = callback3.WaitForResult(); |
| 5581 | EXPECT_EQ(OK, rv); |
| 5582 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5583 | |
| 5584 | response = trans->GetResponseInfo(); |
| 5585 | ASSERT_TRUE(response != NULL); |
| 5586 | |
| 5587 | // There is no challenge info, since the identity worked. |
| 5588 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5589 | |
| 5590 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5591 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5592 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5593 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5594 | } |
| 5595 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5596 | |
| 5597 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5598 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5599 | // from the URL should never be used. |
| 5600 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5601 | HttpRequestInfo request; |
| 5602 | request.method = "GET"; |
| 5603 | request.url = GURL("http://foo:[email protected]/"); |
| 5604 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5605 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5606 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5607 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5609 | |
| 5610 | MockWrite data_writes1[] = { |
| 5611 | MockWrite("GET / HTTP/1.1\r\n" |
| 5612 | "Host: www.google.com\r\n" |
| 5613 | "Connection: keep-alive\r\n\r\n"), |
| 5614 | }; |
| 5615 | |
| 5616 | MockRead data_reads1[] = { |
| 5617 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5618 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5619 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5620 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5621 | }; |
| 5622 | |
| 5623 | // After the challenge above, the transaction will be restarted using the |
| 5624 | // identity supplied by the user, not the one in the URL, to answer the |
| 5625 | // challenge. |
| 5626 | MockWrite data_writes3[] = { |
| 5627 | MockWrite("GET / HTTP/1.1\r\n" |
| 5628 | "Host: www.google.com\r\n" |
| 5629 | "Connection: keep-alive\r\n" |
| 5630 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5631 | }; |
| 5632 | |
| 5633 | MockRead data_reads3[] = { |
| 5634 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5635 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5636 | MockRead(SYNCHRONOUS, OK), |
| 5637 | }; |
| 5638 | |
| 5639 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5640 | data_writes1, arraysize(data_writes1)); |
| 5641 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5642 | data_writes3, arraysize(data_writes3)); |
| 5643 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5644 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5645 | |
| 5646 | TestCompletionCallback callback1; |
| 5647 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5648 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5649 | rv = callback1.WaitForResult(); |
| 5650 | EXPECT_EQ(OK, rv); |
| 5651 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5652 | |
| 5653 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5654 | ASSERT_TRUE(response != NULL); |
| 5655 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5656 | |
| 5657 | TestCompletionCallback callback3; |
| 5658 | rv = trans->RestartWithAuth( |
| 5659 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5660 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5661 | rv = callback3.WaitForResult(); |
| 5662 | EXPECT_EQ(OK, rv); |
| 5663 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5664 | |
| 5665 | response = trans->GetResponseInfo(); |
| 5666 | ASSERT_TRUE(response != NULL); |
| 5667 | |
| 5668 | // There is no challenge info, since the identity worked. |
| 5669 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5670 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5671 | |
| 5672 | // Empty the current queue. |
| 5673 | base::MessageLoop::current()->RunUntilIdle(); |
| 5674 | } |
| 5675 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5676 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5677 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5678 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5679 | |
| 5680 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5681 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5682 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5683 | request.method = "GET"; |
| 5684 | request.url = GURL("http://www.google.com/x/y/z"); |
| 5685 | request.load_flags = 0; |
| 5686 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5687 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5688 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5689 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5690 | MockWrite data_writes1[] = { |
| 5691 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5692 | "Host: www.google.com\r\n" |
| 5693 | "Connection: keep-alive\r\n\r\n"), |
| 5694 | }; |
| 5695 | |
| 5696 | MockRead data_reads1[] = { |
| 5697 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5698 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5699 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5700 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5701 | }; |
| 5702 | |
| 5703 | // Resend with authorization (username=foo, password=bar) |
| 5704 | MockWrite data_writes2[] = { |
| 5705 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 5706 | "Host: www.google.com\r\n" |
| 5707 | "Connection: keep-alive\r\n" |
| 5708 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5709 | }; |
| 5710 | |
| 5711 | // Sever accepts the authorization. |
| 5712 | MockRead data_reads2[] = { |
| 5713 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5714 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5716 | }; |
| 5717 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5718 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5719 | data_writes1, arraysize(data_writes1)); |
| 5720 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5721 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5722 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5723 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5725 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5727 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5728 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5729 | |
| 5730 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5731 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5732 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5733 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5734 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5735 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5737 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5739 | rv = trans->RestartWithAuth( |
| 5740 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5741 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5742 | |
| 5743 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5744 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5745 | |
| 5746 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5747 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5748 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5749 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5750 | } |
| 5751 | |
| 5752 | // ------------------------------------------------------------------------ |
| 5753 | |
| 5754 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5755 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5756 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5757 | request.method = "GET"; |
| 5758 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5759 | // protection space as MyRealm1. |
| 5760 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 5761 | request.load_flags = 0; |
| 5762 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5763 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5764 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5765 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5766 | MockWrite data_writes1[] = { |
| 5767 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5768 | "Host: www.google.com\r\n" |
| 5769 | "Connection: keep-alive\r\n" |
| 5770 | // Send preemptive authorization for MyRealm1 |
| 5771 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5772 | }; |
| 5773 | |
| 5774 | // The server didn't like the preemptive authorization, and |
| 5775 | // challenges us for a different realm (MyRealm2). |
| 5776 | MockRead data_reads1[] = { |
| 5777 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5778 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5779 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5780 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5781 | }; |
| 5782 | |
| 5783 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5784 | MockWrite data_writes2[] = { |
| 5785 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 5786 | "Host: www.google.com\r\n" |
| 5787 | "Connection: keep-alive\r\n" |
| 5788 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 5789 | }; |
| 5790 | |
| 5791 | // Sever accepts the authorization. |
| 5792 | MockRead data_reads2[] = { |
| 5793 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5794 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5795 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5796 | }; |
| 5797 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5798 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5799 | data_writes1, arraysize(data_writes1)); |
| 5800 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5801 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5802 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5803 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5805 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5807 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5808 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5809 | |
| 5810 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5811 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 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 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5816 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 5817 | EXPECT_EQ("www.google.com:80", |
| 5818 | response->auth_challenge->challenger.ToString()); |
| 5819 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5820 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5822 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5824 | rv = trans->RestartWithAuth( |
| 5825 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5826 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5827 | |
| 5828 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5829 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5830 | |
| 5831 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5832 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5833 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5834 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5835 | } |
| 5836 | |
| 5837 | // ------------------------------------------------------------------------ |
| 5838 | |
| 5839 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5840 | // succeed with preemptive authorization. |
| 5841 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5842 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5843 | request.method = "GET"; |
| 5844 | request.url = GURL("http://www.google.com/x/y/z2"); |
| 5845 | request.load_flags = 0; |
| 5846 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5847 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5848 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5849 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5850 | MockWrite data_writes1[] = { |
| 5851 | MockWrite("GET /x/y/z2 HTTP/1.1\r\n" |
| 5852 | "Host: www.google.com\r\n" |
| 5853 | "Connection: keep-alive\r\n" |
| 5854 | // The authorization for MyRealm1 gets sent preemptively |
| 5855 | // (since the url is in the same protection space) |
| 5856 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5857 | }; |
| 5858 | |
| 5859 | // Sever accepts the preemptive authorization |
| 5860 | MockRead data_reads1[] = { |
| 5861 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5862 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5863 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5864 | }; |
| 5865 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5866 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5867 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5868 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5870 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5872 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5874 | |
| 5875 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5876 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5877 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5878 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5879 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5880 | |
| 5881 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5882 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5883 | } |
| 5884 | |
| 5885 | // ------------------------------------------------------------------------ |
| 5886 | |
| 5887 | // Transaction 4: request another URL in MyRealm (however the |
| 5888 | // url is not known to belong to the protection space, so no pre-auth). |
| 5889 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5890 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5891 | request.method = "GET"; |
| 5892 | request.url = GURL("http://www.google.com/x/1"); |
| 5893 | request.load_flags = 0; |
| 5894 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5895 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5897 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5898 | MockWrite data_writes1[] = { |
| 5899 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5900 | "Host: www.google.com\r\n" |
| 5901 | "Connection: keep-alive\r\n\r\n"), |
| 5902 | }; |
| 5903 | |
| 5904 | MockRead data_reads1[] = { |
| 5905 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5906 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5907 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5908 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5909 | }; |
| 5910 | |
| 5911 | // Resend with authorization from MyRealm's cache. |
| 5912 | MockWrite data_writes2[] = { |
| 5913 | MockWrite("GET /x/1 HTTP/1.1\r\n" |
| 5914 | "Host: www.google.com\r\n" |
| 5915 | "Connection: keep-alive\r\n" |
| 5916 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5917 | }; |
| 5918 | |
| 5919 | // Sever accepts the authorization. |
| 5920 | MockRead data_reads2[] = { |
| 5921 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5922 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5924 | }; |
| 5925 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5926 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5927 | data_writes1, arraysize(data_writes1)); |
| 5928 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5929 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5930 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5931 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5933 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5935 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5937 | |
| 5938 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5939 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5940 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5941 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5942 | TestCompletionCallback callback2; |
| 5943 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5944 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5945 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5946 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5947 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5948 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5949 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5950 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5951 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5952 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5953 | } |
| 5954 | |
| 5955 | // ------------------------------------------------------------------------ |
| 5956 | |
| 5957 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5958 | // cached identity. Should invalidate and re-prompt. |
| 5959 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5960 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5961 | request.method = "GET"; |
| 5962 | request.url = GURL("http://www.google.com/p/q/t"); |
| 5963 | request.load_flags = 0; |
| 5964 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5965 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5966 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5967 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5968 | MockWrite data_writes1[] = { |
| 5969 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5970 | "Host: www.google.com\r\n" |
| 5971 | "Connection: keep-alive\r\n\r\n"), |
| 5972 | }; |
| 5973 | |
| 5974 | MockRead data_reads1[] = { |
| 5975 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5976 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5977 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5978 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5979 | }; |
| 5980 | |
| 5981 | // Resend with authorization from cache for MyRealm. |
| 5982 | MockWrite data_writes2[] = { |
| 5983 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 5984 | "Host: www.google.com\r\n" |
| 5985 | "Connection: keep-alive\r\n" |
| 5986 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5987 | }; |
| 5988 | |
| 5989 | // Sever rejects the authorization. |
| 5990 | MockRead data_reads2[] = { |
| 5991 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5992 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5993 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5994 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5995 | }; |
| 5996 | |
| 5997 | // At this point we should prompt for new credentials for MyRealm. |
| 5998 | // Restart with username=foo3, password=foo4. |
| 5999 | MockWrite data_writes3[] = { |
| 6000 | MockWrite("GET /p/q/t HTTP/1.1\r\n" |
| 6001 | "Host: www.google.com\r\n" |
| 6002 | "Connection: keep-alive\r\n" |
| 6003 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 6004 | }; |
| 6005 | |
| 6006 | // Sever accepts the authorization. |
| 6007 | MockRead data_reads3[] = { |
| 6008 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6009 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6010 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6011 | }; |
| 6012 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6013 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6014 | data_writes1, arraysize(data_writes1)); |
| 6015 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6016 | data_writes2, arraysize(data_writes2)); |
| 6017 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6018 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6019 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6020 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6021 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6023 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6025 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6026 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6027 | |
| 6028 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6029 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6030 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6031 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6032 | TestCompletionCallback callback2; |
| 6033 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6034 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6035 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6036 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6037 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6038 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6039 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6040 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6041 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6043 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6045 | rv = trans->RestartWithAuth( |
| 6046 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6047 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6048 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6049 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6050 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6051 | |
| 6052 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6053 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6054 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6055 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6056 | } |
| 6057 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6058 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6059 | // Tests that nonce count increments when multiple auth attempts |
| 6060 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6061 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6062 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6063 | new HttpAuthHandlerDigest::Factory(); |
| 6064 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6065 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6066 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6067 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 6068 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6069 | |
| 6070 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6071 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6072 | HttpRequestInfo request; |
| 6073 | request.method = "GET"; |
| 6074 | request.url = GURL("http://www.google.com/x/y/z"); |
| 6075 | request.load_flags = 0; |
| 6076 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6077 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6079 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6080 | MockWrite data_writes1[] = { |
| 6081 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 6082 | "Host: www.google.com\r\n" |
| 6083 | "Connection: keep-alive\r\n\r\n"), |
| 6084 | }; |
| 6085 | |
| 6086 | MockRead data_reads1[] = { |
| 6087 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6088 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6089 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6090 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6091 | }; |
| 6092 | |
| 6093 | // Resend with authorization (username=foo, password=bar) |
| 6094 | MockWrite data_writes2[] = { |
| 6095 | MockWrite("GET /x/y/z HTTP/1.1\r\n" |
| 6096 | "Host: www.google.com\r\n" |
| 6097 | "Connection: keep-alive\r\n" |
| 6098 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6099 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6100 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6101 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 6102 | }; |
| 6103 | |
| 6104 | // Sever accepts the authorization. |
| 6105 | MockRead data_reads2[] = { |
| 6106 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6107 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6108 | }; |
| 6109 | |
| 6110 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6111 | data_writes1, arraysize(data_writes1)); |
| 6112 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6113 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6114 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6115 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6117 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6119 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6120 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6121 | |
| 6122 | rv = callback1.WaitForResult(); |
| 6123 | EXPECT_EQ(OK, rv); |
| 6124 | |
| 6125 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6126 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6127 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6129 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6131 | rv = trans->RestartWithAuth( |
| 6132 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6134 | |
| 6135 | rv = callback2.WaitForResult(); |
| 6136 | EXPECT_EQ(OK, rv); |
| 6137 | |
| 6138 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6139 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6140 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6141 | } |
| 6142 | |
| 6143 | // ------------------------------------------------------------------------ |
| 6144 | |
| 6145 | // Transaction 2: Request another resource in digestive's protection space. |
| 6146 | // This will preemptively add an Authorization header which should have an |
| 6147 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6148 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6149 | HttpRequestInfo request; |
| 6150 | request.method = "GET"; |
| 6151 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6152 | // protection space as digest. |
| 6153 | request.url = GURL("http://www.google.com/x/y/a/b"); |
| 6154 | request.load_flags = 0; |
| 6155 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6156 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6157 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6158 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6159 | MockWrite data_writes1[] = { |
| 6160 | MockWrite("GET /x/y/a/b HTTP/1.1\r\n" |
| 6161 | "Host: www.google.com\r\n" |
| 6162 | "Connection: keep-alive\r\n" |
| 6163 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6164 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6165 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6166 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
| 6167 | }; |
| 6168 | |
| 6169 | // Sever accepts the authorization. |
| 6170 | MockRead data_reads1[] = { |
| 6171 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6172 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6173 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6174 | }; |
| 6175 | |
| 6176 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6177 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6178 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6180 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6182 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6184 | |
| 6185 | rv = callback1.WaitForResult(); |
| 6186 | EXPECT_EQ(OK, rv); |
| 6187 | |
| 6188 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6189 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6190 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6191 | } |
| 6192 | } |
| 6193 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6194 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6195 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6196 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6197 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6198 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6200 | |
| 6201 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6202 | trans->read_buf_ = new IOBuffer(15); |
| 6203 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6204 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6205 | |
| 6206 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6207 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6208 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6209 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6210 | response->response_time = base::Time::Now(); |
| 6211 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6212 | |
| 6213 | { // Setup state for response_.vary_data |
| 6214 | HttpRequestInfo request; |
| 6215 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6216 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6217 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6218 | request.extra_headers.SetHeader("Foo", "1"); |
| 6219 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6220 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6221 | } |
| 6222 | |
| 6223 | // Cause the above state to be reset. |
| 6224 | trans->ResetStateForRestart(); |
| 6225 | |
| 6226 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6227 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6228 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6229 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6230 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6231 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6232 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6233 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6234 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6235 | } |
| 6236 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6237 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6238 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6239 | HttpRequestInfo request; |
| 6240 | request.method = "GET"; |
| 6241 | request.url = GURL("https://www.google.com/"); |
| 6242 | request.load_flags = 0; |
| 6243 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6244 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [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] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6247 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6248 | MockWrite data_writes[] = { |
| 6249 | MockWrite("GET / HTTP/1.1\r\n" |
| 6250 | "Host: www.google.com\r\n" |
| 6251 | "Connection: keep-alive\r\n\r\n"), |
| 6252 | }; |
| 6253 | |
| 6254 | MockRead data_reads[] = { |
| 6255 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6256 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6257 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6258 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6259 | }; |
| 6260 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6261 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6262 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6263 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6264 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6265 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6266 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6267 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6272 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6274 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6275 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6276 | |
| 6277 | rv = callback.WaitForResult(); |
| 6278 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6280 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6281 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6282 | |
| 6283 | rv = callback.WaitForResult(); |
| 6284 | EXPECT_EQ(OK, rv); |
| 6285 | |
| 6286 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6287 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6288 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6289 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6290 | } |
| 6291 | |
| 6292 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6293 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6294 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6295 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6296 | |
| 6297 | HttpRequestInfo request; |
| 6298 | request.method = "GET"; |
| 6299 | request.url = GURL("https://www.google.com/"); |
| 6300 | request.load_flags = 0; |
| 6301 | |
| 6302 | MockWrite proxy_writes[] = { |
| 6303 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6304 | "Host: www.google.com\r\n" |
| 6305 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6306 | }; |
| 6307 | |
| 6308 | MockRead proxy_reads[] = { |
| 6309 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6310 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6311 | }; |
| 6312 | |
| 6313 | MockWrite data_writes[] = { |
| 6314 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
[email protected] | e44de5d | 2009-06-05 20:12:45 | [diff] [blame] | 6315 | "Host: www.google.com\r\n" |
| 6316 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6317 | MockWrite("GET / HTTP/1.1\r\n" |
| 6318 | "Host: www.google.com\r\n" |
| 6319 | "Connection: keep-alive\r\n\r\n"), |
| 6320 | }; |
| 6321 | |
| 6322 | MockRead data_reads[] = { |
| 6323 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6324 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6325 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6326 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6327 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6328 | }; |
| 6329 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6330 | StaticSocketDataProvider ssl_bad_certificate( |
| 6331 | proxy_reads, arraysize(proxy_reads), |
| 6332 | proxy_writes, arraysize(proxy_writes)); |
| 6333 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6334 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6335 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6336 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6337 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6338 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6339 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6343 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6344 | |
| 6345 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6346 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6347 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6348 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6349 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6352 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6354 | |
| 6355 | rv = callback.WaitForResult(); |
| 6356 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6357 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6358 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6359 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6360 | |
| 6361 | rv = callback.WaitForResult(); |
| 6362 | EXPECT_EQ(OK, rv); |
| 6363 | |
| 6364 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6365 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6366 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6367 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6368 | } |
| 6369 | } |
| 6370 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6371 | |
| 6372 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6373 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6374 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6375 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6376 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6377 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6378 | |
| 6379 | HttpRequestInfo request; |
| 6380 | request.method = "GET"; |
| 6381 | request.url = GURL("https://www.google.com/"); |
| 6382 | request.load_flags = 0; |
| 6383 | |
| 6384 | MockWrite data_writes[] = { |
| 6385 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6386 | "Host: www.google.com\r\n" |
| 6387 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6388 | MockWrite("GET / HTTP/1.1\r\n" |
| 6389 | "Host: www.google.com\r\n" |
| 6390 | "Connection: keep-alive\r\n\r\n"), |
| 6391 | }; |
| 6392 | |
| 6393 | MockRead data_reads[] = { |
| 6394 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6395 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6396 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6397 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6398 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6399 | }; |
| 6400 | |
| 6401 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6402 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6403 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6404 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6405 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6406 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6410 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6411 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6412 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6413 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6414 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6416 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6417 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6418 | |
| 6419 | rv = callback.WaitForResult(); |
| 6420 | EXPECT_EQ(OK, rv); |
| 6421 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6422 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6423 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6424 | |
| 6425 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6426 | EXPECT_EQ(200, response->headers->response_code()); |
| 6427 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6428 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6429 | |
| 6430 | LoadTimingInfo load_timing_info; |
| 6431 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6432 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6433 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6434 | } |
| 6435 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6436 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6437 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6438 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6439 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 6440 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6441 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6442 | |
| 6443 | HttpRequestInfo request; |
| 6444 | request.method = "GET"; |
| 6445 | request.url = GURL("https://www.google.com/"); |
| 6446 | request.load_flags = 0; |
| 6447 | |
| 6448 | MockWrite data_writes[] = { |
| 6449 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6450 | "Host: www.google.com\r\n" |
| 6451 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6452 | }; |
| 6453 | |
| 6454 | MockRead data_reads[] = { |
| 6455 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6456 | MockRead("Location: http://login.example.com/\r\n"), |
| 6457 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6458 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6459 | }; |
| 6460 | |
| 6461 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6462 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6463 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6464 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6468 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6469 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6470 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6471 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6472 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6474 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6475 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6476 | |
| 6477 | rv = callback.WaitForResult(); |
| 6478 | EXPECT_EQ(OK, rv); |
| 6479 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6480 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6481 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6482 | |
| 6483 | EXPECT_EQ(302, response->headers->response_code()); |
| 6484 | std::string url; |
| 6485 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6486 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6487 | |
| 6488 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6489 | // timing for the proxy connection instead of the connection to the host, |
| 6490 | // and no send / receive times. |
| 6491 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6492 | LoadTimingInfo load_timing_info; |
| 6493 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6494 | |
| 6495 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 6496 | EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 6497 | |
| 6498 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6499 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6500 | load_timing_info.proxy_resolve_end); |
| 6501 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6502 | load_timing_info.connect_timing.connect_start); |
| 6503 | ExpectConnectTimingHasTimes( |
| 6504 | load_timing_info.connect_timing, |
| 6505 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6506 | |
| 6507 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6508 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6509 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6510 | } |
| 6511 | |
| 6512 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6513 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6514 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6515 | ProxyService::CreateFixed("https://proxy:70")); |
| 6516 | |
| 6517 | HttpRequestInfo request; |
| 6518 | request.method = "GET"; |
| 6519 | request.url = GURL("https://www.google.com/"); |
| 6520 | request.load_flags = 0; |
| 6521 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6522 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6523 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6524 | scoped_ptr<SpdyFrame> goaway( |
| 6525 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6526 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6527 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 6528 | CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6529 | }; |
| 6530 | |
| 6531 | static const char* const kExtraHeaders[] = { |
| 6532 | "location", |
| 6533 | "http://login.example.com/", |
| 6534 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6535 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6536 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6537 | arraysize(kExtraHeaders)/2, 1)); |
| 6538 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6539 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6540 | MockRead(ASYNC, 0, 2), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6541 | }; |
| 6542 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6543 | DelayedSocketData data( |
| 6544 | 1, // wait for one write to finish before reading. |
| 6545 | data_reads, arraysize(data_reads), |
| 6546 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6547 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6548 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6549 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6550 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6551 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6552 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6553 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6554 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6555 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6556 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6557 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6559 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6560 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6561 | |
| 6562 | rv = callback.WaitForResult(); |
| 6563 | EXPECT_EQ(OK, rv); |
| 6564 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6565 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6566 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6567 | |
| 6568 | EXPECT_EQ(302, response->headers->response_code()); |
| 6569 | std::string url; |
| 6570 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6571 | EXPECT_EQ("http://login.example.com/", url); |
| 6572 | } |
| 6573 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6574 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6575 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6576 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6577 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6578 | ProxyService::CreateFixed("https://proxy:70")); |
| 6579 | |
| 6580 | HttpRequestInfo request; |
| 6581 | request.method = "GET"; |
| 6582 | request.url = GURL("https://www.google.com/"); |
| 6583 | request.load_flags = 0; |
| 6584 | |
| 6585 | MockWrite data_writes[] = { |
| 6586 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 6587 | "Host: www.google.com\r\n" |
| 6588 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6589 | }; |
| 6590 | |
| 6591 | MockRead data_reads[] = { |
| 6592 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6593 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6594 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6595 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6596 | }; |
| 6597 | |
| 6598 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6599 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6600 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6601 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6605 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6606 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6607 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6608 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6611 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6612 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6613 | |
| 6614 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6615 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6616 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6617 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6618 | } |
| 6619 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6620 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6621 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6622 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6623 | session_deps_.proxy_service.reset( |
| 6624 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6625 | |
| 6626 | HttpRequestInfo request; |
| 6627 | request.method = "GET"; |
| 6628 | request.url = GURL("https://www.google.com/"); |
| 6629 | request.load_flags = 0; |
| 6630 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6631 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
| 6632 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6633 | scoped_ptr<SpdyFrame> rst( |
| 6634 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6635 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6636 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6637 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6638 | }; |
| 6639 | |
| 6640 | static const char* const kExtraHeaders[] = { |
| 6641 | "location", |
| 6642 | "http://login.example.com/", |
| 6643 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6644 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6645 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6646 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6647 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6648 | spdy_util_.ConstructSpdyBodyFrame( |
| 6649 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6650 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6651 | CreateMockRead(*resp.get(), 1, SYNCHRONOUS), |
| 6652 | CreateMockRead(*body.get(), 2, SYNCHRONOUS), |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6653 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6654 | }; |
| 6655 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6656 | DelayedSocketData data( |
| 6657 | 1, // wait for one write to finish before reading. |
| 6658 | data_reads, arraysize(data_reads), |
| 6659 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6660 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6661 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6662 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6663 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6666 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6667 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6668 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6669 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6670 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6672 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6673 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6674 | |
| 6675 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6676 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6677 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6678 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6679 | } |
| 6680 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6681 | // Test the request-challenge-retry sequence for basic auth, through |
| 6682 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6683 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6684 | HttpRequestInfo request; |
| 6685 | request.method = "GET"; |
| 6686 | request.url = GURL("https://www.google.com/"); |
| 6687 | // when the no authentication data flag is set. |
| 6688 | request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 6689 | |
| 6690 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6691 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6692 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6693 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6694 | session_deps_.net_log = log.bound().net_log(); |
| 6695 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6696 | |
| 6697 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6698 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
| 6699 | NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6700 | scoped_ptr<SpdyFrame> rst( |
| 6701 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6702 | |
| 6703 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6704 | // be issuing -- the final header line contains the credentials. |
| 6705 | const char* const kAuthCredentials[] = { |
| 6706 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6707 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6708 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6709 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
| 6710 | HostPortPair("www.google.com", 443))); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6711 | // fetch https://www.google.com/ via HTTP |
| 6712 | const char get[] = "GET / HTTP/1.1\r\n" |
| 6713 | "Host: www.google.com\r\n" |
| 6714 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6715 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6716 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6717 | |
| 6718 | MockWrite spdy_writes[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6719 | CreateMockWrite(*req, 1, ASYNC), |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 6720 | CreateMockWrite(*rst, 4, ASYNC), |
| 6721 | CreateMockWrite(*connect2, 5), |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6722 | CreateMockWrite(*wrapped_get, 8), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6723 | }; |
| 6724 | |
| 6725 | // The proxy responds to the connect with a 407, using a persistent |
| 6726 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6727 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6728 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6729 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6730 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6731 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6732 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6733 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6734 | scoped_ptr<SpdyFrame> conn_resp( |
| 6735 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6736 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6737 | "Content-Length: 5\r\n\r\n"; |
| 6738 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6739 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6740 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6741 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6742 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6743 | MockRead spdy_reads[] = { |
[email protected] | 3d7c43f | 2012-07-10 21:26:20 | [diff] [blame] | 6744 | CreateMockRead(*conn_auth_resp, 2, ASYNC), |
| 6745 | CreateMockRead(*conn_resp, 6, ASYNC), |
| 6746 | CreateMockRead(*wrapped_get_resp, 9, ASYNC), |
| 6747 | CreateMockRead(*wrapped_body, 10, ASYNC), |
| 6748 | MockRead(ASYNC, OK, 11), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6749 | }; |
| 6750 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6751 | OrderedSocketData spdy_data( |
| 6752 | spdy_reads, arraysize(spdy_reads), |
| 6753 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6754 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6755 | // Negotiate SPDY to the proxy |
| 6756 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6757 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6759 | // Vanilla SSL to the server |
| 6760 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6762 | |
| 6763 | TestCompletionCallback callback1; |
| 6764 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6765 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6766 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6767 | |
| 6768 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6769 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6770 | |
| 6771 | rv = callback1.WaitForResult(); |
| 6772 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 6773 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6774 | log.GetEntries(&entries); |
| 6775 | size_t pos = ExpectLogContainsSomewhere( |
| 6776 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6777 | NetLog::PHASE_NONE); |
| 6778 | ExpectLogContainsSomewhere( |
| 6779 | entries, pos, |
| 6780 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6781 | NetLog::PHASE_NONE); |
| 6782 | |
| 6783 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6784 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6785 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6786 | EXPECT_EQ(407, response->headers->response_code()); |
| 6787 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6788 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6789 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6790 | |
| 6791 | TestCompletionCallback callback2; |
| 6792 | |
| 6793 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6794 | callback2.callback()); |
| 6795 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6796 | |
| 6797 | rv = callback2.WaitForResult(); |
| 6798 | EXPECT_EQ(OK, rv); |
| 6799 | |
| 6800 | response = trans->GetResponseInfo(); |
| 6801 | ASSERT_TRUE(response != NULL); |
| 6802 | |
| 6803 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6804 | EXPECT_EQ(200, response->headers->response_code()); |
| 6805 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6806 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6807 | |
| 6808 | // The password prompt info should not be set. |
| 6809 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6810 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6811 | LoadTimingInfo load_timing_info; |
| 6812 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6813 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6814 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6815 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6816 | trans.reset(); |
| 6817 | session->CloseAllConnections(); |
| 6818 | } |
| 6819 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6820 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6821 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6822 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6823 | HttpRequestInfo request; |
| 6824 | HttpRequestInfo push_request; |
| 6825 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6826 | request.method = "GET"; |
| 6827 | request.url = GURL("http://www.google.com/"); |
| 6828 | push_request.method = "GET"; |
| 6829 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6830 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6831 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6832 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6833 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6834 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6835 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6836 | |
| 6837 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6838 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6839 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6840 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6841 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6842 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6843 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6844 | |
| 6845 | MockWrite spdy_writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6846 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6847 | }; |
| 6848 | |
| 6849 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6850 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6851 | |
| 6852 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6853 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6854 | |
| 6855 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6856 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6857 | 0, |
| 6858 | 2, |
| 6859 | 1, |
| 6860 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6861 | const char kPushedData[] = "pushed"; |
| 6862 | scoped_ptr<SpdyFrame> stream2_body( |
| 6863 | spdy_util_.ConstructSpdyBodyFrame( |
| 6864 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6865 | |
| 6866 | MockRead spdy_reads[] = { |
| 6867 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6868 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6869 | CreateMockRead(*stream1_body, 4, ASYNC), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6870 | CreateMockRead(*stream2_body, 5, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6871 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6872 | }; |
| 6873 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6874 | OrderedSocketData spdy_data( |
| 6875 | spdy_reads, arraysize(spdy_reads), |
| 6876 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6877 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6878 | // Negotiate SPDY to the proxy |
| 6879 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6880 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6882 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6883 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6884 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6885 | TestCompletionCallback callback; |
| 6886 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6887 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6888 | |
| 6889 | rv = callback.WaitForResult(); |
| 6890 | EXPECT_EQ(OK, rv); |
| 6891 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6892 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6893 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6894 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6895 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6897 | |
| 6898 | rv = callback.WaitForResult(); |
| 6899 | EXPECT_EQ(OK, rv); |
| 6900 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6901 | |
| 6902 | ASSERT_TRUE(response != NULL); |
| 6903 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6904 | |
| 6905 | EXPECT_EQ(200, response->headers->response_code()); |
| 6906 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6907 | |
| 6908 | std::string response_data; |
| 6909 | rv = ReadTransaction(trans.get(), &response_data); |
| 6910 | EXPECT_EQ(OK, rv); |
| 6911 | EXPECT_EQ("hello!", response_data); |
| 6912 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6913 | LoadTimingInfo load_timing_info; |
| 6914 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6915 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6916 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6917 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6918 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6919 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6920 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6921 | |
| 6922 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6923 | EXPECT_EQ(OK, rv); |
| 6924 | EXPECT_EQ("pushed", response_data); |
| 6925 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6926 | LoadTimingInfo push_load_timing_info; |
| 6927 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6928 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6929 | // The transactions should share a socket ID, despite being for different |
| 6930 | // origins. |
| 6931 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6932 | push_load_timing_info.socket_log_id); |
| 6933 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6934 | trans.reset(); |
| 6935 | push_trans.reset(); |
| 6936 | session->CloseAllConnections(); |
| 6937 | } |
| 6938 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6939 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6940 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6941 | HttpRequestInfo request; |
| 6942 | |
| 6943 | request.method = "GET"; |
| 6944 | request.url = GURL("http://www.google.com/"); |
| 6945 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6946 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6947 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6948 | ProxyService::CreateFixed("https://myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 6949 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6950 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6951 | |
| 6952 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6953 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6954 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6955 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6956 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6957 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6958 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6959 | |
| 6960 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6961 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6962 | |
| 6963 | MockWrite spdy_writes[] = { |
| 6964 | CreateMockWrite(*stream1_syn, 1, ASYNC), |
| 6965 | CreateMockWrite(*push_rst, 4), |
| 6966 | }; |
| 6967 | |
| 6968 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6969 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6970 | |
| 6971 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6972 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6973 | |
| 6974 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6975 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6976 | 0, |
| 6977 | 2, |
| 6978 | 1, |
| 6979 | "https://www.another-origin.com/foo.dat")); |
| 6980 | |
| 6981 | MockRead spdy_reads[] = { |
| 6982 | CreateMockRead(*stream1_reply, 2, ASYNC), |
| 6983 | CreateMockRead(*stream2_syn, 3, ASYNC), |
| 6984 | CreateMockRead(*stream1_body, 5, ASYNC), |
| 6985 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 6986 | }; |
| 6987 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 6988 | OrderedSocketData spdy_data( |
| 6989 | spdy_reads, arraysize(spdy_reads), |
| 6990 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6991 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6992 | // Negotiate SPDY to the proxy |
| 6993 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6994 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6996 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6997 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6998 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6999 | TestCompletionCallback callback; |
| 7000 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7001 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7002 | |
| 7003 | rv = callback.WaitForResult(); |
| 7004 | EXPECT_EQ(OK, rv); |
| 7005 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7006 | |
| 7007 | ASSERT_TRUE(response != NULL); |
| 7008 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7009 | |
| 7010 | EXPECT_EQ(200, response->headers->response_code()); |
| 7011 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7012 | |
| 7013 | std::string response_data; |
| 7014 | rv = ReadTransaction(trans.get(), &response_data); |
| 7015 | EXPECT_EQ(OK, rv); |
| 7016 | EXPECT_EQ("hello!", response_data); |
| 7017 | |
| 7018 | trans.reset(); |
| 7019 | session->CloseAllConnections(); |
| 7020 | } |
| 7021 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7022 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7023 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7024 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7025 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7026 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7027 | |
| 7028 | HttpRequestInfo request; |
| 7029 | request.method = "GET"; |
| 7030 | request.url = GURL("https://www.google.com/"); |
| 7031 | request.load_flags = 0; |
| 7032 | |
| 7033 | // Attempt to fetch the URL from a server with a bad cert |
| 7034 | MockWrite bad_cert_writes[] = { |
| 7035 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 7036 | "Host: www.google.com\r\n" |
| 7037 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7038 | }; |
| 7039 | |
| 7040 | MockRead bad_cert_reads[] = { |
| 7041 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7042 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7043 | }; |
| 7044 | |
| 7045 | // Attempt to fetch the URL with a good cert |
| 7046 | MockWrite good_data_writes[] = { |
| 7047 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 7048 | "Host: www.google.com\r\n" |
| 7049 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7050 | MockWrite("GET / HTTP/1.1\r\n" |
| 7051 | "Host: www.google.com\r\n" |
| 7052 | "Connection: keep-alive\r\n\r\n"), |
| 7053 | }; |
| 7054 | |
| 7055 | MockRead good_cert_reads[] = { |
| 7056 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7057 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7058 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7059 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7060 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7061 | }; |
| 7062 | |
| 7063 | StaticSocketDataProvider ssl_bad_certificate( |
| 7064 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7065 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7066 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7067 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7068 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7069 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7070 | |
| 7071 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7073 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7075 | |
| 7076 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7078 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7081 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7082 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7083 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7084 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7085 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7087 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7089 | |
| 7090 | rv = callback.WaitForResult(); |
| 7091 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7093 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7094 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7095 | |
| 7096 | rv = callback.WaitForResult(); |
| 7097 | EXPECT_EQ(OK, rv); |
| 7098 | |
| 7099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7100 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7101 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7102 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7103 | } |
| 7104 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7105 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7106 | HttpRequestInfo request; |
| 7107 | request.method = "GET"; |
| 7108 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7109 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7110 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7111 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7112 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7113 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7114 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7115 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7116 | MockWrite data_writes[] = { |
| 7117 | MockWrite("GET / HTTP/1.1\r\n" |
| 7118 | "Host: www.google.com\r\n" |
| 7119 | "Connection: keep-alive\r\n" |
| 7120 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 7121 | }; |
| 7122 | |
| 7123 | // Lastly, the server responds with the actual content. |
| 7124 | MockRead data_reads[] = { |
| 7125 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7126 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7127 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7128 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7129 | }; |
| 7130 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7131 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7132 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7135 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7137 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7138 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7139 | |
| 7140 | rv = callback.WaitForResult(); |
| 7141 | EXPECT_EQ(OK, rv); |
| 7142 | } |
| 7143 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7144 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7145 | HttpRequestInfo request; |
| 7146 | request.method = "GET"; |
| 7147 | request.url = GURL("https://www.google.com/"); |
| 7148 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7149 | "Chromium Ultra Awesome X Edition"); |
| 7150 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7151 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7152 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7153 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7154 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7155 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7156 | MockWrite data_writes[] = { |
| 7157 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 7158 | "Host: www.google.com\r\n" |
| 7159 | "Proxy-Connection: keep-alive\r\n" |
| 7160 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
| 7161 | }; |
| 7162 | MockRead data_reads[] = { |
| 7163 | // Return an error, so the transaction stops here (this test isn't |
| 7164 | // interested in the rest). |
| 7165 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7166 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7167 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7168 | }; |
| 7169 | |
| 7170 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7171 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7172 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7174 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7176 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7177 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7178 | |
| 7179 | rv = callback.WaitForResult(); |
| 7180 | EXPECT_EQ(OK, rv); |
| 7181 | } |
| 7182 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7183 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7184 | HttpRequestInfo request; |
| 7185 | request.method = "GET"; |
| 7186 | request.url = GURL("http://www.google.com/"); |
| 7187 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7188 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7189 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7190 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7191 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7192 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7194 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7195 | MockWrite data_writes[] = { |
| 7196 | MockWrite("GET / HTTP/1.1\r\n" |
| 7197 | "Host: www.google.com\r\n" |
| 7198 | "Connection: keep-alive\r\n" |
| 7199 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
| 7200 | }; |
| 7201 | |
| 7202 | // Lastly, the server responds with the actual content. |
| 7203 | MockRead data_reads[] = { |
| 7204 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7205 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7206 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7207 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7208 | }; |
| 7209 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7210 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7211 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7212 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7214 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7216 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7217 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7218 | |
| 7219 | rv = callback.WaitForResult(); |
| 7220 | EXPECT_EQ(OK, rv); |
| 7221 | } |
| 7222 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7223 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7224 | HttpRequestInfo request; |
| 7225 | request.method = "POST"; |
| 7226 | request.url = GURL("http://www.google.com/"); |
| 7227 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7229 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7231 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7232 | MockWrite data_writes[] = { |
| 7233 | MockWrite("POST / HTTP/1.1\r\n" |
| 7234 | "Host: www.google.com\r\n" |
| 7235 | "Connection: keep-alive\r\n" |
| 7236 | "Content-Length: 0\r\n\r\n"), |
| 7237 | }; |
| 7238 | |
| 7239 | // Lastly, the server responds with the actual content. |
| 7240 | MockRead data_reads[] = { |
| 7241 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7242 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7243 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7244 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7245 | }; |
| 7246 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7247 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7248 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7251 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7253 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7255 | |
| 7256 | rv = callback.WaitForResult(); |
| 7257 | EXPECT_EQ(OK, rv); |
| 7258 | } |
| 7259 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7260 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7261 | HttpRequestInfo request; |
| 7262 | request.method = "PUT"; |
| 7263 | request.url = GURL("http://www.google.com/"); |
| 7264 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7265 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7266 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7267 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7268 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7269 | MockWrite data_writes[] = { |
| 7270 | MockWrite("PUT / HTTP/1.1\r\n" |
| 7271 | "Host: www.google.com\r\n" |
| 7272 | "Connection: keep-alive\r\n" |
| 7273 | "Content-Length: 0\r\n\r\n"), |
| 7274 | }; |
| 7275 | |
| 7276 | // Lastly, the server responds with the actual content. |
| 7277 | MockRead data_reads[] = { |
| 7278 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7279 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7280 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7281 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7282 | }; |
| 7283 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7284 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7285 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7288 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7290 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7292 | |
| 7293 | rv = callback.WaitForResult(); |
| 7294 | EXPECT_EQ(OK, rv); |
| 7295 | } |
| 7296 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7297 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7298 | HttpRequestInfo request; |
| 7299 | request.method = "HEAD"; |
| 7300 | request.url = GURL("http://www.google.com/"); |
| 7301 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7302 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7303 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7304 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7305 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7306 | MockWrite data_writes[] = { |
| 7307 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7308 | "Host: www.google.com\r\n" |
| 7309 | "Connection: keep-alive\r\n" |
| 7310 | "Content-Length: 0\r\n\r\n"), |
| 7311 | }; |
| 7312 | |
| 7313 | // Lastly, the server responds with the actual content. |
| 7314 | MockRead data_reads[] = { |
| 7315 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7316 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7317 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7318 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7319 | }; |
| 7320 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7321 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7322 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7323 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7324 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7325 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7327 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7329 | |
| 7330 | rv = callback.WaitForResult(); |
| 7331 | EXPECT_EQ(OK, rv); |
| 7332 | } |
| 7333 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7334 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7335 | HttpRequestInfo request; |
| 7336 | request.method = "GET"; |
| 7337 | request.url = GURL("http://www.google.com/"); |
| 7338 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7339 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7340 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7341 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7342 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7343 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7344 | MockWrite data_writes[] = { |
| 7345 | MockWrite("GET / HTTP/1.1\r\n" |
| 7346 | "Host: www.google.com\r\n" |
| 7347 | "Connection: keep-alive\r\n" |
| 7348 | "Pragma: no-cache\r\n" |
| 7349 | "Cache-Control: no-cache\r\n\r\n"), |
| 7350 | }; |
| 7351 | |
| 7352 | // Lastly, the server responds with the actual content. |
| 7353 | MockRead data_reads[] = { |
| 7354 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7355 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7356 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7357 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7364 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7366 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7367 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7368 | |
| 7369 | rv = callback.WaitForResult(); |
| 7370 | EXPECT_EQ(OK, rv); |
| 7371 | } |
| 7372 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7373 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7374 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7375 | HttpRequestInfo request; |
| 7376 | request.method = "GET"; |
| 7377 | request.url = GURL("http://www.google.com/"); |
| 7378 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7379 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7380 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7381 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7382 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7383 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7384 | MockWrite data_writes[] = { |
| 7385 | MockWrite("GET / HTTP/1.1\r\n" |
| 7386 | "Host: www.google.com\r\n" |
| 7387 | "Connection: keep-alive\r\n" |
| 7388 | "Cache-Control: max-age=0\r\n\r\n"), |
| 7389 | }; |
| 7390 | |
| 7391 | // Lastly, the server responds with the actual content. |
| 7392 | MockRead data_reads[] = { |
| 7393 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7394 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7395 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7396 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7397 | }; |
| 7398 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7399 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7400 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7403 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7405 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7406 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7407 | |
| 7408 | rv = callback.WaitForResult(); |
| 7409 | EXPECT_EQ(OK, rv); |
| 7410 | } |
| 7411 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7412 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7413 | HttpRequestInfo request; |
| 7414 | request.method = "GET"; |
| 7415 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7416 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7417 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7418 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7419 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7420 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7421 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7422 | MockWrite data_writes[] = { |
| 7423 | MockWrite("GET / HTTP/1.1\r\n" |
| 7424 | "Host: www.google.com\r\n" |
| 7425 | "Connection: keep-alive\r\n" |
| 7426 | "FooHeader: Bar\r\n\r\n"), |
| 7427 | }; |
| 7428 | |
| 7429 | // Lastly, the server responds with the actual content. |
| 7430 | MockRead data_reads[] = { |
| 7431 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7432 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7433 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7434 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7435 | }; |
| 7436 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7437 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7438 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7439 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7441 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7445 | |
| 7446 | rv = callback.WaitForResult(); |
| 7447 | EXPECT_EQ(OK, rv); |
| 7448 | } |
| 7449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7450 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7451 | HttpRequestInfo request; |
| 7452 | request.method = "GET"; |
| 7453 | request.url = GURL("http://www.google.com/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7454 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7455 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7456 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7457 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7458 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7459 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7460 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7461 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7462 | MockWrite data_writes[] = { |
| 7463 | MockWrite("GET / HTTP/1.1\r\n" |
| 7464 | "Host: www.google.com\r\n" |
| 7465 | "Connection: keep-alive\r\n" |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7466 | "referer: www.foo.com\r\n" |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7467 | "hEllo: Kitty\r\n" |
| 7468 | "FoO: bar\r\n\r\n"), |
| 7469 | }; |
| 7470 | |
| 7471 | // Lastly, the server responds with the actual content. |
| 7472 | MockRead data_reads[] = { |
| 7473 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7474 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7475 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7476 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7477 | }; |
| 7478 | |
| 7479 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7480 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7481 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7483 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7484 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7485 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7486 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7487 | |
| 7488 | rv = callback.WaitForResult(); |
| 7489 | EXPECT_EQ(OK, rv); |
| 7490 | } |
| 7491 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7492 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7493 | HttpRequestInfo request; |
| 7494 | request.method = "GET"; |
| 7495 | request.url = GURL("http://www.google.com/"); |
| 7496 | request.load_flags = 0; |
| 7497 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7498 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7499 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7500 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7501 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7502 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7503 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7504 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7505 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7506 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7507 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7508 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7509 | |
| 7510 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7511 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7512 | MockWrite("GET / HTTP/1.1\r\n" |
| 7513 | "Host: www.google.com\r\n" |
| 7514 | "Connection: keep-alive\r\n\r\n") |
| 7515 | }; |
| 7516 | |
| 7517 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7518 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7519 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7520 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7521 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7522 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7523 | }; |
| 7524 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7525 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7526 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7527 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7528 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7529 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7531 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7532 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7533 | |
| 7534 | rv = callback.WaitForResult(); |
| 7535 | EXPECT_EQ(OK, rv); |
| 7536 | |
| 7537 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7538 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7539 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7540 | LoadTimingInfo load_timing_info; |
| 7541 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7542 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7543 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7544 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7545 | std::string response_text; |
| 7546 | rv = ReadTransaction(trans.get(), &response_text); |
| 7547 | EXPECT_EQ(OK, rv); |
| 7548 | EXPECT_EQ("Payload", response_text); |
| 7549 | } |
| 7550 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7551 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7552 | HttpRequestInfo request; |
| 7553 | request.method = "GET"; |
| 7554 | request.url = GURL("https://www.google.com/"); |
| 7555 | request.load_flags = 0; |
| 7556 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7557 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7558 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
| 7559 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7560 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7561 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7562 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7563 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7564 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7565 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7566 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7567 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7568 | |
| 7569 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7570 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7571 | arraysize(write_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7572 | MockWrite("GET / HTTP/1.1\r\n" |
| 7573 | "Host: www.google.com\r\n" |
| 7574 | "Connection: keep-alive\r\n\r\n") |
| 7575 | }; |
| 7576 | |
| 7577 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7578 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7579 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7580 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7581 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7582 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7583 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7584 | }; |
| 7585 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7586 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7587 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7588 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7589 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7590 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7591 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7593 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7595 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7596 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7597 | |
| 7598 | rv = callback.WaitForResult(); |
| 7599 | EXPECT_EQ(OK, rv); |
| 7600 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7601 | LoadTimingInfo load_timing_info; |
| 7602 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7603 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7604 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7605 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7606 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7607 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7608 | |
| 7609 | std::string response_text; |
| 7610 | rv = ReadTransaction(trans.get(), &response_text); |
| 7611 | EXPECT_EQ(OK, rv); |
| 7612 | EXPECT_EQ("Payload", response_text); |
| 7613 | } |
| 7614 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7615 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7616 | HttpRequestInfo request; |
| 7617 | request.method = "GET"; |
| 7618 | request.url = GURL("http://www.google.com/"); |
| 7619 | request.load_flags = 0; |
| 7620 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7621 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7622 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
| 7623 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7624 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7625 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7626 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7627 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7629 | |
| 7630 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7631 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7632 | |
| 7633 | MockWrite data_writes[] = { |
| 7634 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7635 | MockWrite("GET / HTTP/1.1\r\n" |
| 7636 | "Host: www.google.com\r\n" |
| 7637 | "Connection: keep-alive\r\n\r\n") |
| 7638 | }; |
| 7639 | |
| 7640 | MockRead data_reads[] = { |
| 7641 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7642 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7643 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7644 | MockRead("Payload"), |
| 7645 | MockRead(SYNCHRONOUS, OK) |
| 7646 | }; |
| 7647 | |
| 7648 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7649 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7650 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7651 | |
| 7652 | TestCompletionCallback callback; |
| 7653 | |
| 7654 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7655 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7656 | |
| 7657 | rv = callback.WaitForResult(); |
| 7658 | EXPECT_EQ(OK, rv); |
| 7659 | |
| 7660 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7661 | ASSERT_TRUE(response != NULL); |
| 7662 | |
| 7663 | LoadTimingInfo load_timing_info; |
| 7664 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7665 | TestLoadTimingNotReused(load_timing_info, |
| 7666 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7667 | |
| 7668 | std::string response_text; |
| 7669 | rv = ReadTransaction(trans.get(), &response_text); |
| 7670 | EXPECT_EQ(OK, rv); |
| 7671 | EXPECT_EQ("Payload", response_text); |
| 7672 | } |
| 7673 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7674 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7675 | HttpRequestInfo request; |
| 7676 | request.method = "GET"; |
| 7677 | request.url = GURL("http://www.google.com/"); |
| 7678 | request.load_flags = 0; |
| 7679 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7680 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7681 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7682 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7683 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7684 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7685 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7686 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7688 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7689 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7690 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7691 | const char kSOCKS5OkRequest[] = { |
| 7692 | 0x05, // Version |
| 7693 | 0x01, // Command (CONNECT) |
| 7694 | 0x00, // Reserved. |
| 7695 | 0x03, // Address type (DOMAINNAME). |
| 7696 | 0x0E, // Length of domain (14) |
| 7697 | // Domain string: |
| 7698 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7699 | 0x00, 0x50, // 16-bit port (80) |
| 7700 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7701 | const char kSOCKS5OkResponse[] = |
| 7702 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7703 | |
| 7704 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7705 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7706 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7707 | MockWrite("GET / HTTP/1.1\r\n" |
| 7708 | "Host: www.google.com\r\n" |
| 7709 | "Connection: keep-alive\r\n\r\n") |
| 7710 | }; |
| 7711 | |
| 7712 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7713 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7714 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7715 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7716 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7717 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7718 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7719 | }; |
| 7720 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7721 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7722 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7723 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7725 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7727 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7728 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7729 | |
| 7730 | rv = callback.WaitForResult(); |
| 7731 | EXPECT_EQ(OK, rv); |
| 7732 | |
| 7733 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7734 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7735 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7736 | LoadTimingInfo load_timing_info; |
| 7737 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7738 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7739 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7740 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7741 | std::string response_text; |
| 7742 | rv = ReadTransaction(trans.get(), &response_text); |
| 7743 | EXPECT_EQ(OK, rv); |
| 7744 | EXPECT_EQ("Payload", response_text); |
| 7745 | } |
| 7746 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7747 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7748 | HttpRequestInfo request; |
| 7749 | request.method = "GET"; |
| 7750 | request.url = GURL("https://www.google.com/"); |
| 7751 | request.load_flags = 0; |
| 7752 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7753 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7754 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
| 7755 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7756 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7757 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7758 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7759 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7761 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7762 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7763 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7764 | const unsigned char kSOCKS5OkRequest[] = { |
| 7765 | 0x05, // Version |
| 7766 | 0x01, // Command (CONNECT) |
| 7767 | 0x00, // Reserved. |
| 7768 | 0x03, // Address type (DOMAINNAME). |
| 7769 | 0x0E, // Length of domain (14) |
| 7770 | // Domain string: |
| 7771 | 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm', |
| 7772 | 0x01, 0xBB, // 16-bit port (443) |
| 7773 | }; |
| 7774 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7775 | const char kSOCKS5OkResponse[] = |
| 7776 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7777 | |
| 7778 | MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7779 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7780 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7781 | arraysize(kSOCKS5OkRequest)), |
| 7782 | MockWrite("GET / HTTP/1.1\r\n" |
| 7783 | "Host: www.google.com\r\n" |
| 7784 | "Connection: keep-alive\r\n\r\n") |
| 7785 | }; |
| 7786 | |
| 7787 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7788 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7789 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7790 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7791 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7792 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7793 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7794 | }; |
| 7795 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7796 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7797 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7798 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7799 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7800 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7803 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7805 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7806 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7807 | |
| 7808 | rv = callback.WaitForResult(); |
| 7809 | EXPECT_EQ(OK, rv); |
| 7810 | |
| 7811 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7812 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7813 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7814 | LoadTimingInfo load_timing_info; |
| 7815 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7816 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7817 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7818 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7819 | std::string response_text; |
| 7820 | rv = ReadTransaction(trans.get(), &response_text); |
| 7821 | EXPECT_EQ(OK, rv); |
| 7822 | EXPECT_EQ("Payload", response_text); |
| 7823 | } |
| 7824 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7825 | namespace { |
| 7826 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7827 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7828 | |
| 7829 | struct GroupNameTest { |
| 7830 | std::string proxy_server; |
| 7831 | std::string url; |
| 7832 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7833 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7834 | }; |
| 7835 | |
| 7836 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7837 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7838 | SpdySessionDependencies* session_deps_) { |
| 7839 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7840 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7841 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7842 | session->http_server_properties(); |
| 7843 | http_server_properties->SetAlternateProtocol( |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7844 | HostPortPair("host.with.alternate", 80), 443, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 7845 | AlternateProtocolFromNextProto(next_proto), 1.0); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7846 | |
| 7847 | return session; |
| 7848 | } |
| 7849 | |
| 7850 | int GroupNameTransactionHelper( |
| 7851 | const std::string& url, |
| 7852 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7853 | HttpRequestInfo request; |
| 7854 | request.method = "GET"; |
| 7855 | request.url = GURL(url); |
| 7856 | request.load_flags = 0; |
| 7857 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7858 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7859 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7861 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7862 | |
| 7863 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7864 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7865 | } |
| 7866 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7867 | } // namespace |
| 7868 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7869 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7870 | const GroupNameTest tests[] = { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7871 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7872 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7873 | "http://www.google.com/direct", |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7874 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7875 | false, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7876 | }, |
| 7877 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7878 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7879 | "http://[2001:1418:13:1::25]/direct", |
| 7880 | "[2001:1418:13:1::25]:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7881 | false, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7882 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7883 | |
| 7884 | // SSL Tests |
| 7885 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7886 | "", // unused |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7887 | "https://www.google.com/direct_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7888 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7889 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7890 | }, |
| 7891 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7892 | "", // unused |
| 7893 | "https://[2001:1418:13:1::25]/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7894 | "ssl/[2001:1418:13:1::25]:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7895 | true, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7896 | }, |
| 7897 | { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7898 | "", // unused |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7899 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7900 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7901 | true, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7902 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7903 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7904 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7905 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7906 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7907 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7908 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7909 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7910 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7911 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7912 | |
| 7913 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7914 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7915 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7916 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7917 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7918 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7919 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7920 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7921 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7922 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7923 | |
| 7924 | EXPECT_EQ(ERR_IO_PENDING, |
| 7925 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7926 | if (tests[i].ssl) |
| 7927 | EXPECT_EQ(tests[i].expected_group_name, |
| 7928 | ssl_conn_pool->last_group_name_received()); |
| 7929 | else |
| 7930 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7931 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7932 | } |
| 7933 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7934 | } |
| 7935 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7936 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7937 | const GroupNameTest tests[] = { |
| 7938 | { |
| 7939 | "http_proxy", |
| 7940 | "http://www.google.com/http_proxy_normal", |
| 7941 | "www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7942 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7943 | }, |
| 7944 | |
| 7945 | // SSL Tests |
| 7946 | { |
| 7947 | "http_proxy", |
| 7948 | "https://www.google.com/http_connect_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7949 | "ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7950 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7951 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7952 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7953 | { |
| 7954 | "http_proxy", |
| 7955 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 7956 | "ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7957 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 7958 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7959 | |
| 7960 | { |
| 7961 | "http_proxy", |
| 7962 | "ftp://ftp.google.com/http_proxy_normal", |
| 7963 | "ftp/ftp.google.com:21", |
| 7964 | false, |
| 7965 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7966 | }; |
| 7967 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7968 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7969 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7970 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7971 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7972 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7973 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7974 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7975 | |
| 7976 | HttpNetworkSessionPeer peer(session); |
| 7977 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7978 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7979 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7980 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7981 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7982 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7983 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7984 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7985 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7986 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 7987 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7988 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7989 | |
| 7990 | EXPECT_EQ(ERR_IO_PENDING, |
| 7991 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7992 | if (tests[i].ssl) |
| 7993 | EXPECT_EQ(tests[i].expected_group_name, |
| 7994 | ssl_conn_pool->last_group_name_received()); |
| 7995 | else |
| 7996 | EXPECT_EQ(tests[i].expected_group_name, |
| 7997 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7998 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7999 | } |
| 8000 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8001 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8002 | const GroupNameTest tests[] = { |
| 8003 | { |
| 8004 | "socks4://socks_proxy:1080", |
| 8005 | "http://www.google.com/socks4_direct", |
| 8006 | "socks4/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8007 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8008 | }, |
| 8009 | { |
| 8010 | "socks5://socks_proxy:1080", |
| 8011 | "http://www.google.com/socks5_direct", |
| 8012 | "socks5/www.google.com:80", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8013 | false, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8014 | }, |
| 8015 | |
| 8016 | // SSL Tests |
| 8017 | { |
| 8018 | "socks4://socks_proxy:1080", |
| 8019 | "https://www.google.com/socks4_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 8020 | "socks4/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8021 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8022 | }, |
| 8023 | { |
| 8024 | "socks5://socks_proxy:1080", |
| 8025 | "https://www.google.com/socks5_ssl", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 8026 | "socks5/ssl/www.google.com:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8027 | true, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8028 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8029 | |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 8030 | { |
| 8031 | "socks4://socks_proxy:1080", |
| 8032 | "http://host.with.alternate/direct", |
[email protected] | 0e88ad60 | 2010-05-04 23:47:02 | [diff] [blame] | 8033 | "socks4/ssl/host.with.alternate:443", |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8034 | true, |
[email protected] | 9faeded9 | 2010-04-29 20:03:05 | [diff] [blame] | 8035 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8036 | }; |
| 8037 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8038 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8039 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8040 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8041 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8042 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8043 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8044 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8045 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8046 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8047 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8048 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8049 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8050 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8051 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8052 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8053 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8054 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8055 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8056 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8057 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8058 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8059 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8060 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8062 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8063 | EXPECT_EQ(ERR_IO_PENDING, |
| 8064 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8065 | if (tests[i].ssl) |
| 8066 | EXPECT_EQ(tests[i].expected_group_name, |
| 8067 | ssl_conn_pool->last_group_name_received()); |
| 8068 | else |
| 8069 | EXPECT_EQ(tests[i].expected_group_name, |
| 8070 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8071 | } |
| 8072 | } |
| 8073 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8074 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8075 | HttpRequestInfo request; |
| 8076 | request.method = "GET"; |
| 8077 | request.url = GURL("http://www.google.com/"); |
| 8078 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8079 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8080 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8081 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8082 | // This simulates failure resolving all hostnames; that means we will fail |
| 8083 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8084 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8085 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8086 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8087 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8088 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8090 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8092 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8093 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8094 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8095 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8096 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8097 | } |
| 8098 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8099 | // Base test to make sure that when the load flags for a request specify to |
| 8100 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8101 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8102 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8103 | // Issue a request, asking to bypass the cache(s). |
| 8104 | HttpRequestInfo request; |
| 8105 | request.method = "GET"; |
| 8106 | request.load_flags = load_flags; |
| 8107 | request.url = GURL("http://www.google.com/"); |
| 8108 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8109 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8110 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8111 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8112 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8113 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8114 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8115 | |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8116 | // 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] | 8117 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8118 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8119 | int rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 8120 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 8121 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 8122 | &addrlist, |
| 8123 | callback.callback(), |
| 8124 | NULL, |
| 8125 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8126 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8127 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8128 | EXPECT_EQ(OK, rv); |
| 8129 | |
| 8130 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8131 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8132 | rv = session_deps_.host_resolver->Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 8133 | HostResolver::RequestInfo(HostPortPair("www.google.com", 80)), |
| 8134 | DEFAULT_PRIORITY, |
[email protected] | b9823c0 | 2013-08-16 21:24:41 | [diff] [blame] | 8135 | &addrlist, |
| 8136 | callback.callback(), |
| 8137 | NULL, |
| 8138 | BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8139 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8140 | |
| 8141 | // Inject a failure the next time that "www.google.com" is resolved. This way |
| 8142 | // we can tell if the next lookup hit the cache, or the "network". |
| 8143 | // (cache --> success, "network" --> failure). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8144 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8145 | |
| 8146 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8147 | // 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] | 8148 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8149 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8150 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8151 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8152 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8153 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8154 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8155 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8156 | |
| 8157 | // If we bypassed the cache, we would have gotten a failure while resolving |
| 8158 | // "www.google.com". |
| 8159 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8160 | } |
| 8161 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8162 | // There are multiple load flags that should trigger the host cache bypass. |
| 8163 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8164 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8165 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8166 | } |
| 8167 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8168 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8169 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8170 | } |
| 8171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8172 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8173 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8174 | } |
| 8175 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8176 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8177 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8178 | HttpRequestInfo request; |
| 8179 | request.method = "GET"; |
| 8180 | request.url = GURL("http://www.foo.com/"); |
| 8181 | request.load_flags = 0; |
| 8182 | |
| 8183 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8184 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8185 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8186 | StaticSocketDataProvider data(NULL, 0, |
| 8187 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8189 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8191 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8192 | |
| 8193 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8196 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8197 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8198 | |
| 8199 | rv = callback.WaitForResult(); |
| 8200 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8201 | } |
| 8202 | |
| 8203 | // Check that a connection closed after the start of the headers finishes ok. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8204 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8205 | HttpRequestInfo request; |
| 8206 | request.method = "GET"; |
| 8207 | request.url = GURL("http://www.foo.com/"); |
| 8208 | request.load_flags = 0; |
| 8209 | |
| 8210 | MockRead data_reads[] = { |
| 8211 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8212 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8213 | }; |
| 8214 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8215 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8216 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8217 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8218 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8219 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8220 | |
| 8221 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8222 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8224 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8226 | |
| 8227 | rv = callback.WaitForResult(); |
| 8228 | EXPECT_EQ(OK, rv); |
| 8229 | |
| 8230 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8231 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8232 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8233 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8234 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8235 | |
| 8236 | std::string response_data; |
| 8237 | rv = ReadTransaction(trans.get(), &response_data); |
| 8238 | EXPECT_EQ(OK, rv); |
| 8239 | EXPECT_EQ("", response_data); |
| 8240 | } |
| 8241 | |
| 8242 | // Make sure that a dropped connection while draining the body for auth |
| 8243 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8244 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8245 | HttpRequestInfo request; |
| 8246 | request.method = "GET"; |
| 8247 | request.url = GURL("http://www.google.com/"); |
| 8248 | request.load_flags = 0; |
| 8249 | |
| 8250 | MockWrite data_writes1[] = { |
| 8251 | MockWrite("GET / HTTP/1.1\r\n" |
| 8252 | "Host: www.google.com\r\n" |
| 8253 | "Connection: keep-alive\r\n\r\n"), |
| 8254 | }; |
| 8255 | |
| 8256 | MockRead data_reads1[] = { |
| 8257 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8258 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8259 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8260 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8261 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8262 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8263 | }; |
| 8264 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8265 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8266 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8267 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8268 | |
| 8269 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8270 | // be issuing -- the final header line contains the credentials. |
| 8271 | MockWrite data_writes2[] = { |
| 8272 | MockWrite("GET / HTTP/1.1\r\n" |
| 8273 | "Host: www.google.com\r\n" |
| 8274 | "Connection: keep-alive\r\n" |
| 8275 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 8276 | }; |
| 8277 | |
| 8278 | // Lastly, the server responds with the actual content. |
| 8279 | MockRead data_reads2[] = { |
| 8280 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8281 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8282 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8283 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8284 | }; |
| 8285 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8286 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8287 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8288 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8289 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8291 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8292 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8293 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8294 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8296 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8297 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8298 | |
| 8299 | rv = callback1.WaitForResult(); |
| 8300 | EXPECT_EQ(OK, rv); |
| 8301 | |
| 8302 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8303 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8304 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8306 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8308 | rv = trans->RestartWithAuth( |
| 8309 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8311 | |
| 8312 | rv = callback2.WaitForResult(); |
| 8313 | EXPECT_EQ(OK, rv); |
| 8314 | |
| 8315 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8316 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8317 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8318 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8319 | } |
| 8320 | |
| 8321 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8322 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8323 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8324 | |
| 8325 | HttpRequestInfo request; |
| 8326 | request.method = "GET"; |
| 8327 | request.url = GURL("https://www.google.com/"); |
| 8328 | request.load_flags = 0; |
| 8329 | |
| 8330 | MockRead proxy_reads[] = { |
| 8331 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8332 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8333 | }; |
| 8334 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8335 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8336 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8337 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8338 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8341 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8342 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8343 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8344 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8345 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8346 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8347 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8349 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8351 | |
| 8352 | rv = callback.WaitForResult(); |
| 8353 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8354 | } |
| 8355 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8356 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8357 | HttpRequestInfo request; |
| 8358 | request.method = "GET"; |
| 8359 | request.url = GURL("http://www.google.com/"); |
| 8360 | request.load_flags = 0; |
| 8361 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8362 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8363 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8364 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8365 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8366 | MockRead data_reads[] = { |
| 8367 | 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] | 8368 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8369 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8370 | |
| 8371 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8372 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8373 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8374 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8376 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8378 | |
| 8379 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8380 | |
| 8381 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8382 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8383 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8384 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8385 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8386 | |
| 8387 | std::string response_data; |
| 8388 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8389 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8390 | } |
| 8391 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8392 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8393 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8394 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8395 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8396 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8397 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8398 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8399 | ScopedVector<UploadElementReader> element_readers; |
| 8400 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8401 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8402 | temp_file_path, |
| 8403 | 0, |
| 8404 | kuint64max, |
| 8405 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8406 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8407 | |
| 8408 | HttpRequestInfo request; |
| 8409 | request.method = "POST"; |
| 8410 | request.url = GURL("http://www.google.com/upload"); |
| 8411 | request.upload_data_stream = &upload_data_stream; |
| 8412 | request.load_flags = 0; |
| 8413 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8414 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8415 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8416 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8417 | |
| 8418 | MockRead data_reads[] = { |
| 8419 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8420 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8422 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8423 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8426 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8428 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8430 | |
| 8431 | rv = callback.WaitForResult(); |
| 8432 | EXPECT_EQ(OK, rv); |
| 8433 | |
| 8434 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8435 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8436 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8437 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8438 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8439 | |
| 8440 | std::string response_data; |
| 8441 | rv = ReadTransaction(trans.get(), &response_data); |
| 8442 | EXPECT_EQ(OK, rv); |
| 8443 | EXPECT_EQ("hello world", response_data); |
| 8444 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8445 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8446 | } |
| 8447 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8448 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8449 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8450 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8451 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8452 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8453 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8454 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8455 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8456 | ScopedVector<UploadElementReader> element_readers; |
| 8457 | element_readers.push_back( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 8458 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 8459 | temp_file, |
| 8460 | 0, |
| 8461 | kuint64max, |
| 8462 | base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8463 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8464 | |
| 8465 | HttpRequestInfo request; |
| 8466 | request.method = "POST"; |
| 8467 | request.url = GURL("http://www.google.com/upload"); |
| 8468 | request.upload_data_stream = &upload_data_stream; |
| 8469 | request.load_flags = 0; |
| 8470 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8471 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8472 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8473 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8474 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8475 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8476 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8477 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8479 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8481 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8482 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8483 | |
| 8484 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8485 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8486 | |
| 8487 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8488 | EXPECT_FALSE(response); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8489 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8490 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8491 | } |
| 8492 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8493 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8494 | class FakeUploadElementReader : public UploadElementReader { |
| 8495 | public: |
| 8496 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8497 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8498 | |
| 8499 | const CompletionCallback& callback() const { return callback_; } |
| 8500 | |
| 8501 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8502 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8503 | callback_ = callback; |
| 8504 | return ERR_IO_PENDING; |
| 8505 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8506 | uint64 GetContentLength() const override { return 0; } |
| 8507 | uint64 BytesRemaining() const override { return 0; } |
| 8508 | int Read(IOBuffer* buf, |
| 8509 | int buf_length, |
| 8510 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8511 | return ERR_FAILED; |
| 8512 | } |
| 8513 | |
| 8514 | private: |
| 8515 | CompletionCallback callback_; |
| 8516 | }; |
| 8517 | |
| 8518 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8519 | ScopedVector<UploadElementReader> element_readers; |
| 8520 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8521 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8522 | |
| 8523 | HttpRequestInfo request; |
| 8524 | request.method = "POST"; |
| 8525 | request.url = GURL("http://www.google.com/upload"); |
| 8526 | request.upload_data_stream = &upload_data_stream; |
| 8527 | request.load_flags = 0; |
| 8528 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8529 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8530 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8531 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8532 | |
| 8533 | StaticSocketDataProvider data; |
| 8534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8535 | |
| 8536 | TestCompletionCallback callback; |
| 8537 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8539 | base::MessageLoop::current()->RunUntilIdle(); |
| 8540 | |
| 8541 | // Transaction is pending on request body initialization. |
| 8542 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8543 | |
| 8544 | // Return Init()'s result after the transaction gets destroyed. |
| 8545 | trans.reset(); |
| 8546 | fake_reader->callback().Run(OK); // Should not crash. |
| 8547 | } |
| 8548 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8549 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8550 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8551 | |
| 8552 | HttpRequestInfo request; |
| 8553 | request.method = "GET"; |
| 8554 | request.url = GURL("http://www.google.com/"); |
| 8555 | request.load_flags = 0; |
| 8556 | |
| 8557 | // First transaction will request a resource and receive a Basic challenge |
| 8558 | // with realm="first_realm". |
| 8559 | MockWrite data_writes1[] = { |
| 8560 | MockWrite("GET / HTTP/1.1\r\n" |
| 8561 | "Host: www.google.com\r\n" |
| 8562 | "Connection: keep-alive\r\n" |
| 8563 | "\r\n"), |
| 8564 | }; |
| 8565 | MockRead data_reads1[] = { |
| 8566 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8567 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8568 | "\r\n"), |
| 8569 | }; |
| 8570 | |
| 8571 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8572 | // for first_realm. The server will reject and provide a challenge with |
| 8573 | // second_realm. |
| 8574 | MockWrite data_writes2[] = { |
| 8575 | MockWrite("GET / HTTP/1.1\r\n" |
| 8576 | "Host: www.google.com\r\n" |
| 8577 | "Connection: keep-alive\r\n" |
| 8578 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8579 | "\r\n"), |
| 8580 | }; |
| 8581 | MockRead data_reads2[] = { |
| 8582 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8583 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8584 | "\r\n"), |
| 8585 | }; |
| 8586 | |
| 8587 | // This again fails, and goes back to first_realm. Make sure that the |
| 8588 | // entry is removed from cache. |
| 8589 | MockWrite data_writes3[] = { |
| 8590 | MockWrite("GET / HTTP/1.1\r\n" |
| 8591 | "Host: www.google.com\r\n" |
| 8592 | "Connection: keep-alive\r\n" |
| 8593 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8594 | "\r\n"), |
| 8595 | }; |
| 8596 | MockRead data_reads3[] = { |
| 8597 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8598 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8599 | "\r\n"), |
| 8600 | }; |
| 8601 | |
| 8602 | // Try one last time (with the correct password) and get the resource. |
| 8603 | MockWrite data_writes4[] = { |
| 8604 | MockWrite("GET / HTTP/1.1\r\n" |
| 8605 | "Host: www.google.com\r\n" |
| 8606 | "Connection: keep-alive\r\n" |
| 8607 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8608 | "\r\n"), |
| 8609 | }; |
| 8610 | MockRead data_reads4[] = { |
| 8611 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8612 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8613 | "Content-Length: 5\r\n" |
| 8614 | "\r\n" |
| 8615 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8616 | }; |
| 8617 | |
| 8618 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8619 | data_writes1, arraysize(data_writes1)); |
| 8620 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8621 | data_writes2, arraysize(data_writes2)); |
| 8622 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8623 | data_writes3, arraysize(data_writes3)); |
| 8624 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8625 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8626 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8627 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8628 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8629 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8631 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8632 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8633 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8634 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8635 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8636 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8637 | // Issue the first request with Authorize headers. There should be a |
| 8638 | // password prompt for first_realm waiting to be filled in after the |
| 8639 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8640 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8641 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8642 | rv = callback1.WaitForResult(); |
| 8643 | EXPECT_EQ(OK, rv); |
| 8644 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8645 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8646 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8647 | ASSERT_FALSE(challenge == NULL); |
| 8648 | EXPECT_FALSE(challenge->is_proxy); |
| 8649 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8650 | EXPECT_EQ("first_realm", challenge->realm); |
| 8651 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8652 | |
| 8653 | // Issue the second request with an incorrect password. There should be a |
| 8654 | // password prompt for second_realm waiting to be filled in after the |
| 8655 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8656 | TestCompletionCallback callback2; |
| 8657 | rv = trans->RestartWithAuth( |
| 8658 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8659 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8660 | rv = callback2.WaitForResult(); |
| 8661 | EXPECT_EQ(OK, rv); |
| 8662 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8663 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8664 | challenge = response->auth_challenge.get(); |
| 8665 | ASSERT_FALSE(challenge == NULL); |
| 8666 | EXPECT_FALSE(challenge->is_proxy); |
| 8667 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8668 | EXPECT_EQ("second_realm", challenge->realm); |
| 8669 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8670 | |
| 8671 | // Issue the third request with another incorrect password. There should be |
| 8672 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8673 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8674 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8675 | TestCompletionCallback callback3; |
| 8676 | rv = trans->RestartWithAuth( |
| 8677 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8678 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8679 | rv = callback3.WaitForResult(); |
| 8680 | EXPECT_EQ(OK, rv); |
| 8681 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8682 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8683 | challenge = response->auth_challenge.get(); |
| 8684 | ASSERT_FALSE(challenge == NULL); |
| 8685 | EXPECT_FALSE(challenge->is_proxy); |
| 8686 | EXPECT_EQ("www.google.com:80", challenge->challenger.ToString()); |
| 8687 | EXPECT_EQ("first_realm", challenge->realm); |
| 8688 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8689 | |
| 8690 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8691 | TestCompletionCallback callback4; |
| 8692 | rv = trans->RestartWithAuth( |
| 8693 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8695 | rv = callback4.WaitForResult(); |
| 8696 | EXPECT_EQ(OK, rv); |
| 8697 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8698 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8699 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8700 | } |
| 8701 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8702 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8703 | session_deps_.next_protos = SpdyNextProtos(); |
| 8704 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8705 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8706 | std::string alternate_protocol_http_header = |
| 8707 | GetAlternateProtocolHttpHeader(); |
| 8708 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8709 | MockRead data_reads[] = { |
| 8710 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8711 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8712 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8714 | }; |
| 8715 | |
| 8716 | HttpRequestInfo request; |
| 8717 | request.method = "GET"; |
| 8718 | request.url = GURL("http://www.google.com/"); |
| 8719 | request.load_flags = 0; |
| 8720 | |
| 8721 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8722 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8723 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8725 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8726 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8727 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8731 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8733 | |
[email protected] | 2fbaecf2 | 2010-07-22 22:20:35 | [diff] [blame] | 8734 | HostPortPair http_host_port_pair("www.google.com", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8735 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8736 | *session->http_server_properties(); |
bnc | 3c255331 | 2015-02-03 23:12:01 | [diff] [blame] | 8737 | AlternateProtocolInfo alternate = |
| 8738 | http_server_properties.GetAlternateProtocol(http_host_port_pair); |
| 8739 | EXPECT_EQ(alternate.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8740 | |
| 8741 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8742 | |
| 8743 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8744 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8745 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8746 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8747 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8748 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8749 | |
| 8750 | std::string response_data; |
| 8751 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8752 | EXPECT_EQ("hello world", response_data); |
| 8753 | |
bnc | 3c255331 | 2015-02-03 23:12:01 | [diff] [blame] | 8754 | alternate = http_server_properties.GetAlternateProtocol(http_host_port_pair); |
| 8755 | EXPECT_EQ(443, alternate.port); |
| 8756 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), alternate.protocol); |
| 8757 | EXPECT_EQ(1.0, alternate.probability); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8758 | } |
| 8759 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8760 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8761 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8762 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8763 | |
| 8764 | HttpRequestInfo request; |
| 8765 | request.method = "GET"; |
| 8766 | request.url = GURL("http://www.google.com/"); |
| 8767 | request.load_flags = 0; |
| 8768 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8769 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8770 | StaticSocketDataProvider first_data; |
| 8771 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8772 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8773 | |
| 8774 | MockRead data_reads[] = { |
| 8775 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8776 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8777 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8778 | }; |
| 8779 | StaticSocketDataProvider second_data( |
| 8780 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8781 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8782 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8783 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8784 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8785 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8786 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8787 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 8788 | // port 80 (another restricted port). |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8789 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8790 | HostPortPair::FromURL(request.url), |
| 8791 | 666 /* port is ignored by MockConnect anyway */, |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8792 | AlternateProtocolFromNextProto(GetParam()), 1.0); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8793 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8794 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8795 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8796 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8798 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8799 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8800 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8801 | |
| 8802 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8803 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8804 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8805 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8806 | |
| 8807 | std::string response_data; |
| 8808 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8809 | EXPECT_EQ("hello world", response_data); |
| 8810 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 8811 | const AlternateProtocolInfo alternate = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8812 | http_server_properties->GetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8813 | HostPortPair::FromURL(request.url)); |
bnc | 3c255331 | 2015-02-03 23:12:01 | [diff] [blame] | 8814 | EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); |
bnc | cbd55d5f | 2014-11-06 19:50:40 | [diff] [blame] | 8815 | EXPECT_TRUE(alternate.is_broken); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8816 | } |
| 8817 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8818 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8819 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8820 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8821 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8822 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8823 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8824 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8825 | |
| 8826 | HttpRequestInfo restricted_port_request; |
| 8827 | restricted_port_request.method = "GET"; |
| 8828 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8829 | restricted_port_request.load_flags = 0; |
| 8830 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8831 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8832 | StaticSocketDataProvider first_data; |
| 8833 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8834 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8835 | |
| 8836 | MockRead data_reads[] = { |
| 8837 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8838 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8839 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8840 | }; |
| 8841 | StaticSocketDataProvider second_data( |
| 8842 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8843 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8844 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8845 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8846 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8847 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8848 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8849 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8850 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8851 | HostPortPair::FromURL(restricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8852 | kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8853 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8854 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8855 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8856 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8857 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8859 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8860 | &restricted_port_request, |
| 8861 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8863 | // Invalid change to unrestricted port should fail. |
| 8864 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8865 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8866 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8867 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8868 | AlternateProtocolPortRestrictedPermitted) { |
| 8869 | // Ensure that we're allowed to redirect traffic via an alternate |
| 8870 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8871 | // on a restricted port (port < 1024) if we set |
| 8872 | // enable_user_alternate_protocol_ports. |
| 8873 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8874 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8875 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8876 | |
| 8877 | HttpRequestInfo restricted_port_request; |
| 8878 | restricted_port_request.method = "GET"; |
| 8879 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8880 | restricted_port_request.load_flags = 0; |
| 8881 | |
| 8882 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 8883 | StaticSocketDataProvider first_data; |
| 8884 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8885 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8886 | |
| 8887 | MockRead data_reads[] = { |
| 8888 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8889 | MockRead("hello world"), |
| 8890 | MockRead(ASYNC, OK), |
| 8891 | }; |
| 8892 | StaticSocketDataProvider second_data( |
| 8893 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8894 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8895 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8896 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8897 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8898 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8899 | session->http_server_properties(); |
| 8900 | const int kUnrestrictedAlternatePort = 1024; |
| 8901 | http_server_properties->SetAlternateProtocol( |
| 8902 | HostPortPair::FromURL(restricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8903 | kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8904 | 1.0); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8905 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8906 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8907 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8908 | TestCompletionCallback callback; |
| 8909 | |
| 8910 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8911 | &restricted_port_request, |
| 8912 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 8913 | // Change to unrestricted port should succeed. |
| 8914 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8915 | } |
| 8916 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8917 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8918 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8919 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8920 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8921 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8922 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8923 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8924 | |
| 8925 | HttpRequestInfo restricted_port_request; |
| 8926 | restricted_port_request.method = "GET"; |
| 8927 | restricted_port_request.url = GURL("http://www.google.com:1023/"); |
| 8928 | restricted_port_request.load_flags = 0; |
| 8929 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8930 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8931 | StaticSocketDataProvider first_data; |
| 8932 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8933 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8934 | |
| 8935 | MockRead data_reads[] = { |
| 8936 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8937 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8938 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8939 | }; |
| 8940 | StaticSocketDataProvider second_data( |
| 8941 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8942 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8943 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8944 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8945 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8946 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8947 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8948 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8949 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8950 | HostPortPair::FromURL(restricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 8951 | kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 8952 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8953 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8954 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8955 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8956 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8958 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8959 | &restricted_port_request, |
| 8960 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8961 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8962 | // Valid change to restricted port should pass. |
| 8963 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8964 | } |
| 8965 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8966 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8967 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8968 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 8969 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8970 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8971 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8972 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8973 | |
| 8974 | HttpRequestInfo unrestricted_port_request; |
| 8975 | unrestricted_port_request.method = "GET"; |
| 8976 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 8977 | unrestricted_port_request.load_flags = 0; |
| 8978 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 8979 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8980 | StaticSocketDataProvider first_data; |
| 8981 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8982 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8983 | |
| 8984 | MockRead data_reads[] = { |
| 8985 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 8986 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8987 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8988 | }; |
| 8989 | StaticSocketDataProvider second_data( |
| 8990 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8991 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8992 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8993 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8994 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8995 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8996 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8997 | const int kRestrictedAlternatePort = 80; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8998 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 8999 | HostPortPair::FromURL(unrestricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9000 | kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 9001 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9002 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9003 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9004 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9005 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9007 | int rv = trans->Start( |
| 9008 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9009 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9010 | // Valid change to restricted port should pass. |
| 9011 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9012 | } |
| 9013 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9014 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9015 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9016 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9017 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9018 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9019 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9020 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9021 | |
| 9022 | HttpRequestInfo unrestricted_port_request; |
| 9023 | unrestricted_port_request.method = "GET"; |
| 9024 | unrestricted_port_request.url = GURL("http://www.google.com:1024/"); |
| 9025 | unrestricted_port_request.load_flags = 0; |
| 9026 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9027 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9028 | StaticSocketDataProvider first_data; |
| 9029 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9030 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9031 | |
| 9032 | MockRead data_reads[] = { |
| 9033 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9034 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9035 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9036 | }; |
| 9037 | StaticSocketDataProvider second_data( |
| 9038 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9039 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9040 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9041 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9042 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9043 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9044 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9045 | const int kUnrestrictedAlternatePort = 1024; |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9046 | http_server_properties->SetAlternateProtocol( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9047 | HostPortPair::FromURL(unrestricted_port_request.url), |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9048 | kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()), |
| 9049 | 1.0); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9050 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9051 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9052 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9053 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9055 | int rv = trans->Start( |
| 9056 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9058 | // Valid change to an unrestricted port should pass. |
| 9059 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9060 | } |
| 9061 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9062 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9063 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9064 | // protocol to an unsafe port, and that we resume the second |
| 9065 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9066 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9067 | |
| 9068 | HttpRequestInfo request; |
| 9069 | request.method = "GET"; |
| 9070 | request.url = GURL("http://www.google.com/"); |
| 9071 | request.load_flags = 0; |
| 9072 | |
| 9073 | // The alternate protocol request will error out before we attempt to connect, |
| 9074 | // so only the standard HTTP request will try to connect. |
| 9075 | MockRead data_reads[] = { |
| 9076 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9077 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9078 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9079 | }; |
| 9080 | StaticSocketDataProvider data( |
| 9081 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9082 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9083 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9084 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9085 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9086 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9087 | session->http_server_properties(); |
| 9088 | const int kUnsafePort = 7; |
| 9089 | http_server_properties->SetAlternateProtocol( |
bnc | 1102b55 | 2015-01-30 20:11:01 | [diff] [blame] | 9090 | HostPortPair::FromURL(request.url), kUnsafePort, |
| 9091 | AlternateProtocolFromNextProto(GetParam()), 1.0); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9092 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9093 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9094 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9095 | TestCompletionCallback callback; |
| 9096 | |
| 9097 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9098 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9099 | // The HTTP request should succeed. |
| 9100 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9101 | |
| 9102 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9103 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9104 | |
| 9105 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9106 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9107 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9108 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9109 | |
| 9110 | std::string response_data; |
| 9111 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9112 | EXPECT_EQ("hello world", response_data); |
| 9113 | } |
| 9114 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9115 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9116 | session_deps_.use_alternate_protocols = true; |
| 9117 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9118 | |
| 9119 | HttpRequestInfo request; |
| 9120 | request.method = "GET"; |
| 9121 | request.url = GURL("http://www.google.com/"); |
| 9122 | request.load_flags = 0; |
| 9123 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9124 | std::string alternate_protocol_http_header = |
| 9125 | GetAlternateProtocolHttpHeader(); |
| 9126 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9127 | MockRead data_reads[] = { |
| 9128 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9129 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9130 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9131 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9132 | MockRead(ASYNC, OK) |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9133 | }; |
| 9134 | |
| 9135 | StaticSocketDataProvider first_transaction( |
| 9136 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9137 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9138 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9139 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9140 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9142 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9143 | scoped_ptr<SpdyFrame> req( |
| 9144 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9145 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9147 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9148 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9149 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9150 | CreateMockRead(*resp), |
| 9151 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9152 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9153 | }; |
| 9154 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9155 | DelayedSocketData spdy_data( |
| 9156 | 1, // wait for one write to finish before reading. |
| 9157 | spdy_reads, arraysize(spdy_reads), |
| 9158 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9159 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9160 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9161 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9162 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9163 | NULL, 0, NULL, 0); |
| 9164 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9165 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9166 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9167 | &hanging_non_alternate_protocol_socket); |
| 9168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9169 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9170 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9171 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9172 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9173 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9175 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9176 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9177 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9178 | |
| 9179 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9180 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9181 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9182 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9183 | |
| 9184 | std::string response_data; |
| 9185 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9186 | EXPECT_EQ("hello world", response_data); |
| 9187 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9188 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9190 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9191 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9192 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9193 | |
| 9194 | response = trans->GetResponseInfo(); |
| 9195 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9196 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9197 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9198 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9199 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9200 | |
| 9201 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9202 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9203 | } |
| 9204 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9205 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9206 | session_deps_.use_alternate_protocols = true; |
| 9207 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9208 | |
| 9209 | HttpRequestInfo request; |
| 9210 | request.method = "GET"; |
| 9211 | request.url = GURL("http://www.google.com/"); |
| 9212 | request.load_flags = 0; |
| 9213 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9214 | std::string alternate_protocol_http_header = |
| 9215 | GetAlternateProtocolHttpHeader(); |
| 9216 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9217 | MockRead data_reads[] = { |
| 9218 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9219 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9220 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9221 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9222 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9223 | }; |
| 9224 | |
| 9225 | StaticSocketDataProvider first_transaction( |
| 9226 | data_reads, arraysize(data_reads), NULL, 0); |
| 9227 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9228 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9229 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9230 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9231 | StaticSocketDataProvider hanging_socket( |
| 9232 | NULL, 0, NULL, 0); |
| 9233 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9234 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9235 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9236 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9237 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9238 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9239 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9240 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9241 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9242 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9243 | scoped_ptr<SpdyFrame> req1( |
| 9244 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9245 | scoped_ptr<SpdyFrame> req2( |
| 9246 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9247 | MockWrite spdy_writes[] = { |
| 9248 | CreateMockWrite(*req1), |
| 9249 | CreateMockWrite(*req2), |
| 9250 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9251 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9252 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9253 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9254 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9255 | MockRead spdy_reads[] = { |
| 9256 | CreateMockRead(*resp1), |
| 9257 | CreateMockRead(*data1), |
| 9258 | CreateMockRead(*resp2), |
| 9259 | CreateMockRead(*data2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9260 | MockRead(ASYNC, 0, 0), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9261 | }; |
| 9262 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9263 | DelayedSocketData spdy_data( |
| 9264 | 2, // wait for writes to finish before reading. |
| 9265 | spdy_reads, arraysize(spdy_reads), |
| 9266 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9267 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9268 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9269 | |
| 9270 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9271 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9272 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9273 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9274 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9275 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9277 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9278 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9279 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9280 | |
| 9281 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9282 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9283 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9284 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9285 | |
| 9286 | std::string response_data; |
| 9287 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9288 | EXPECT_EQ("hello world", response_data); |
| 9289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9290 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9291 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9292 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9295 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9296 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9297 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9299 | |
| 9300 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9301 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9302 | |
| 9303 | response = trans2.GetResponseInfo(); |
| 9304 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9305 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9306 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9307 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9308 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9309 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9310 | EXPECT_EQ("hello!", response_data); |
| 9311 | |
| 9312 | response = trans3.GetResponseInfo(); |
| 9313 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9314 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9315 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9316 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9317 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9318 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9319 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9320 | } |
| 9321 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9322 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9323 | session_deps_.use_alternate_protocols = true; |
| 9324 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9325 | |
| 9326 | HttpRequestInfo request; |
| 9327 | request.method = "GET"; |
| 9328 | request.url = GURL("http://www.google.com/"); |
| 9329 | request.load_flags = 0; |
| 9330 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9331 | std::string alternate_protocol_http_header = |
| 9332 | GetAlternateProtocolHttpHeader(); |
| 9333 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9334 | MockRead data_reads[] = { |
| 9335 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9336 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9337 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9338 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9339 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9340 | }; |
| 9341 | |
| 9342 | StaticSocketDataProvider first_transaction( |
| 9343 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9344 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9345 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9346 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9347 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9349 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9350 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9351 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9352 | NULL, 0, NULL, 0); |
| 9353 | hanging_alternate_protocol_socket.set_connect_data( |
| 9354 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9355 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9356 | &hanging_alternate_protocol_socket); |
| 9357 | |
| 9358 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9359 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9361 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9362 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9363 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9364 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9365 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9367 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9369 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9370 | |
| 9371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9372 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9373 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9374 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9375 | |
| 9376 | std::string response_data; |
| 9377 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9378 | EXPECT_EQ("hello world", response_data); |
| 9379 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9380 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9382 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9383 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9384 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9385 | |
| 9386 | response = trans->GetResponseInfo(); |
| 9387 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9388 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9389 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9390 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9391 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9392 | |
| 9393 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9394 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9395 | } |
| 9396 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9397 | class CapturingProxyResolver : public ProxyResolver { |
| 9398 | public: |
| 9399 | CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9400 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9401 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9402 | int GetProxyForURL(const GURL& url, |
| 9403 | ProxyInfo* results, |
| 9404 | const CompletionCallback& callback, |
| 9405 | RequestHandle* request, |
| 9406 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9407 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9408 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9409 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9410 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9411 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9412 | } |
| 9413 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9414 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9415 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9416 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9417 | NOTREACHED(); |
| 9418 | return LOAD_STATE_IDLE; |
| 9419 | } |
| 9420 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9421 | void CancelSetPacScript() override { NOTREACHED(); } |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 9422 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9423 | int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&, |
| 9424 | const CompletionCallback& /*callback*/) override { |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9425 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9426 | } |
| 9427 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9428 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9429 | |
| 9430 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9431 | std::vector<GURL> resolved_; |
| 9432 | |
| 9433 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9434 | }; |
| 9435 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9436 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9437 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9438 | session_deps_.use_alternate_protocols = true; |
| 9439 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9440 | |
| 9441 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9442 | proxy_config.set_auto_detect(true); |
| 9443 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9444 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9445 | CapturingProxyResolver* capturing_proxy_resolver = |
| 9446 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9447 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9448 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 9449 | NULL)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9450 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9451 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9452 | |
| 9453 | HttpRequestInfo request; |
| 9454 | request.method = "GET"; |
| 9455 | request.url = GURL("http://www.google.com/"); |
| 9456 | request.load_flags = 0; |
| 9457 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9458 | std::string alternate_protocol_http_header = |
| 9459 | GetAlternateProtocolHttpHeader(); |
| 9460 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9461 | MockRead data_reads[] = { |
| 9462 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9463 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9464 | MockRead("hello world"), |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 9465 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9466 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9467 | }; |
| 9468 | |
| 9469 | StaticSocketDataProvider first_transaction( |
| 9470 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9471 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9472 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9473 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9474 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9476 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9477 | scoped_ptr<SpdyFrame> req( |
| 9478 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9479 | MockWrite spdy_writes[] = { |
| 9480 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 9481 | "Host: www.google.com\r\n" |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9482 | "Proxy-Connection: keep-alive\r\n\r\n"), // 0 |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9483 | CreateMockWrite(*req), // 3 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9484 | }; |
| 9485 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9486 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9487 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9488 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9489 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9490 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9491 | MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1 |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9492 | CreateMockRead(*resp.get(), 4), // 2, 4 |
| 9493 | CreateMockRead(*data.get(), 4), // 5 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9494 | MockRead(ASYNC, 0, 0, 4), // 6 |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9495 | }; |
| 9496 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9497 | OrderedSocketData spdy_data( |
| 9498 | spdy_reads, arraysize(spdy_reads), |
| 9499 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9500 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9501 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9502 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9503 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9504 | NULL, 0, NULL, 0); |
| 9505 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9506 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9507 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9508 | &hanging_non_alternate_protocol_socket); |
| 9509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9510 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9511 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9512 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9513 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9514 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9516 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9517 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9518 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9519 | |
| 9520 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9521 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9522 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9523 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9524 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9525 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9526 | |
| 9527 | std::string response_data; |
| 9528 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9529 | EXPECT_EQ("hello world", response_data); |
| 9530 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9531 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9533 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9534 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9535 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9536 | |
| 9537 | response = trans->GetResponseInfo(); |
| 9538 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9539 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9540 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9541 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9542 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9543 | |
| 9544 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9545 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9546 | ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9547 | EXPECT_EQ("http://www.google.com/", |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9548 | capturing_proxy_resolver->resolved()[0].spec()); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9549 | EXPECT_EQ("https://www.google.com/", |
| 9550 | capturing_proxy_resolver->resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9551 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9552 | LoadTimingInfo load_timing_info; |
| 9553 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9554 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9555 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9556 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9557 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9558 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9559 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9560 | session_deps_.use_alternate_protocols = true; |
| 9561 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9562 | |
| 9563 | HttpRequestInfo request; |
| 9564 | request.method = "GET"; |
| 9565 | request.url = GURL("http://www.google.com/"); |
| 9566 | request.load_flags = 0; |
| 9567 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9568 | std::string alternate_protocol_http_header = |
| 9569 | GetAlternateProtocolHttpHeader(); |
| 9570 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9571 | MockRead data_reads[] = { |
| 9572 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9573 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9574 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9575 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9576 | }; |
| 9577 | |
| 9578 | StaticSocketDataProvider first_transaction( |
| 9579 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9580 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9581 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9582 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9583 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9585 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9586 | scoped_ptr<SpdyFrame> req( |
| 9587 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9588 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9589 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9590 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9591 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9592 | MockRead spdy_reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 9593 | CreateMockRead(*resp), |
| 9594 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9595 | MockRead(ASYNC, 0, 0), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9596 | }; |
| 9597 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 9598 | DelayedSocketData spdy_data( |
| 9599 | 1, // wait for one write to finish before reading. |
| 9600 | spdy_reads, arraysize(spdy_reads), |
| 9601 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9602 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9603 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9604 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9605 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9606 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9607 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9608 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9611 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9612 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9613 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9614 | |
| 9615 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9616 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9617 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9618 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9619 | |
| 9620 | std::string response_data; |
| 9621 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9622 | EXPECT_EQ("hello world", response_data); |
| 9623 | |
| 9624 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9625 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9626 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9627 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9628 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9629 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9630 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9631 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9633 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9634 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9635 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9636 | |
| 9637 | response = trans->GetResponseInfo(); |
| 9638 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9639 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9640 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9641 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9642 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9643 | |
| 9644 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9645 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9646 | } |
| 9647 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9648 | // GenerateAuthToken is a mighty big test. |
| 9649 | // It tests all permutation of GenerateAuthToken behavior: |
| 9650 | // - Synchronous and Asynchronous completion. |
| 9651 | // - OK or error on completion. |
| 9652 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9653 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9654 | // - Non-authenticating and authenticating backend. |
| 9655 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9656 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9657 | // problems generating an auth token for an authenticating proxy, we don't |
| 9658 | // need to test all permutations of the backend server). |
| 9659 | // |
| 9660 | // The test proceeds by going over each of the configuration cases, and |
| 9661 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9662 | // specifies both the configuration for the test as well as the expectations |
| 9663 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9664 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9665 | static const char kServer[] = "http://www.example.com"; |
| 9666 | static const char kSecureServer[] = "https://www.example.com"; |
| 9667 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9668 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9669 | |
| 9670 | enum AuthTiming { |
| 9671 | AUTH_NONE, |
| 9672 | AUTH_SYNC, |
| 9673 | AUTH_ASYNC, |
| 9674 | }; |
| 9675 | |
| 9676 | const MockWrite kGet( |
| 9677 | "GET / HTTP/1.1\r\n" |
| 9678 | "Host: www.example.com\r\n" |
| 9679 | "Connection: keep-alive\r\n\r\n"); |
| 9680 | const MockWrite kGetProxy( |
| 9681 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9682 | "Host: www.example.com\r\n" |
| 9683 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9684 | const MockWrite kGetAuth( |
| 9685 | "GET / HTTP/1.1\r\n" |
| 9686 | "Host: www.example.com\r\n" |
| 9687 | "Connection: keep-alive\r\n" |
| 9688 | "Authorization: auth_token\r\n\r\n"); |
| 9689 | const MockWrite kGetProxyAuth( |
| 9690 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9691 | "Host: www.example.com\r\n" |
| 9692 | "Proxy-Connection: keep-alive\r\n" |
| 9693 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9694 | const MockWrite kGetAuthThroughProxy( |
| 9695 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9696 | "Host: www.example.com\r\n" |
| 9697 | "Proxy-Connection: keep-alive\r\n" |
| 9698 | "Authorization: auth_token\r\n\r\n"); |
| 9699 | const MockWrite kGetAuthWithProxyAuth( |
| 9700 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9701 | "Host: www.example.com\r\n" |
| 9702 | "Proxy-Connection: keep-alive\r\n" |
| 9703 | "Proxy-Authorization: auth_token\r\n" |
| 9704 | "Authorization: auth_token\r\n\r\n"); |
| 9705 | const MockWrite kConnect( |
| 9706 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9707 | "Host: www.example.com\r\n" |
| 9708 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9709 | const MockWrite kConnectProxyAuth( |
| 9710 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 9711 | "Host: www.example.com\r\n" |
| 9712 | "Proxy-Connection: keep-alive\r\n" |
| 9713 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 9714 | |
| 9715 | const MockRead kSuccess( |
| 9716 | "HTTP/1.1 200 OK\r\n" |
| 9717 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9718 | "Content-Length: 3\r\n\r\n" |
| 9719 | "Yes"); |
| 9720 | const MockRead kFailure( |
| 9721 | "Should not be called."); |
| 9722 | const MockRead kServerChallenge( |
| 9723 | "HTTP/1.1 401 Unauthorized\r\n" |
| 9724 | "WWW-Authenticate: Mock realm=server\r\n" |
| 9725 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9726 | "Content-Length: 14\r\n\r\n" |
| 9727 | "Unauthorized\r\n"); |
| 9728 | const MockRead kProxyChallenge( |
| 9729 | "HTTP/1.1 407 Unauthorized\r\n" |
| 9730 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 9731 | "Proxy-Connection: close\r\n" |
| 9732 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 9733 | "Content-Length: 14\r\n\r\n" |
| 9734 | "Unauthorized\r\n"); |
| 9735 | const MockRead kProxyConnected( |
| 9736 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 9737 | |
| 9738 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 9739 | // no constructors, but the C++ compiler on Windows warns about |
| 9740 | // unspecified data in compound literals. So, moved to using constructors, |
| 9741 | // and TestRound's created with the default constructor should not be used. |
| 9742 | struct TestRound { |
| 9743 | TestRound() |
| 9744 | : expected_rv(ERR_UNEXPECTED), |
| 9745 | extra_write(NULL), |
| 9746 | extra_read(NULL) { |
| 9747 | } |
| 9748 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9749 | int expected_rv_arg) |
| 9750 | : write(write_arg), |
| 9751 | read(read_arg), |
| 9752 | expected_rv(expected_rv_arg), |
| 9753 | extra_write(NULL), |
| 9754 | extra_read(NULL) { |
| 9755 | } |
| 9756 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 9757 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9758 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9759 | : write(write_arg), |
| 9760 | read(read_arg), |
| 9761 | expected_rv(expected_rv_arg), |
| 9762 | extra_write(extra_write_arg), |
| 9763 | extra_read(extra_read_arg) { |
| 9764 | } |
| 9765 | MockWrite write; |
| 9766 | MockRead read; |
| 9767 | int expected_rv; |
| 9768 | const MockWrite* extra_write; |
| 9769 | const MockRead* extra_read; |
| 9770 | }; |
| 9771 | |
| 9772 | static const int kNoSSL = 500; |
| 9773 | |
| 9774 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9775 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9776 | AuthTiming proxy_auth_timing; |
| 9777 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9778 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9779 | AuthTiming server_auth_timing; |
| 9780 | int server_auth_rv; |
| 9781 | int num_auth_rounds; |
| 9782 | int first_ssl_round; |
| 9783 | TestRound rounds[3]; |
| 9784 | } test_configs[] = { |
| 9785 | // Non-authenticating HTTP server with a direct connection. |
| 9786 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9787 | { TestRound(kGet, kSuccess, OK)}}, |
| 9788 | // Authenticating HTTP server with a direct connection. |
| 9789 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9790 | { TestRound(kGet, kServerChallenge, OK), |
| 9791 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9792 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9793 | { TestRound(kGet, kServerChallenge, OK), |
| 9794 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9795 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9796 | { TestRound(kGet, kServerChallenge, OK), |
| 9797 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9798 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9799 | { TestRound(kGet, kServerChallenge, OK), |
| 9800 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9801 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 9802 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 9803 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 9804 | // Authenticating HTTP server through a non-authenticating proxy. |
| 9805 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 9806 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9807 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9808 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 9809 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9810 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9811 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 9812 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9813 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 9814 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 9815 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 9816 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 9817 | // Non-authenticating HTTP server through an authenticating proxy. |
| 9818 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9819 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9820 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9821 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9822 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9823 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9824 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9825 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9826 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 9827 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9828 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9829 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 9830 | // Authenticating HTTP server through an authenticating proxy. |
| 9831 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9832 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9833 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9834 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9835 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9836 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9837 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9838 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9839 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 9840 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9841 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9842 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9843 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 9844 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9845 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9846 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9847 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9848 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9849 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9850 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9851 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9852 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9853 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9854 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9855 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 9856 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9857 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9858 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 9859 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 9860 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 9861 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 9862 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 9863 | // Non-authenticating HTTPS server with a direct connection. |
| 9864 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9865 | { TestRound(kGet, kSuccess, OK)}}, |
| 9866 | // Authenticating HTTPS server with a direct connection. |
| 9867 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9868 | { TestRound(kGet, kServerChallenge, OK), |
| 9869 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9870 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9871 | { TestRound(kGet, kServerChallenge, OK), |
| 9872 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9873 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9874 | { TestRound(kGet, kServerChallenge, OK), |
| 9875 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9876 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9877 | { TestRound(kGet, kServerChallenge, OK), |
| 9878 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9879 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 9880 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 9881 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9882 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 9883 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 9884 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9885 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9886 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 9887 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9888 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9889 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 9890 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9891 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9892 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 9893 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 9894 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9895 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 9896 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9897 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9898 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9899 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9900 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9901 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9902 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 9903 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9904 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 9905 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 9906 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9907 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 9908 | // Authenticating HTTPS server through an authenticating proxy. |
| 9909 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9910 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9911 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9912 | &kGet, &kServerChallenge), |
| 9913 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9914 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9915 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9916 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9917 | &kGet, &kServerChallenge), |
| 9918 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9919 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 9920 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9921 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9922 | &kGet, &kServerChallenge), |
| 9923 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9924 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 9925 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9926 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9927 | &kGet, &kServerChallenge), |
| 9928 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9929 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9930 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9931 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9932 | &kGet, &kServerChallenge), |
| 9933 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9934 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9935 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9936 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9937 | &kGet, &kServerChallenge), |
| 9938 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9939 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 9940 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9941 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9942 | &kGet, &kServerChallenge), |
| 9943 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 9944 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 9945 | { TestRound(kConnect, kProxyChallenge, OK), |
| 9946 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 9947 | &kGet, &kServerChallenge), |
| 9948 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 9949 | }; |
| 9950 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9951 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9952 | HttpAuthHandlerMock::Factory* auth_factory( |
| 9953 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9954 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9955 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 9956 | |
| 9957 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9958 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9959 | for (int n = 0; n < 2; n++) { |
| 9960 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 9961 | std::string auth_challenge = "Mock realm=proxy"; |
| 9962 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9963 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9964 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9965 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 9966 | origin, BoundNetLog()); |
| 9967 | auth_handler->SetGenerateExpectation( |
| 9968 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 9969 | test_config.proxy_auth_rv); |
| 9970 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 9971 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9972 | } |
| 9973 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 9974 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9975 | std::string auth_challenge = "Mock realm=server"; |
| 9976 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 9977 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 9978 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9979 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 9980 | origin, BoundNetLog()); |
| 9981 | auth_handler->SetGenerateExpectation( |
| 9982 | test_config.server_auth_timing == AUTH_ASYNC, |
| 9983 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 9984 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9985 | } |
| 9986 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9987 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 9988 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9989 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9990 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9991 | } |
| 9992 | |
| 9993 | HttpRequestInfo request; |
| 9994 | request.method = "GET"; |
| 9995 | request.url = GURL(test_config.server_url); |
| 9996 | request.load_flags = 0; |
| 9997 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9998 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10000 | |
| 10001 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10002 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10003 | |
| 10004 | // Set up expected reads and writes. |
| 10005 | MockRead reads[2]; |
| 10006 | reads[0] = read_write_round.read; |
| 10007 | size_t length_reads = 1; |
| 10008 | if (read_write_round.extra_read) { |
| 10009 | reads[1] = *read_write_round.extra_read; |
| 10010 | length_reads = 2; |
| 10011 | } |
| 10012 | |
| 10013 | MockWrite writes[2]; |
| 10014 | writes[0] = read_write_round.write; |
| 10015 | size_t length_writes = 1; |
| 10016 | if (read_write_round.extra_write) { |
| 10017 | writes[1] = *read_write_round.extra_write; |
| 10018 | length_writes = 2; |
| 10019 | } |
| 10020 | StaticSocketDataProvider data_provider( |
| 10021 | reads, length_reads, writes, length_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10022 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10023 | |
| 10024 | // Add an SSL sequence if necessary. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10025 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10026 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10027 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10028 | &ssl_socket_data_provider); |
| 10029 | |
| 10030 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10031 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10032 | int rv; |
| 10033 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10034 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10035 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10036 | rv = trans.RestartWithAuth( |
| 10037 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10038 | } |
| 10039 | if (rv == ERR_IO_PENDING) |
| 10040 | rv = callback.WaitForResult(); |
| 10041 | |
| 10042 | // Compare results with expected data. |
| 10043 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10044 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10045 | if (read_write_round.expected_rv == OK) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10046 | ASSERT_TRUE(response != NULL); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10047 | } else { |
| 10048 | EXPECT_TRUE(response == NULL); |
| 10049 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10050 | continue; |
| 10051 | } |
| 10052 | if (round + 1 < test_config.num_auth_rounds) { |
| 10053 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10054 | } else { |
| 10055 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10056 | } |
| 10057 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10058 | } |
| 10059 | } |
| 10060 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10061 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10062 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10063 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10064 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10065 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10066 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10067 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10068 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10069 | |
| 10070 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10071 | auth_handler->set_connection_based(true); |
| 10072 | std::string auth_challenge = "Mock realm=server"; |
| 10073 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10074 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10075 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10076 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10077 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10078 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10079 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10080 | int rv = OK; |
| 10081 | const HttpResponseInfo* response = NULL; |
| 10082 | HttpRequestInfo request; |
| 10083 | request.method = "GET"; |
| 10084 | request.url = origin; |
| 10085 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10086 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10087 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10088 | |
| 10089 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10090 | // to validate that the TCP socket is not released to the pool between |
| 10091 | // each round of multi-round authentication. |
| 10092 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10093 | ClientSocketPoolHistograms transport_pool_histograms("SmallTCP"); |
| 10094 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10095 | 50, // Max sockets for pool |
| 10096 | 1, // Max sockets per group |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10097 | &transport_pool_histograms, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10098 | session_deps_.host_resolver.get(), |
| 10099 | session_deps_.socket_factory.get(), |
| 10100 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10101 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10102 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10103 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10104 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10105 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10106 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10107 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10108 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10109 | |
| 10110 | const MockWrite kGet( |
| 10111 | "GET / HTTP/1.1\r\n" |
| 10112 | "Host: www.example.com\r\n" |
| 10113 | "Connection: keep-alive\r\n\r\n"); |
| 10114 | const MockWrite kGetAuth( |
| 10115 | "GET / HTTP/1.1\r\n" |
| 10116 | "Host: www.example.com\r\n" |
| 10117 | "Connection: keep-alive\r\n" |
| 10118 | "Authorization: auth_token\r\n\r\n"); |
| 10119 | |
| 10120 | const MockRead kServerChallenge( |
| 10121 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10122 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10123 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10124 | "Content-Length: 14\r\n\r\n" |
| 10125 | "Unauthorized\r\n"); |
| 10126 | const MockRead kSuccess( |
| 10127 | "HTTP/1.1 200 OK\r\n" |
| 10128 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10129 | "Content-Length: 3\r\n\r\n" |
| 10130 | "Yes"); |
| 10131 | |
| 10132 | MockWrite writes[] = { |
| 10133 | // First round |
| 10134 | kGet, |
| 10135 | // Second round |
| 10136 | kGetAuth, |
| 10137 | // Third round |
| 10138 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10139 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10140 | kGetAuth, |
| 10141 | // Competing request |
| 10142 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10143 | }; |
| 10144 | MockRead reads[] = { |
| 10145 | // First round |
| 10146 | kServerChallenge, |
| 10147 | // Second round |
| 10148 | kServerChallenge, |
| 10149 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10150 | kServerChallenge, |
| 10151 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10152 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10153 | // Competing response |
| 10154 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10155 | }; |
| 10156 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10157 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10158 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10159 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10160 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10161 | |
| 10162 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10163 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10164 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10165 | if (rv == ERR_IO_PENDING) |
| 10166 | rv = callback.WaitForResult(); |
| 10167 | EXPECT_EQ(OK, rv); |
| 10168 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10169 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10170 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10171 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10172 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10173 | // In between rounds, another request comes in for the same domain. |
| 10174 | // It should not be able to grab the TCP socket that trans has already |
| 10175 | // claimed. |
| 10176 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10177 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10178 | TestCompletionCallback callback_compete; |
| 10179 | rv = trans_compete->Start( |
| 10180 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10182 | // callback_compete.WaitForResult at this point would stall forever, |
| 10183 | // since the HttpNetworkTransaction does not release the request back to |
| 10184 | // the pool until after authentication completes. |
| 10185 | |
| 10186 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10187 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10188 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10189 | if (rv == ERR_IO_PENDING) |
| 10190 | rv = callback.WaitForResult(); |
| 10191 | EXPECT_EQ(OK, rv); |
| 10192 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10193 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10194 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10195 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10196 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10197 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10198 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10199 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10200 | if (rv == ERR_IO_PENDING) |
| 10201 | rv = callback.WaitForResult(); |
| 10202 | EXPECT_EQ(OK, rv); |
| 10203 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10204 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10205 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10206 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10207 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10208 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10209 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10210 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10211 | if (rv == ERR_IO_PENDING) |
| 10212 | rv = callback.WaitForResult(); |
| 10213 | EXPECT_EQ(OK, rv); |
| 10214 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10215 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10216 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10217 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10218 | |
| 10219 | // Read the body since the fourth round was successful. This will also |
| 10220 | // release the socket back to the pool. |
| 10221 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10222 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10223 | if (rv == ERR_IO_PENDING) |
| 10224 | rv = callback.WaitForResult(); |
| 10225 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10226 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10227 | EXPECT_EQ(0, rv); |
| 10228 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10229 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10230 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10231 | |
| 10232 | // The competing request can now finish. Wait for the headers and then |
| 10233 | // read the body. |
| 10234 | rv = callback_compete.WaitForResult(); |
| 10235 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10236 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10237 | if (rv == ERR_IO_PENDING) |
| 10238 | rv = callback.WaitForResult(); |
| 10239 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10240 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10241 | EXPECT_EQ(0, rv); |
| 10242 | |
| 10243 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10244 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10245 | } |
| 10246 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10247 | // This tests the case that a request is issued via http instead of spdy after |
| 10248 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10249 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10250 | session_deps_.use_alternate_protocols = true; |
| 10251 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10252 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10253 | session_deps_.next_protos = next_protos; |
| 10254 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10255 | HttpRequestInfo request; |
| 10256 | request.method = "GET"; |
| 10257 | request.url = GURL("https://www.google.com/"); |
| 10258 | request.load_flags = 0; |
| 10259 | |
| 10260 | MockWrite data_writes[] = { |
| 10261 | MockWrite("GET / HTTP/1.1\r\n" |
| 10262 | "Host: www.google.com\r\n" |
| 10263 | "Connection: keep-alive\r\n\r\n"), |
| 10264 | }; |
| 10265 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10266 | std::string alternate_protocol_http_header = |
| 10267 | GetAlternateProtocolHttpHeader(); |
| 10268 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10269 | MockRead data_reads[] = { |
| 10270 | MockRead("HTTP/1.1 200 OK\r\n"), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10271 | MockRead(alternate_protocol_http_header.c_str()), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10272 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10273 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10274 | }; |
| 10275 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10276 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10277 | ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 10278 | ssl.next_proto = "http/1.1"; |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 10279 | ssl.protocol_negotiated = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10280 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10282 | |
| 10283 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10284 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10287 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10288 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10289 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10290 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10291 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10293 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10294 | |
| 10295 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10296 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10297 | |
| 10298 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10299 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10300 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10301 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10302 | |
| 10303 | std::string response_data; |
| 10304 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10305 | EXPECT_EQ("hello world", response_data); |
| 10306 | |
| 10307 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10308 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10309 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10310 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10311 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10312 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10313 | // followed by an immediate server closing of the socket. |
| 10314 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10315 | session_deps_.use_alternate_protocols = true; |
| 10316 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10317 | |
| 10318 | HttpRequestInfo request; |
| 10319 | request.method = "GET"; |
| 10320 | request.url = GURL("https://www.google.com/"); |
| 10321 | request.load_flags = 0; |
| 10322 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10323 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10324 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10326 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10327 | scoped_ptr<SpdyFrame> req( |
| 10328 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 10329 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10330 | |
| 10331 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10332 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10333 | }; |
| 10334 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10335 | DelayedSocketData spdy_data( |
| 10336 | 0, // don't wait in this case, immediate hangup. |
| 10337 | spdy_reads, arraysize(spdy_reads), |
| 10338 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10339 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10341 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10342 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10343 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10344 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10347 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10348 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10349 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10350 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10351 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10352 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10353 | // it gets it. This is needed since the auth handler may get destroyed |
| 10354 | // before we get a chance to query it. |
| 10355 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10356 | public: |
| 10357 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10358 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10359 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10360 | |
| 10361 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10362 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10363 | const HttpRequestInfo* request, |
| 10364 | const CompletionCallback& callback, |
| 10365 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10366 | *url_ = request->url; |
| 10367 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10368 | credentials, request, callback, auth_token); |
| 10369 | } |
| 10370 | |
| 10371 | private: |
| 10372 | GURL* url_; |
| 10373 | }; |
| 10374 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10375 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10376 | // This test ensures that the URL passed into the proxy is upgraded |
| 10377 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10378 | session_deps_.use_alternate_protocols = true; |
| 10379 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10380 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10381 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10382 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 10383 | CapturingNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10384 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10385 | GURL request_url; |
| 10386 | { |
| 10387 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10388 | new HttpAuthHandlerMock::Factory(); |
| 10389 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10390 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10391 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10392 | auth_factory->set_do_init_from_challenge(true); |
| 10393 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10394 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10395 | |
| 10396 | HttpRequestInfo request; |
| 10397 | request.method = "GET"; |
| 10398 | request.url = GURL("http://www.google.com"); |
| 10399 | request.load_flags = 0; |
| 10400 | |
| 10401 | // First round goes unauthenticated through the proxy. |
| 10402 | MockWrite data_writes_1[] = { |
| 10403 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10404 | "Host: www.google.com\r\n" |
| 10405 | "Proxy-Connection: keep-alive\r\n" |
| 10406 | "\r\n"), |
| 10407 | }; |
| 10408 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10409 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10410 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10411 | MockRead("Alternate-Protocol: 443:"), |
| 10412 | MockRead(GetAlternateProtocolFromParam()), |
| 10413 | MockRead("\r\n"), |
| 10414 | MockRead("Proxy-Connection: close\r\n"), |
| 10415 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10416 | }; |
| 10417 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10418 | data_writes_1, arraysize(data_writes_1)); |
| 10419 | |
| 10420 | // Second round tries to tunnel to www.google.com due to the |
| 10421 | // Alternate-Protocol announcement in the first round. It fails due |
| 10422 | // to a proxy authentication challenge. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10423 | // After the failure, a tunnel is established to www.google.com using |
| 10424 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10425 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10426 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10427 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10428 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10429 | // to obtain a new one. |
| 10430 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10431 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10432 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10433 | // establishment and SPDY framing issues. Alas, the |
| 10434 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10435 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10436 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10437 | scoped_ptr<SpdyFrame> req( |
| 10438 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10439 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10440 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10441 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10442 | MockWrite data_writes_2[] = { |
| 10443 | // First connection attempt without Proxy-Authorization. |
| 10444 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10445 | "Host: www.google.com\r\n" |
| 10446 | "Proxy-Connection: keep-alive\r\n" |
| 10447 | "\r\n"), |
| 10448 | |
| 10449 | // Second connection attempt with Proxy-Authorization. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10450 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10451 | "Host: www.google.com\r\n" |
| 10452 | "Proxy-Connection: keep-alive\r\n" |
| 10453 | "Proxy-Authorization: auth_token\r\n" |
| 10454 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10455 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10456 | // SPDY request |
| 10457 | CreateMockWrite(*req), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10458 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10459 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10460 | "Proxy-Authenticate: Mock\r\n" |
| 10461 | "Proxy-Connection: close\r\n" |
| 10462 | "\r\n"); |
| 10463 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10464 | MockRead data_reads_2[] = { |
| 10465 | // First connection attempt fails |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10466 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1), |
| 10467 | MockRead(ASYNC, kRejectConnectResponse, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10468 | arraysize(kRejectConnectResponse) - 1, 1), |
| 10469 | |
| 10470 | // Second connection attempt passes |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10471 | MockRead(ASYNC, kAcceptConnectResponse, |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10472 | arraysize(kAcceptConnectResponse) -1, 4), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10473 | |
| 10474 | // SPDY response |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10475 | CreateMockRead(*resp.get(), 6), |
| 10476 | CreateMockRead(*data.get(), 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10477 | MockRead(ASYNC, 0, 0, 6), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10478 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10479 | OrderedSocketData data_2( |
| 10480 | data_reads_2, arraysize(data_reads_2), |
| 10481 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10482 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10483 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10484 | ssl.SetNextProto(GetParam()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10485 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10486 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10487 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10488 | NULL, 0, NULL, 0); |
| 10489 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10490 | never_finishing_connect); |
| 10491 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10492 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10493 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10495 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10496 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10497 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10498 | |
| 10499 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10500 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10501 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10502 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10503 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10504 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10505 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10506 | |
| 10507 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10508 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10509 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10511 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10512 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10513 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10514 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10515 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10516 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10517 | |
| 10518 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10519 | TestCompletionCallback callback_3; |
| 10520 | rv = trans_2->RestartWithAuth( |
| 10521 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10522 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10523 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10524 | |
| 10525 | // After all that work, these two lines (or actually, just the scheme) are |
| 10526 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10527 | EXPECT_EQ("https", request_url.scheme()); |
| 10528 | EXPECT_EQ("www.google.com", request_url.host()); |
| 10529 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10530 | LoadTimingInfo load_timing_info; |
| 10531 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10532 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10533 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10534 | } |
| 10535 | |
| 10536 | // Test that if we cancel the transaction as the connection is completing, that |
| 10537 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10538 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10539 | // Setup everything about the connection to complete synchronously, so that |
| 10540 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10541 | // for is the callback from the HttpStreamRequest. |
| 10542 | // Then cancel the transaction. |
| 10543 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10544 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10545 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10546 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10547 | MockRead(SYNCHRONOUS, "hello world"), |
| 10548 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10549 | }; |
| 10550 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10551 | HttpRequestInfo request; |
| 10552 | request.method = "GET"; |
| 10553 | request.url = GURL("http://www.google.com/"); |
| 10554 | request.load_flags = 0; |
| 10555 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10556 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10557 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10558 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10559 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10560 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10561 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10562 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10563 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10565 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10566 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10567 | CapturingBoundNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10568 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10569 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10570 | trans.reset(); // Cancel the transaction here. |
| 10571 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10572 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10573 | } |
| 10574 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10575 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10576 | // stream is drained properly and added back to the socket pool. The main |
| 10577 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10578 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10579 | // deleted. |
| 10580 | // See http://crbug.com/368418 |
| 10581 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10582 | MockRead data_reads[] = { |
| 10583 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10584 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10585 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10586 | MockRead(ASYNC, "1"), |
| 10587 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10588 | // HttpNetworkTransaction has been deleted. |
| 10589 | MockRead(ASYNC, "2"), |
| 10590 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10591 | }; |
| 10592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10594 | |
| 10595 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10596 | |
| 10597 | { |
| 10598 | HttpRequestInfo request; |
| 10599 | request.method = "GET"; |
| 10600 | request.url = GURL("http://www.google.com/"); |
| 10601 | request.load_flags = 0; |
| 10602 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10604 | TestCompletionCallback callback; |
| 10605 | |
| 10606 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10607 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10608 | callback.WaitForResult(); |
| 10609 | |
| 10610 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10611 | ASSERT_TRUE(response != NULL); |
| 10612 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10613 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10614 | |
| 10615 | // The transaction and HttpRequestInfo are deleted. |
| 10616 | } |
| 10617 | |
| 10618 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10619 | base::MessageLoop::current()->RunUntilIdle(); |
| 10620 | |
| 10621 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10622 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10623 | } |
| 10624 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10625 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10626 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10627 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10628 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10629 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10630 | session_deps_.net_log = log.bound().net_log(); |
| 10631 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10632 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10633 | HttpRequestInfo request; |
| 10634 | request.method = "GET"; |
| 10635 | request.url = GURL("http://www.google.com/"); |
| 10636 | |
| 10637 | MockWrite data_writes1[] = { |
| 10638 | MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 10639 | "Host: www.google.com\r\n" |
| 10640 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10641 | }; |
| 10642 | |
| 10643 | MockRead data_reads1[] = { |
| 10644 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10645 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10646 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10647 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10648 | }; |
| 10649 | |
| 10650 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10651 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10652 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10654 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10655 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10656 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10658 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10659 | trans->SetBeforeProxyHeadersSentCallback( |
| 10660 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10661 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10663 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10664 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10665 | |
| 10666 | rv = callback1.WaitForResult(); |
| 10667 | EXPECT_EQ(OK, rv); |
| 10668 | |
| 10669 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10670 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10671 | |
| 10672 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10673 | EXPECT_EQ(200, response->headers->response_code()); |
| 10674 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10675 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10676 | EXPECT_TRUE( |
| 10677 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10678 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10679 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10680 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10681 | |
| 10682 | LoadTimingInfo load_timing_info; |
| 10683 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10684 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10685 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10686 | } |
| 10687 | |
| 10688 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10689 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10690 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10691 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10692 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10693 | session_deps_.net_log = log.bound().net_log(); |
| 10694 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10695 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10696 | HttpRequestInfo request; |
| 10697 | request.method = "GET"; |
| 10698 | request.url = GURL("https://www.google.com/"); |
| 10699 | |
| 10700 | // Since we have proxy, should try to establish tunnel. |
| 10701 | MockWrite data_writes1[] = { |
| 10702 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10703 | "Host: www.google.com\r\n" |
| 10704 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10705 | |
| 10706 | MockWrite("GET / HTTP/1.1\r\n" |
| 10707 | "Host: www.google.com\r\n" |
| 10708 | "Connection: keep-alive\r\n\r\n"), |
| 10709 | }; |
| 10710 | |
| 10711 | MockRead data_reads1[] = { |
| 10712 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 10713 | |
| 10714 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10715 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10716 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10717 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10718 | }; |
| 10719 | |
| 10720 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10721 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10722 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10723 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10726 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10727 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10731 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10733 | |
| 10734 | rv = callback1.WaitForResult(); |
| 10735 | EXPECT_EQ(OK, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10736 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10737 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10738 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10739 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10740 | NetLog::PHASE_NONE); |
| 10741 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10742 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10743 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10744 | NetLog::PHASE_NONE); |
| 10745 | |
| 10746 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10747 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10748 | |
| 10749 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10750 | EXPECT_EQ(200, response->headers->response_code()); |
| 10751 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10752 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10753 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10754 | EXPECT_TRUE( |
| 10755 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10756 | |
| 10757 | LoadTimingInfo load_timing_info; |
| 10758 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10759 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10760 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10761 | } |
| 10762 | |
| 10763 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 10764 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10765 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10766 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 10767 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10768 | session_deps_.net_log = log.bound().net_log(); |
| 10769 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10770 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10771 | HttpRequestInfo request; |
| 10772 | request.method = "GET"; |
| 10773 | request.url = GURL("https://www.google.com/"); |
| 10774 | |
| 10775 | // Since we have proxy, should try to establish tunnel. |
| 10776 | MockWrite data_writes1[] = { |
| 10777 | MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 10778 | "Host: www.google.com\r\n" |
| 10779 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10780 | |
| 10781 | MockWrite("GET / HTTP/1.1\r\n" |
| 10782 | "Host: www.google.com\r\n" |
| 10783 | "Connection: keep-alive\r\n\r\n"), |
| 10784 | }; |
| 10785 | |
| 10786 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10787 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10788 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10789 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10790 | }; |
| 10791 | |
| 10792 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10793 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10794 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10795 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10796 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10798 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10799 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10800 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10801 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10803 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10804 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10805 | |
| 10806 | rv = callback1.WaitForResult(); |
| 10807 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 10808 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10809 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10810 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10811 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10812 | NetLog::PHASE_NONE); |
| 10813 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 10814 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10815 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10816 | NetLog::PHASE_NONE); |
| 10817 | } |
| 10818 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10819 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10820 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10821 | scoped_ptr<SpdyFrame> req( |
| 10822 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10823 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 10824 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10825 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10826 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10827 | MockRead spdy_reads[] = { |
| 10828 | CreateMockRead(*resp), |
| 10829 | CreateMockRead(*data), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10830 | MockRead(ASYNC, 0, 0), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10831 | }; |
| 10832 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 10833 | DelayedSocketData spdy_data( |
| 10834 | 1, // wait for one write to finish before reading. |
| 10835 | spdy_reads, arraysize(spdy_reads), |
| 10836 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10837 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10838 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10839 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10840 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10841 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10842 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10843 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10844 | |
| 10845 | // Set up an initial SpdySession in the pool to reuse. |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10846 | HostPortPair host_port_pair("www.google.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10847 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10848 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10849 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10850 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10851 | |
| 10852 | HttpRequestInfo request; |
| 10853 | request.method = "GET"; |
| 10854 | request.url = GURL("https://www.google.com/"); |
| 10855 | request.load_flags = 0; |
| 10856 | |
| 10857 | // This is the important line that marks this as a preconnect. |
| 10858 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 10859 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10862 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 10863 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10864 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10865 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10866 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 10867 | } |
| 10868 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10869 | // Given a net error, cause that error to be returned from the first Write() |
| 10870 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10871 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10872 | int error, IoMode mode) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10873 | net::HttpRequestInfo request_info; |
| 10874 | request_info.url = GURL("https://www.example.com/"); |
| 10875 | request_info.method = "GET"; |
| 10876 | request_info.load_flags = net::LOAD_NORMAL; |
| 10877 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10878 | SSLSocketDataProvider ssl_data(mode, OK); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10879 | net::MockWrite data_writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10880 | net::MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10881 | }; |
| 10882 | net::StaticSocketDataProvider data(NULL, 0, |
| 10883 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10885 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10886 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10887 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10888 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10889 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10891 | TestCompletionCallback callback; |
| 10892 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10893 | if (rv == net::ERR_IO_PENDING) |
| 10894 | rv = callback.WaitForResult(); |
| 10895 | ASSERT_EQ(error, rv); |
| 10896 | } |
| 10897 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10898 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10899 | // Just check a grab bag of cert errors. |
| 10900 | static const int kErrors[] = { |
| 10901 | ERR_CERT_COMMON_NAME_INVALID, |
| 10902 | ERR_CERT_AUTHORITY_INVALID, |
| 10903 | ERR_CERT_DATE_INVALID, |
| 10904 | }; |
| 10905 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10906 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 10907 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 10908 | } |
| 10909 | } |
| 10910 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10911 | // Ensure that a client certificate is removed from the SSL client auth |
| 10912 | // cache when: |
| 10913 | // 1) No proxy is involved. |
| 10914 | // 2) TLS False Start is disabled. |
| 10915 | // 3) The initial TLS handshake requests a client certificate. |
| 10916 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10917 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10918 | ClientAuthCertCache_Direct_NoFalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10919 | net::HttpRequestInfo request_info; |
| 10920 | request_info.url = GURL("https://www.example.com/"); |
| 10921 | request_info.method = "GET"; |
| 10922 | request_info.load_flags = net::LOAD_NORMAL; |
| 10923 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10924 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 10925 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10926 | |
| 10927 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 10928 | // CertificateRequest is received for the first time, the handshake will |
| 10929 | // be aborted to allow the caller to provide a certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10930 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10931 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10933 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10935 | |
| 10936 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 10937 | // False Start is not being used, the result of the SSL handshake will be |
| 10938 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 10939 | // matches the result of a server sending a handshake_failure alert, |
| 10940 | // rather than a Finished message, because it requires a client |
| 10941 | // certificate and none was supplied. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10942 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10943 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10944 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10945 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10946 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10947 | |
| 10948 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 10949 | // connection to a server fails during an SSL handshake, |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10950 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 10951 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10952 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10953 | // requiring a client certificate, this fallback handshake should also |
| 10954 | // fail. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10955 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10956 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10958 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10959 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10960 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10961 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 10962 | // connection to a server fails during an SSL handshake, |
| 10963 | // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous |
| 10964 | // connection was attempted with TLSv1. This is transparent to the caller |
| 10965 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 10966 | // requiring a client certificate, this fallback handshake should also |
| 10967 | // fail. |
| 10968 | SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10969 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10971 | net::StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10972 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 10973 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 10974 | // Need one more if TLSv1.2 is enabled. |
| 10975 | SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
| 10976 | ssl_data5.cert_request_info = cert_request.get(); |
| 10977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 10978 | net::StaticSocketDataProvider data5(NULL, 0, NULL, 0); |
| 10979 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 10980 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10981 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10982 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10984 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10985 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10986 | TestCompletionCallback callback; |
| 10987 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 10988 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 10989 | |
| 10990 | // Complete the SSL handshake, which should abort due to requiring a |
| 10991 | // client certificate. |
| 10992 | rv = callback.WaitForResult(); |
| 10993 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 10994 | |
| 10995 | // Indicate that no certificate should be supplied. From the perspective |
| 10996 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 10997 | // certificate, so this is the same as supply a |
| 10998 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10999 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11000 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11001 | |
| 11002 | // Ensure the certificate was added to the client auth cache before |
| 11003 | // allowing the connection to continue restarting. |
| 11004 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11005 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11006 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11007 | ASSERT_EQ(NULL, client_cert.get()); |
| 11008 | |
| 11009 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11010 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11011 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11012 | rv = callback.WaitForResult(); |
| 11013 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 11014 | |
| 11015 | // Ensure that the client certificate is removed from the cache on a |
| 11016 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11017 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11018 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11019 | } |
| 11020 | |
| 11021 | // Ensure that a client certificate is removed from the SSL client auth |
| 11022 | // cache when: |
| 11023 | // 1) No proxy is involved. |
| 11024 | // 2) TLS False Start is enabled. |
| 11025 | // 3) The initial TLS handshake requests a client certificate. |
| 11026 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11027 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11028 | ClientAuthCertCache_Direct_FalseStart) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11029 | net::HttpRequestInfo request_info; |
| 11030 | request_info.url = GURL("https://www.example.com/"); |
| 11031 | request_info.method = "GET"; |
| 11032 | request_info.load_flags = net::LOAD_NORMAL; |
| 11033 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11034 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11035 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11036 | |
| 11037 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11038 | // return successfully after reading up to the peer's Certificate message. |
| 11039 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11040 | // enqueue application data to be sent in the same packet as the |
| 11041 | // ChangeCipherSpec and Finished messages. |
| 11042 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11043 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11044 | // Finished messages. If there was an error negotiating with the peer, |
| 11045 | // such as due to the peer requiring a client certificate when none was |
| 11046 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11047 | // called. |
| 11048 | |
| 11049 | // Like the non-False Start case, when a client certificate is requested by |
| 11050 | // the peer, the handshake is aborted during the Connect() call. |
| 11051 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11052 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11053 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11055 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11056 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11057 | |
| 11058 | // When a client certificate is supplied, Connect() will not be aborted |
| 11059 | // when the peer requests the certificate. Instead, the handshake will |
| 11060 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11061 | // the socket. The handshake messages are not processed until Read() is |
| 11062 | // called, which then detects that the handshake was aborted, due to the |
| 11063 | // peer sending a handshake_failure because it requires a client |
| 11064 | // certificate. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11065 | SSLSocketDataProvider ssl_data2(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11066 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11068 | net::MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11069 | net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11070 | }; |
| 11071 | net::StaticSocketDataProvider data2( |
| 11072 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11073 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11074 | |
| 11075 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11076 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11077 | // TLSv1. It has the same behaviour as [ssl_]data2. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11078 | SSLSocketDataProvider ssl_data3(ASYNC, net::OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11079 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11081 | net::StaticSocketDataProvider data3( |
| 11082 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11083 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11084 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11085 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11086 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
| 11087 | SSLSocketDataProvider ssl_data4(ASYNC, net::OK); |
| 11088 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11089 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11090 | net::StaticSocketDataProvider data4( |
| 11091 | data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11092 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11093 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11094 | // Need one more if TLSv1.2 is enabled. |
| 11095 | SSLSocketDataProvider ssl_data5(ASYNC, net::OK); |
| 11096 | ssl_data5.cert_request_info = cert_request.get(); |
| 11097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
| 11098 | net::StaticSocketDataProvider data5( |
| 11099 | data2_reads, arraysize(data2_reads), NULL, 0); |
| 11100 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11101 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11102 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11103 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11104 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11105 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11106 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11107 | TestCompletionCallback callback; |
| 11108 | int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11109 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11110 | |
| 11111 | // Complete the SSL handshake, which should abort due to requiring a |
| 11112 | // client certificate. |
| 11113 | rv = callback.WaitForResult(); |
| 11114 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 11115 | |
| 11116 | // Indicate that no certificate should be supplied. From the perspective |
| 11117 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11118 | // certificate, so this is the same as supply a |
| 11119 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11120 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11121 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11122 | |
| 11123 | // Ensure the certificate was added to the client auth cache before |
| 11124 | // allowing the connection to continue restarting. |
| 11125 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11126 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11127 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11128 | ASSERT_EQ(NULL, client_cert.get()); |
| 11129 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11130 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11131 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11132 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11133 | rv = callback.WaitForResult(); |
| 11134 | ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 11135 | |
| 11136 | // Ensure that the client certificate is removed from the cache on a |
| 11137 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11138 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11139 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11140 | } |
| 11141 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11142 | // Ensure that a client certificate is removed from the SSL client auth |
| 11143 | // cache when: |
| 11144 | // 1) An HTTPS proxy is involved. |
| 11145 | // 3) The HTTPS proxy requests a client certificate. |
| 11146 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11147 | // proxy. |
| 11148 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11149 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11150 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11151 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11152 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 11153 | CapturingBoundNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11154 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11155 | |
| 11156 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11157 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11158 | |
| 11159 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11160 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11161 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11162 | // (proxy:70). |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11163 | SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11164 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11166 | net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11167 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11168 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11169 | SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11170 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11172 | net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11173 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11174 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11175 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11176 | #if 0 |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11177 | SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11178 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11179 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11180 | net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11181 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11182 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11183 | |
| 11184 | net::HttpRequestInfo requests[2]; |
| 11185 | requests[0].url = GURL("https://www.example.com/"); |
| 11186 | requests[0].method = "GET"; |
| 11187 | requests[0].load_flags = net::LOAD_NORMAL; |
| 11188 | |
| 11189 | requests[1].url = GURL("http://www.example.com/"); |
| 11190 | requests[1].method = "GET"; |
| 11191 | requests[1].load_flags = net::LOAD_NORMAL; |
| 11192 | |
| 11193 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11194 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 11195 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11196 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11197 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11198 | |
| 11199 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11200 | TestCompletionCallback callback; |
| 11201 | int rv = trans->Start( |
| 11202 | &requests[i], callback.callback(), net::BoundNetLog()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11203 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11204 | |
| 11205 | // Complete the SSL handshake, which should abort due to requiring a |
| 11206 | // client certificate. |
| 11207 | rv = callback.WaitForResult(); |
| 11208 | ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
| 11209 | |
| 11210 | // Indicate that no certificate should be supplied. From the perspective |
| 11211 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11212 | // certificate, so this is the same as supply a |
| 11213 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11214 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11215 | ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 11216 | |
| 11217 | // Ensure the certificate was added to the client auth cache before |
| 11218 | // allowing the connection to continue restarting. |
| 11219 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11220 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11221 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11222 | ASSERT_EQ(NULL, client_cert.get()); |
| 11223 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11224 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11225 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11226 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11227 | |
| 11228 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11229 | // then consume ssl_data3, which should also fail. The result code is |
| 11230 | // checked against what ssl_data3 should return. |
| 11231 | rv = callback.WaitForResult(); |
| 11232 | ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv); |
| 11233 | |
| 11234 | // Now that the new handshake has failed, ensure that the client |
| 11235 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11236 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11237 | HostPortPair("proxy", 70), &client_cert)); |
| 11238 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11239 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11240 | } |
| 11241 | } |
| 11242 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11243 | // Unlike TEST/TEST_F, which are macros that expand to further macros, |
| 11244 | // TEST_P is a macro that expands directly to code that stringizes the |
| 11245 | // arguments. As a result, macros passed as parameters (such as prefix |
| 11246 | // or test_case_name) will not be expanded by the preprocessor. To |
| 11247 | // work around this, indirect the macro for TEST_P, so that the |
| 11248 | // pre-processor will expand macros such as MAYBE_test_name before |
| 11249 | // instantiating the test. |
| 11250 | #define WRAPPED_TEST_P(test_case_name, test_name) \ |
| 11251 | TEST_P(test_case_name, test_name) |
| 11252 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11253 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11254 | #if defined(OS_WIN) |
| 11255 | #define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling |
| 11256 | #else |
| 11257 | #define MAYBE_UseIPConnectionPooling UseIPConnectionPooling |
| 11258 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11259 | WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11260 | session_deps_.use_alternate_protocols = true; |
| 11261 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11262 | |
| 11263 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11264 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11265 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11266 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11267 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11268 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11269 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11270 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11272 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11273 | scoped_ptr<SpdyFrame> host1_req( |
| 11274 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11275 | scoped_ptr<SpdyFrame> host2_req( |
| 11276 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11277 | MockWrite spdy_writes[] = { |
| 11278 | CreateMockWrite(*host1_req, 1), |
| 11279 | CreateMockWrite(*host2_req, 4), |
| 11280 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11281 | scoped_ptr<SpdyFrame> host1_resp( |
| 11282 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11283 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11284 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11285 | scoped_ptr<SpdyFrame> host2_resp( |
| 11286 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11287 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11288 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11289 | MockRead spdy_reads[] = { |
| 11290 | CreateMockRead(*host1_resp, 2), |
| 11291 | CreateMockRead(*host1_resp_body, 3), |
| 11292 | CreateMockRead(*host2_resp, 5), |
| 11293 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11294 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11295 | }; |
| 11296 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11297 | IPAddressNumber ip; |
| 11298 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11299 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11300 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11301 | OrderedSocketData spdy_data( |
| 11302 | connect, |
| 11303 | spdy_reads, arraysize(spdy_reads), |
| 11304 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11305 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11306 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11307 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11308 | HttpRequestInfo request1; |
| 11309 | request1.method = "GET"; |
| 11310 | request1.url = GURL("https://www.google.com/"); |
| 11311 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11312 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11314 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11315 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11316 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11317 | |
| 11318 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11319 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11320 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11321 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11322 | |
| 11323 | std::string response_data; |
| 11324 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11325 | EXPECT_EQ("hello!", response_data); |
| 11326 | |
| 11327 | // Preload www.gmail.com into HostCache. |
| 11328 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11329 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11330 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11331 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11332 | DEFAULT_PRIORITY, |
| 11333 | &ignored, |
| 11334 | callback.callback(), |
| 11335 | NULL, |
| 11336 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11337 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11338 | rv = callback.WaitForResult(); |
| 11339 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11340 | |
| 11341 | HttpRequestInfo request2; |
| 11342 | request2.method = "GET"; |
| 11343 | request2.url = GURL("https://www.gmail.com/"); |
| 11344 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11345 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11347 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11348 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11349 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11350 | |
| 11351 | response = trans2.GetResponseInfo(); |
| 11352 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11353 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11354 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11355 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11356 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11357 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11358 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11359 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11360 | #undef MAYBE_UseIPConnectionPooling |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11361 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11362 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11363 | session_deps_.use_alternate_protocols = true; |
| 11364 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11365 | |
| 11366 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11367 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11368 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11369 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11370 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11371 | |
| 11372 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11373 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11375 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11376 | scoped_ptr<SpdyFrame> host1_req( |
| 11377 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11378 | scoped_ptr<SpdyFrame> host2_req( |
| 11379 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11380 | MockWrite spdy_writes[] = { |
| 11381 | CreateMockWrite(*host1_req, 1), |
| 11382 | CreateMockWrite(*host2_req, 4), |
| 11383 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11384 | scoped_ptr<SpdyFrame> host1_resp( |
| 11385 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11386 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11387 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11388 | scoped_ptr<SpdyFrame> host2_resp( |
| 11389 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11390 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11391 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11392 | MockRead spdy_reads[] = { |
| 11393 | CreateMockRead(*host1_resp, 2), |
| 11394 | CreateMockRead(*host1_resp_body, 3), |
| 11395 | CreateMockRead(*host2_resp, 5), |
| 11396 | CreateMockRead(*host2_resp_body, 6), |
| 11397 | MockRead(ASYNC, 0, 7), |
| 11398 | }; |
| 11399 | |
| 11400 | IPAddressNumber ip; |
| 11401 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11402 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11403 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11404 | OrderedSocketData spdy_data( |
| 11405 | connect, |
| 11406 | spdy_reads, arraysize(spdy_reads), |
| 11407 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11408 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11409 | |
| 11410 | TestCompletionCallback callback; |
| 11411 | HttpRequestInfo request1; |
| 11412 | request1.method = "GET"; |
| 11413 | request1.url = GURL("https://www.google.com/"); |
| 11414 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11415 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11416 | |
| 11417 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11418 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11419 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11420 | |
| 11421 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11422 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11423 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11424 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11425 | |
| 11426 | std::string response_data; |
| 11427 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11428 | EXPECT_EQ("hello!", response_data); |
| 11429 | |
| 11430 | HttpRequestInfo request2; |
| 11431 | request2.method = "GET"; |
| 11432 | request2.url = GURL("https://www.gmail.com/"); |
| 11433 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11434 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11435 | |
| 11436 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11437 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11438 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11439 | |
| 11440 | response = trans2.GetResponseInfo(); |
| 11441 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11442 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11443 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11444 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11445 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11446 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11447 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11448 | } |
| 11449 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11450 | class OneTimeCachingHostResolver : public net::HostResolver { |
| 11451 | public: |
| 11452 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11453 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11454 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11455 | |
| 11456 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11457 | |
| 11458 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11459 | int Resolve(const RequestInfo& info, |
| 11460 | RequestPriority priority, |
| 11461 | AddressList* addresses, |
| 11462 | const CompletionCallback& callback, |
| 11463 | RequestHandle* out_req, |
| 11464 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11465 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11466 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11467 | } |
| 11468 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11469 | int ResolveFromCache(const RequestInfo& info, |
| 11470 | AddressList* addresses, |
| 11471 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11472 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11473 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11474 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11475 | return rv; |
| 11476 | } |
| 11477 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11478 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11479 | host_resolver_.CancelRequest(req); |
| 11480 | } |
| 11481 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11482 | MockCachingHostResolver* GetMockHostResolver() { |
| 11483 | return &host_resolver_; |
| 11484 | } |
| 11485 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11486 | private: |
| 11487 | MockCachingHostResolver host_resolver_; |
| 11488 | const HostPortPair host_port_; |
| 11489 | }; |
| 11490 | |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11491 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 |
| 11492 | #if defined(OS_WIN) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11493 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11494 | DISABLED_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11495 | #else |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11496 | #define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \ |
| 11497 | UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11498 | #endif |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11499 | WRAPPED_TEST_P(HttpNetworkTransactionTest, |
| 11500 | MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11501 | // Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_ |
| 11502 | // prefix doesn't work with parametrized tests). |
| 11503 | #if defined(OS_WIN) |
| 11504 | return; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11505 | #else |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11506 | session_deps_.use_alternate_protocols = true; |
| 11507 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11508 | |
| 11509 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11510 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11511 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11512 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11513 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11514 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11515 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11516 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11517 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11518 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11519 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11520 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11521 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11522 | scoped_ptr<SpdyFrame> host1_req( |
| 11523 | spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST)); |
| 11524 | scoped_ptr<SpdyFrame> host2_req( |
| 11525 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11526 | MockWrite spdy_writes[] = { |
| 11527 | CreateMockWrite(*host1_req, 1), |
| 11528 | CreateMockWrite(*host2_req, 4), |
| 11529 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11530 | scoped_ptr<SpdyFrame> host1_resp( |
| 11531 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11532 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11533 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11534 | scoped_ptr<SpdyFrame> host2_resp( |
| 11535 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11536 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11537 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11538 | MockRead spdy_reads[] = { |
| 11539 | CreateMockRead(*host1_resp, 2), |
| 11540 | CreateMockRead(*host1_resp_body, 3), |
| 11541 | CreateMockRead(*host2_resp, 5), |
| 11542 | CreateMockRead(*host2_resp_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11543 | MockRead(ASYNC, 0, 7), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11544 | }; |
| 11545 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11546 | IPAddressNumber ip; |
| 11547 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11548 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11549 | MockConnect connect(ASYNC, OK, peer_addr); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11550 | OrderedSocketData spdy_data( |
| 11551 | connect, |
| 11552 | spdy_reads, arraysize(spdy_reads), |
| 11553 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11554 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11555 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11556 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11557 | HttpRequestInfo request1; |
| 11558 | request1.method = "GET"; |
| 11559 | request1.url = GURL("https://www.google.com/"); |
| 11560 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11561 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11563 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11565 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11566 | |
| 11567 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11568 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11569 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11570 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11571 | |
| 11572 | std::string response_data; |
| 11573 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11574 | EXPECT_EQ("hello!", response_data); |
| 11575 | |
| 11576 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11577 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11578 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11579 | rv = host_resolver.Resolve(resolve_info, |
| 11580 | DEFAULT_PRIORITY, |
| 11581 | &ignored, |
| 11582 | callback.callback(), |
| 11583 | NULL, |
| 11584 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11585 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11586 | rv = callback.WaitForResult(); |
| 11587 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11588 | |
| 11589 | HttpRequestInfo request2; |
| 11590 | request2.method = "GET"; |
| 11591 | request2.url = GURL("https://www.gmail.com/"); |
| 11592 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11593 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11595 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11596 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11597 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11598 | |
| 11599 | response = trans2.GetResponseInfo(); |
| 11600 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11601 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11602 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11603 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11604 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11605 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11606 | EXPECT_EQ("hello!", response_data); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 11607 | #endif |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11608 | } |
[email protected] | 45b17082 | 2012-05-04 21:18:14 | [diff] [blame] | 11609 | #undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11610 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11611 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11612 | const std::string https_url = "https://www.google.com:8080/"; |
| 11613 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11614 | |
| 11615 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11616 | scoped_ptr<SpdyFrame> req1( |
| 11617 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11618 | |
| 11619 | MockWrite writes1[] = { |
| 11620 | CreateMockWrite(*req1, 0), |
| 11621 | }; |
| 11622 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11623 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11624 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11625 | MockRead reads1[] = { |
| 11626 | CreateMockRead(*resp1, 1), |
| 11627 | CreateMockRead(*body1, 2), |
| 11628 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11629 | }; |
| 11630 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11631 | DelayedSocketData data1( |
| 11632 | 1, reads1, arraysize(reads1), |
| 11633 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11634 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11635 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11636 | |
| 11637 | // HTTP GET for the HTTP URL |
| 11638 | MockWrite writes2[] = { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11639 | MockWrite(ASYNC, 4, |
| 11640 | "GET / HTTP/1.1\r\n" |
| 11641 | "Host: www.google.com:8080\r\n" |
| 11642 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11643 | }; |
| 11644 | |
| 11645 | MockRead reads2[] = { |
| 11646 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11647 | MockRead(ASYNC, 6, "hello"), |
| 11648 | MockRead(ASYNC, 7, OK), |
| 11649 | }; |
| 11650 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11651 | DelayedSocketData data2( |
| 11652 | 1, reads2, arraysize(reads2), |
| 11653 | writes2, arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11654 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11655 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11656 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11658 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11659 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11660 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11661 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11662 | |
| 11663 | // Start the first transaction to set up the SpdySession |
| 11664 | HttpRequestInfo request1; |
| 11665 | request1.method = "GET"; |
| 11666 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11667 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11668 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11669 | TestCompletionCallback callback1; |
| 11670 | EXPECT_EQ(ERR_IO_PENDING, |
| 11671 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11672 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11673 | |
| 11674 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11675 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11676 | |
| 11677 | // Now, start the HTTP request |
| 11678 | HttpRequestInfo request2; |
| 11679 | request2.method = "GET"; |
| 11680 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11681 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11682 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11683 | TestCompletionCallback callback2; |
| 11684 | EXPECT_EQ(ERR_IO_PENDING, |
| 11685 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11686 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11687 | |
| 11688 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11689 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11690 | } |
| 11691 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11692 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11693 | const std::string https_url = "https://www.google.com:8080/"; |
| 11694 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11695 | |
| 11696 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11697 | const HostPortPair host_port_pair("www.google.com", 8080); |
| 11698 | scoped_ptr<SpdyFrame> connect( |
| 11699 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11700 | scoped_ptr<SpdyFrame> req1( |
| 11701 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11702 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 11703 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11704 | |
| 11705 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11706 | SpdyHeaderBlock req2_block; |
| 11707 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11708 | req2_block[spdy_util_.GetPathKey()] = "/"; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11709 | req2_block[spdy_util_.GetHostKey()] = "www.google.com:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11710 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 11711 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 11712 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11713 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11714 | |
| 11715 | MockWrite writes1[] = { |
| 11716 | CreateMockWrite(*connect, 0), |
| 11717 | CreateMockWrite(*wrapped_req1, 2), |
| 11718 | CreateMockWrite(*req2, 5), |
| 11719 | }; |
| 11720 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11721 | scoped_ptr<SpdyFrame> conn_resp( |
| 11722 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11723 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11724 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11725 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 11726 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 11727 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 11728 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 11729 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11730 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11731 | MockRead reads1[] = { |
| 11732 | CreateMockRead(*conn_resp, 1), |
| 11733 | CreateMockRead(*wrapped_resp1, 3), |
| 11734 | CreateMockRead(*wrapped_body1, 4), |
| 11735 | CreateMockRead(*resp2, 6), |
| 11736 | CreateMockRead(*body2, 7), |
| 11737 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 11738 | }; |
| 11739 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11740 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 11741 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11742 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11743 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11744 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11745 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11746 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
| 11747 | CapturingNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11748 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11749 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11750 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11751 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11752 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11753 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11754 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11755 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11756 | |
| 11757 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11758 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11759 | |
| 11760 | // Start the first transaction to set up the SpdySession |
| 11761 | HttpRequestInfo request1; |
| 11762 | request1.method = "GET"; |
| 11763 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11764 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11765 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11766 | TestCompletionCallback callback1; |
| 11767 | EXPECT_EQ(ERR_IO_PENDING, |
| 11768 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11769 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11770 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11771 | |
| 11772 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11773 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11774 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11775 | LoadTimingInfo load_timing_info1; |
| 11776 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 11777 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 11778 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11779 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11780 | // Now, start the HTTP request |
| 11781 | HttpRequestInfo request2; |
| 11782 | request2.method = "GET"; |
| 11783 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11784 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11785 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11786 | TestCompletionCallback callback2; |
| 11787 | EXPECT_EQ(ERR_IO_PENDING, |
| 11788 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11789 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11790 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11791 | |
| 11792 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11793 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 11794 | |
| 11795 | LoadTimingInfo load_timing_info2; |
| 11796 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 11797 | // The established SPDY sessions is considered reused by the HTTP request. |
| 11798 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 11799 | // HTTP requests over a SPDY session should have a different connection |
| 11800 | // socket_log_id than requests over a tunnel. |
| 11801 | 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] | 11802 | } |
| 11803 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11804 | TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11805 | session_deps_.force_spdy_always = true; |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11806 | const std::string https_url = "https://www.google.com:8080/"; |
| 11807 | const std::string http_url = "http://www.google.com:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11808 | |
| 11809 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11810 | scoped_ptr<SpdyFrame> req1( |
| 11811 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11812 | // SPDY GET for the HTTP URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11813 | scoped_ptr<SpdyFrame> req2( |
| 11814 | spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11815 | |
| 11816 | MockWrite writes[] = { |
| 11817 | CreateMockWrite(*req1, 1), |
| 11818 | CreateMockWrite(*req2, 4), |
| 11819 | }; |
| 11820 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11821 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11822 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11823 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11824 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11825 | MockRead reads[] = { |
| 11826 | CreateMockRead(*resp1, 2), |
| 11827 | CreateMockRead(*body1, 3), |
| 11828 | CreateMockRead(*resp2, 5), |
| 11829 | CreateMockRead(*body2, 6), |
| 11830 | MockRead(ASYNC, ERR_IO_PENDING, 7) |
| 11831 | }; |
| 11832 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11833 | OrderedSocketData data(reads, arraysize(reads), |
| 11834 | writes, arraysize(writes)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11835 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11836 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11837 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11838 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11839 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11840 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11841 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11842 | |
| 11843 | // Start the first transaction to set up the SpdySession |
| 11844 | HttpRequestInfo request1; |
| 11845 | request1.method = "GET"; |
| 11846 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11847 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11848 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11849 | TestCompletionCallback callback1; |
| 11850 | EXPECT_EQ(ERR_IO_PENDING, |
| 11851 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11852 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11853 | |
| 11854 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11855 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11856 | |
| 11857 | // Now, start the HTTP request |
| 11858 | HttpRequestInfo request2; |
| 11859 | request2.method = "GET"; |
| 11860 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11861 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11862 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11863 | TestCompletionCallback callback2; |
| 11864 | EXPECT_EQ(ERR_IO_PENDING, |
| 11865 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11866 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11867 | |
| 11868 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11869 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11870 | } |
| 11871 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11872 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 11873 | // that we do not pool other origins that resolve to the same IP when |
| 11874 | // the certificate does not match the new origin. |
| 11875 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11876 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11877 | const std::string url1 = "http://www.google.com/"; |
| 11878 | const std::string url2 = "https://mail.google.com/"; |
| 11879 | const std::string ip_addr = "1.2.3.4"; |
| 11880 | |
| 11881 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11882 | scoped_ptr<SpdyHeaderBlock> headers( |
| 11883 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 11884 | scoped_ptr<SpdyFrame> req1( |
| 11885 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11886 | |
| 11887 | MockWrite writes1[] = { |
| 11888 | CreateMockWrite(*req1, 0), |
| 11889 | }; |
| 11890 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11891 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11892 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11893 | MockRead reads1[] = { |
| 11894 | CreateMockRead(*resp1, 1), |
| 11895 | CreateMockRead(*body1, 2), |
| 11896 | MockRead(ASYNC, OK, 3) // EOF |
| 11897 | }; |
| 11898 | |
| 11899 | scoped_ptr<DeterministicSocketData> data1( |
| 11900 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 11901 | writes1, arraysize(writes1))); |
| 11902 | IPAddressNumber ip; |
| 11903 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 11904 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11905 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 11906 | data1->set_connect_data(connect_data1); |
| 11907 | |
| 11908 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11909 | scoped_ptr<SpdyFrame> req2( |
| 11910 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11911 | |
| 11912 | MockWrite writes2[] = { |
| 11913 | CreateMockWrite(*req2, 0), |
| 11914 | }; |
| 11915 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11916 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11917 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11918 | MockRead reads2[] = { |
| 11919 | CreateMockRead(*resp2, 1), |
| 11920 | CreateMockRead(*body2, 2), |
| 11921 | MockRead(ASYNC, OK, 3) // EOF |
| 11922 | }; |
| 11923 | |
| 11924 | scoped_ptr<DeterministicSocketData> data2( |
| 11925 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 11926 | writes2, arraysize(writes2))); |
| 11927 | MockConnect connect_data2(ASYNC, OK); |
| 11928 | data2->set_connect_data(connect_data2); |
| 11929 | |
| 11930 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 11931 | // all others direct. |
| 11932 | ProxyConfig proxy_config; |
| 11933 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 11934 | CapturingProxyResolver* capturing_proxy_resolver = |
| 11935 | new CapturingProxyResolver(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11936 | session_deps_.proxy_service.reset(new ProxyService( |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11937 | new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 11938 | NULL)); |
| 11939 | |
| 11940 | // Load a valid cert. Note, that this does not need to |
| 11941 | // be valid for proxy because the MockSSLClientSocket does |
| 11942 | // not actually verify it. But SpdySession will use this |
| 11943 | // to see if it is valid for the new origin |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11944 | base::FilePath certs_dir = GetTestCertsDirectory(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11945 | scoped_refptr<X509Certificate> server_cert( |
| 11946 | ImportCertFromFile(certs_dir, "ok_cert.pem")); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11947 | ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11948 | |
| 11949 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11950 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11951 | ssl1.cert = server_cert; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11952 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 11953 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11954 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11955 | |
| 11956 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11957 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11958 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 11959 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 11960 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11961 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11962 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11963 | session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 11964 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11965 | |
| 11966 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11967 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11968 | |
| 11969 | // Start the first transaction to set up the SpdySession |
| 11970 | HttpRequestInfo request1; |
| 11971 | request1.method = "GET"; |
| 11972 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11973 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11974 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11975 | TestCompletionCallback callback1; |
| 11976 | ASSERT_EQ(ERR_IO_PENDING, |
| 11977 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 11978 | data1->RunFor(3); |
| 11979 | |
| 11980 | ASSERT_TRUE(callback1.have_result()); |
| 11981 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11982 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11983 | |
| 11984 | // Now, start the HTTP request |
| 11985 | HttpRequestInfo request2; |
| 11986 | request2.method = "GET"; |
| 11987 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11988 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11989 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11990 | TestCompletionCallback callback2; |
| 11991 | EXPECT_EQ(ERR_IO_PENDING, |
| 11992 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11993 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 11994 | data2->RunFor(3); |
| 11995 | |
| 11996 | ASSERT_TRUE(callback2.have_result()); |
| 11997 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11998 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11999 | } |
| 12000 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12001 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12002 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12003 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12004 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12005 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12006 | const std::string https_url = "https://www.google.com/"; |
| 12007 | |
| 12008 | MockRead reads1[] = { |
| 12009 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12010 | }; |
| 12011 | |
| 12012 | scoped_ptr<DeterministicSocketData> data1( |
| 12013 | new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0)); |
| 12014 | data1->SetStop(1); |
| 12015 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12016 | scoped_ptr<SpdyFrame> req2( |
| 12017 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12018 | MockWrite writes2[] = { |
| 12019 | CreateMockWrite(*req2, 0), |
| 12020 | }; |
| 12021 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12022 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12023 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12024 | MockRead reads2[] = { |
| 12025 | CreateMockRead(*resp2, 1), |
| 12026 | CreateMockRead(*body2, 2), |
| 12027 | MockRead(ASYNC, OK, 3) // EOF |
| 12028 | }; |
| 12029 | |
| 12030 | scoped_ptr<DeterministicSocketData> data2( |
| 12031 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12032 | writes2, arraysize(writes2))); |
| 12033 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12034 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12035 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12036 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12037 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12038 | data1.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12039 | |
| 12040 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12041 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12042 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12043 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12044 | data2.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12045 | |
| 12046 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12047 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12048 | |
| 12049 | // Start the first transaction to set up the SpdySession and verify that |
| 12050 | // connection was closed. |
| 12051 | HttpRequestInfo request1; |
| 12052 | request1.method = "GET"; |
| 12053 | request1.url = GURL(https_url); |
| 12054 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12055 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12056 | TestCompletionCallback callback1; |
| 12057 | EXPECT_EQ(ERR_IO_PENDING, |
| 12058 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12059 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12060 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12061 | |
| 12062 | // Now, start the second request and make sure it succeeds. |
| 12063 | HttpRequestInfo request2; |
| 12064 | request2.method = "GET"; |
| 12065 | request2.url = GURL(https_url); |
| 12066 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12067 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12068 | TestCompletionCallback callback2; |
| 12069 | EXPECT_EQ(ERR_IO_PENDING, |
| 12070 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12071 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12072 | data2->RunFor(3); |
| 12073 | |
| 12074 | ASSERT_TRUE(callback2.have_result()); |
| 12075 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12076 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12077 | } |
| 12078 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12079 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12080 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12081 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12082 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12083 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12084 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12085 | |
| 12086 | // Use two different hosts with different IPs so they don't get pooled. |
| 12087 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12088 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 12089 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12090 | |
| 12091 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12092 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12093 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12094 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12095 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12097 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12098 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12099 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12100 | MockWrite spdy1_writes[] = { |
| 12101 | CreateMockWrite(*host1_req, 1), |
| 12102 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12103 | scoped_ptr<SpdyFrame> host1_resp( |
| 12104 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12105 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12106 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12107 | MockRead spdy1_reads[] = { |
| 12108 | CreateMockRead(*host1_resp, 2), |
| 12109 | CreateMockRead(*host1_resp_body, 3), |
| 12110 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 12111 | }; |
| 12112 | |
| 12113 | scoped_ptr<OrderedSocketData> spdy1_data( |
| 12114 | new OrderedSocketData( |
| 12115 | spdy1_reads, arraysize(spdy1_reads), |
| 12116 | spdy1_writes, arraysize(spdy1_writes))); |
| 12117 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12118 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12119 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12120 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12121 | MockWrite spdy2_writes[] = { |
| 12122 | CreateMockWrite(*host2_req, 1), |
| 12123 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12124 | scoped_ptr<SpdyFrame> host2_resp( |
| 12125 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12126 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12127 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12128 | MockRead spdy2_reads[] = { |
| 12129 | CreateMockRead(*host2_resp, 2), |
| 12130 | CreateMockRead(*host2_resp_body, 3), |
| 12131 | MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 12132 | }; |
| 12133 | |
| 12134 | scoped_ptr<OrderedSocketData> spdy2_data( |
| 12135 | new OrderedSocketData( |
| 12136 | spdy2_reads, arraysize(spdy2_reads), |
| 12137 | spdy2_writes, arraysize(spdy2_writes))); |
| 12138 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12139 | |
| 12140 | MockWrite http_write[] = { |
| 12141 | MockWrite("GET / HTTP/1.1\r\n" |
| 12142 | "Host: www.a.com\r\n" |
| 12143 | "Connection: keep-alive\r\n\r\n"), |
| 12144 | }; |
| 12145 | |
| 12146 | MockRead http_read[] = { |
| 12147 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12148 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12149 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12150 | MockRead("hello!"), |
| 12151 | }; |
| 12152 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12153 | http_write, arraysize(http_write)); |
| 12154 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12155 | |
| 12156 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12157 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12158 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12159 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12160 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12161 | |
| 12162 | TestCompletionCallback callback; |
| 12163 | HttpRequestInfo request1; |
| 12164 | request1.method = "GET"; |
| 12165 | request1.url = GURL("https://www.a.com/"); |
| 12166 | request1.load_flags = 0; |
| 12167 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12169 | |
| 12170 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 12171 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12172 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12173 | |
| 12174 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12175 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12176 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12177 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12178 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12179 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12180 | |
| 12181 | std::string response_data; |
| 12182 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12183 | EXPECT_EQ("hello!", response_data); |
| 12184 | trans.reset(); |
| 12185 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12186 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12187 | |
| 12188 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12189 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12190 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12191 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12192 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12193 | HttpRequestInfo request2; |
| 12194 | request2.method = "GET"; |
| 12195 | request2.url = GURL("https://www.b.com/"); |
| 12196 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12197 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12198 | |
| 12199 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 12200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12201 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12202 | |
| 12203 | response = trans->GetResponseInfo(); |
| 12204 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12205 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12206 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12207 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12208 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12209 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12210 | EXPECT_EQ("hello!", response_data); |
| 12211 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12212 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12213 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12214 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12215 | |
| 12216 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12217 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12218 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12219 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12220 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12221 | HttpRequestInfo request3; |
| 12222 | request3.method = "GET"; |
| 12223 | request3.url = GURL("http://www.a.com/"); |
| 12224 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12225 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12226 | |
| 12227 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 12228 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12229 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12230 | |
| 12231 | response = trans->GetResponseInfo(); |
| 12232 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12233 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12234 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12235 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12236 | EXPECT_FALSE(response->was_npn_negotiated); |
| 12237 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12238 | EXPECT_EQ("hello!", response_data); |
| 12239 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12240 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12241 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12242 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12243 | } |
| 12244 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12245 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 12246 | HttpRequestInfo request; |
| 12247 | request.method = "GET"; |
| 12248 | request.url = GURL("http://www.google.com/"); |
| 12249 | request.load_flags = 0; |
| 12250 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12251 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12252 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12253 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12254 | |
| 12255 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 12256 | StaticSocketDataProvider data; |
| 12257 | data.set_connect_data(mock_connect); |
| 12258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12259 | |
| 12260 | TestCompletionCallback callback; |
| 12261 | |
| 12262 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12264 | |
| 12265 | rv = callback.WaitForResult(); |
| 12266 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12267 | |
| 12268 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12269 | |
| 12270 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12271 | HttpRequestHeaders request_headers; |
| 12272 | trans->GetFullRequestHeaders(&request_headers); |
| 12273 | } |
| 12274 | |
| 12275 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 12276 | HttpRequestInfo request; |
| 12277 | request.method = "GET"; |
| 12278 | request.url = GURL("http://www.google.com/"); |
| 12279 | request.load_flags = 0; |
| 12280 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12281 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12282 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12283 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12284 | |
| 12285 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12286 | StaticSocketDataProvider data; |
| 12287 | data.set_connect_data(mock_connect); |
| 12288 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12289 | |
| 12290 | TestCompletionCallback callback; |
| 12291 | |
| 12292 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12294 | |
| 12295 | rv = callback.WaitForResult(); |
| 12296 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12297 | |
| 12298 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12299 | |
| 12300 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12301 | HttpRequestHeaders request_headers; |
| 12302 | trans->GetFullRequestHeaders(&request_headers); |
| 12303 | } |
| 12304 | |
| 12305 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12306 | HttpRequestInfo request; |
| 12307 | request.method = "GET"; |
| 12308 | request.url = GURL("http://www.google.com/"); |
| 12309 | request.load_flags = 0; |
| 12310 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12311 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12312 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12313 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12314 | |
| 12315 | MockWrite data_writes[] = { |
| 12316 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12317 | }; |
| 12318 | MockRead data_reads[] = { |
| 12319 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12320 | }; |
| 12321 | |
| 12322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12323 | data_writes, arraysize(data_writes)); |
| 12324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12325 | |
| 12326 | TestCompletionCallback callback; |
| 12327 | |
| 12328 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12329 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12330 | |
| 12331 | rv = callback.WaitForResult(); |
| 12332 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12333 | |
| 12334 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12335 | |
| 12336 | HttpRequestHeaders request_headers; |
| 12337 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12338 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12339 | } |
| 12340 | |
| 12341 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12342 | HttpRequestInfo request; |
| 12343 | request.method = "GET"; |
| 12344 | request.url = GURL("http://www.google.com/"); |
| 12345 | request.load_flags = 0; |
| 12346 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12347 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12348 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12349 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12350 | |
| 12351 | MockWrite data_writes[] = { |
| 12352 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12353 | }; |
| 12354 | MockRead data_reads[] = { |
| 12355 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12356 | }; |
| 12357 | |
| 12358 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12359 | data_writes, arraysize(data_writes)); |
| 12360 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12361 | |
| 12362 | TestCompletionCallback callback; |
| 12363 | |
| 12364 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12365 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12366 | |
| 12367 | rv = callback.WaitForResult(); |
| 12368 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12369 | |
| 12370 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12371 | |
| 12372 | HttpRequestHeaders request_headers; |
| 12373 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12374 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12375 | } |
| 12376 | |
| 12377 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12378 | HttpRequestInfo request; |
| 12379 | request.method = "GET"; |
| 12380 | request.url = GURL("http://www.google.com/"); |
| 12381 | request.load_flags = 0; |
| 12382 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12383 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12384 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12386 | |
| 12387 | MockWrite data_writes[] = { |
| 12388 | MockWrite("GET / HTTP/1.1\r\n" |
| 12389 | "Host: www.google.com\r\n" |
| 12390 | "Connection: keep-alive\r\n\r\n"), |
| 12391 | }; |
| 12392 | MockRead data_reads[] = { |
| 12393 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12394 | }; |
| 12395 | |
| 12396 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12397 | data_writes, arraysize(data_writes)); |
| 12398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12399 | |
| 12400 | TestCompletionCallback callback; |
| 12401 | |
| 12402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12403 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12404 | |
| 12405 | rv = callback.WaitForResult(); |
| 12406 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12407 | |
| 12408 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12409 | |
| 12410 | HttpRequestHeaders request_headers; |
| 12411 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12412 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12413 | } |
| 12414 | |
| 12415 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 12416 | HttpRequestInfo request; |
| 12417 | request.method = "GET"; |
| 12418 | request.url = GURL("http://www.google.com/"); |
| 12419 | request.load_flags = 0; |
| 12420 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12421 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12422 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12424 | |
| 12425 | MockWrite data_writes[] = { |
| 12426 | MockWrite("GET / HTTP/1.1\r\n" |
| 12427 | "Host: www.google.com\r\n" |
| 12428 | "Connection: keep-alive\r\n\r\n"), |
| 12429 | }; |
| 12430 | MockRead data_reads[] = { |
| 12431 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 12432 | }; |
| 12433 | |
| 12434 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12435 | data_writes, arraysize(data_writes)); |
| 12436 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12437 | |
| 12438 | TestCompletionCallback callback; |
| 12439 | |
| 12440 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12442 | |
| 12443 | rv = callback.WaitForResult(); |
| 12444 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12445 | |
| 12446 | EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 12447 | |
| 12448 | HttpRequestHeaders request_headers; |
| 12449 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12450 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12451 | } |
| 12452 | |
| 12453 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 12454 | HttpRequestInfo request; |
| 12455 | request.method = "GET"; |
| 12456 | request.url = GURL("http://www.google.com/"); |
| 12457 | request.load_flags = 0; |
| 12458 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 12459 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12460 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12461 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12462 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12463 | |
| 12464 | MockWrite data_writes[] = { |
| 12465 | MockWrite("GET / HTTP/1.1\r\n" |
| 12466 | "Host: www.google.com\r\n" |
| 12467 | "Connection: keep-alive\r\n" |
| 12468 | "X-Foo: bar\r\n\r\n"), |
| 12469 | }; |
| 12470 | MockRead data_reads[] = { |
| 12471 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12472 | "Content-Length: 5\r\n\r\n" |
| 12473 | "hello"), |
| 12474 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 12475 | }; |
| 12476 | |
| 12477 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12478 | data_writes, arraysize(data_writes)); |
| 12479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12480 | |
| 12481 | TestCompletionCallback callback; |
| 12482 | |
| 12483 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12484 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12485 | |
| 12486 | rv = callback.WaitForResult(); |
| 12487 | EXPECT_EQ(OK, rv); |
| 12488 | |
| 12489 | HttpRequestHeaders request_headers; |
| 12490 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12491 | std::string foo; |
| 12492 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 12493 | EXPECT_EQ("bar", foo); |
| 12494 | } |
| 12495 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12496 | namespace { |
| 12497 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12498 | // Fake HttpStream that simply records calls to SetPriority(). |
| 12499 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12500 | public base::SupportsWeakPtr<FakeStream> { |
| 12501 | public: |
| 12502 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12503 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12504 | |
| 12505 | RequestPriority priority() const { return priority_; } |
| 12506 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12507 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12508 | RequestPriority priority, |
| 12509 | const BoundNetLog& net_log, |
| 12510 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12511 | return ERR_IO_PENDING; |
| 12512 | } |
| 12513 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12514 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12515 | HttpResponseInfo* response, |
| 12516 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12517 | ADD_FAILURE(); |
| 12518 | return ERR_UNEXPECTED; |
| 12519 | } |
| 12520 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12521 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12522 | ADD_FAILURE(); |
| 12523 | return ERR_UNEXPECTED; |
| 12524 | } |
| 12525 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12526 | int ReadResponseBody(IOBuffer* buf, |
| 12527 | int buf_len, |
| 12528 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12529 | ADD_FAILURE(); |
| 12530 | return ERR_UNEXPECTED; |
| 12531 | } |
| 12532 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12533 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12534 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12535 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12536 | ADD_FAILURE(); |
| 12537 | return false; |
| 12538 | } |
| 12539 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12540 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12541 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12542 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12543 | ADD_FAILURE(); |
| 12544 | return false; |
| 12545 | } |
| 12546 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12547 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12548 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12549 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12550 | ADD_FAILURE(); |
| 12551 | return false; |
| 12552 | } |
| 12553 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12554 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 12555 | ADD_FAILURE(); |
| 12556 | return 0; |
| 12557 | } |
| 12558 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12559 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12560 | ADD_FAILURE(); |
| 12561 | return false; |
| 12562 | } |
| 12563 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12564 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 12565 | |
| 12566 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12567 | ADD_FAILURE(); |
| 12568 | } |
| 12569 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12570 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12571 | ADD_FAILURE(); |
| 12572 | return false; |
| 12573 | } |
| 12574 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12575 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12576 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12577 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12578 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 12579 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 12580 | |
| 12581 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 12582 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12583 | private: |
| 12584 | RequestPriority priority_; |
| 12585 | |
| 12586 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 12587 | }; |
| 12588 | |
| 12589 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 12590 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12591 | class FakeStreamRequest : public HttpStreamRequest, |
| 12592 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 12593 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12594 | FakeStreamRequest(RequestPriority priority, |
| 12595 | HttpStreamRequest::Delegate* delegate) |
| 12596 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12597 | delegate_(delegate), |
| 12598 | websocket_stream_create_helper_(NULL) {} |
| 12599 | |
| 12600 | FakeStreamRequest(RequestPriority priority, |
| 12601 | HttpStreamRequest::Delegate* delegate, |
| 12602 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 12603 | : priority_(priority), |
| 12604 | delegate_(delegate), |
| 12605 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12606 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12607 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12608 | |
| 12609 | RequestPriority priority() const { return priority_; } |
| 12610 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12611 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 12612 | websocket_stream_create_helper() const { |
| 12613 | return websocket_stream_create_helper_; |
| 12614 | } |
| 12615 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12616 | // Create a new FakeStream and pass it to the request's |
| 12617 | // delegate. Returns a weak pointer to the FakeStream. |
| 12618 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 12619 | FakeStream* fake_stream = new FakeStream(priority_); |
| 12620 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 12621 | // immediately delete |fake_stream|. |
| 12622 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 12623 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 12624 | return weak_stream; |
| 12625 | } |
| 12626 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12627 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12628 | ADD_FAILURE(); |
| 12629 | return ERR_UNEXPECTED; |
| 12630 | } |
| 12631 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12632 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12633 | ADD_FAILURE(); |
| 12634 | return LoadState(); |
| 12635 | } |
| 12636 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12637 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12638 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12639 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12640 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12641 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12642 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12643 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12644 | |
| 12645 | private: |
| 12646 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12647 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12648 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12649 | |
| 12650 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 12651 | }; |
| 12652 | |
| 12653 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 12654 | class FakeStreamFactory : public HttpStreamFactory { |
| 12655 | public: |
| 12656 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12657 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12658 | |
| 12659 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 12660 | // RequestStream() (which may be NULL if it was destroyed already). |
| 12661 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 12662 | return last_stream_request_; |
| 12663 | } |
| 12664 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12665 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 12666 | RequestPriority priority, |
| 12667 | const SSLConfig& server_ssl_config, |
| 12668 | const SSLConfig& proxy_ssl_config, |
| 12669 | HttpStreamRequest::Delegate* delegate, |
| 12670 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12671 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12672 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12673 | return fake_request; |
| 12674 | } |
| 12675 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12676 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12677 | const HttpRequestInfo& info, |
| 12678 | RequestPriority priority, |
| 12679 | const SSLConfig& server_ssl_config, |
| 12680 | const SSLConfig& proxy_ssl_config, |
| 12681 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 12682 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12683 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12684 | FakeStreamRequest* fake_request = |
| 12685 | new FakeStreamRequest(priority, delegate, create_helper); |
| 12686 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 12687 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12688 | } |
| 12689 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12690 | void PreconnectStreams(int num_streams, |
| 12691 | const HttpRequestInfo& info, |
| 12692 | RequestPriority priority, |
| 12693 | const SSLConfig& server_ssl_config, |
| 12694 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12695 | ADD_FAILURE(); |
| 12696 | } |
| 12697 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12698 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12699 | ADD_FAILURE(); |
| 12700 | return NULL; |
| 12701 | } |
| 12702 | |
| 12703 | private: |
| 12704 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 12705 | |
| 12706 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 12707 | }; |
| 12708 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12709 | // TODO(ricea): Maybe unify this with the one in |
| 12710 | // url_request_http_job_unittest.cc ? |
| 12711 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 12712 | public: |
| 12713 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 12714 | bool using_proxy) |
| 12715 | : state_(connection.release(), using_proxy) {} |
| 12716 | |
| 12717 | // Fake implementation of HttpStreamBase methods. |
| 12718 | // This ends up being quite "real" because this object has to really send data |
| 12719 | // on the mock socket. It might be easier to use the real implementation, but |
| 12720 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 12721 | // difficult. |
| 12722 | int InitializeStream(const HttpRequestInfo* request_info, |
| 12723 | RequestPriority priority, |
| 12724 | const BoundNetLog& net_log, |
| 12725 | const CompletionCallback& callback) override { |
| 12726 | state_.Initialize(request_info, priority, net_log, callback); |
| 12727 | return OK; |
| 12728 | } |
| 12729 | |
| 12730 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 12731 | HttpResponseInfo* response, |
| 12732 | const CompletionCallback& callback) override { |
| 12733 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 12734 | response, callback); |
| 12735 | } |
| 12736 | |
| 12737 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 12738 | return parser()->ReadResponseHeaders(callback); |
| 12739 | } |
| 12740 | |
| 12741 | int ReadResponseBody(IOBuffer* buf, |
| 12742 | int buf_len, |
| 12743 | const CompletionCallback& callback) override { |
| 12744 | NOTREACHED(); |
| 12745 | return ERR_IO_PENDING; |
| 12746 | } |
| 12747 | |
| 12748 | void Close(bool not_reusable) override { |
| 12749 | if (parser()) |
| 12750 | parser()->Close(true); |
| 12751 | } |
| 12752 | |
| 12753 | bool IsResponseBodyComplete() const override { |
| 12754 | NOTREACHED(); |
| 12755 | return false; |
| 12756 | } |
| 12757 | |
| 12758 | bool CanFindEndOfResponse() const override { |
| 12759 | return parser()->CanFindEndOfResponse(); |
| 12760 | } |
| 12761 | |
| 12762 | bool IsConnectionReused() const override { |
| 12763 | NOTREACHED(); |
| 12764 | return false; |
| 12765 | } |
| 12766 | void SetConnectionReused() override { NOTREACHED(); } |
| 12767 | |
| 12768 | bool IsConnectionReusable() const override { |
| 12769 | NOTREACHED(); |
| 12770 | return false; |
| 12771 | } |
| 12772 | |
| 12773 | int64 GetTotalReceivedBytes() const override { |
| 12774 | NOTREACHED(); |
| 12775 | return 0; |
| 12776 | } |
| 12777 | |
| 12778 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 12779 | NOTREACHED(); |
| 12780 | return false; |
| 12781 | } |
| 12782 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 12783 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12784 | |
| 12785 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 12786 | NOTREACHED(); |
| 12787 | } |
| 12788 | |
| 12789 | bool IsSpdyHttpStream() const override { |
| 12790 | NOTREACHED(); |
| 12791 | return false; |
| 12792 | } |
| 12793 | |
| 12794 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 12795 | |
| 12796 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 12797 | |
| 12798 | UploadProgress GetUploadProgress() const override { |
| 12799 | NOTREACHED(); |
| 12800 | return UploadProgress(); |
| 12801 | } |
| 12802 | |
| 12803 | HttpStream* RenewStreamForAuth() override { |
| 12804 | NOTREACHED(); |
| 12805 | return nullptr; |
| 12806 | } |
| 12807 | |
| 12808 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 12809 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 12810 | NOTREACHED(); |
| 12811 | return scoped_ptr<WebSocketStream>(); |
| 12812 | } |
| 12813 | |
| 12814 | private: |
| 12815 | HttpStreamParser* parser() const { return state_.parser(); } |
| 12816 | HttpBasicState state_; |
| 12817 | |
| 12818 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 12819 | }; |
| 12820 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12821 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 12822 | // worth doing. |
| 12823 | class FakeWebSocketStreamCreateHelper : |
| 12824 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 12825 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12826 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 12827 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12828 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 12829 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 12830 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12831 | } |
| 12832 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12833 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12834 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 12835 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12836 | NOTREACHED(); |
| 12837 | return NULL; |
| 12838 | }; |
| 12839 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12840 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12841 | |
| 12842 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 12843 | NOTREACHED(); |
| 12844 | return scoped_ptr<WebSocketStream>(); |
| 12845 | } |
| 12846 | }; |
| 12847 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12848 | } // namespace |
| 12849 | |
| 12850 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 12851 | // stream request on start. |
| 12852 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 12853 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12854 | HttpNetworkSessionPeer peer(session); |
| 12855 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12856 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12857 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12858 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12859 | |
| 12860 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 12861 | |
| 12862 | HttpRequestInfo request; |
| 12863 | TestCompletionCallback callback; |
| 12864 | EXPECT_EQ(ERR_IO_PENDING, |
| 12865 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12866 | |
| 12867 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12868 | fake_factory->last_stream_request(); |
| 12869 | ASSERT_TRUE(fake_request != NULL); |
| 12870 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12871 | } |
| 12872 | |
| 12873 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12874 | // updates to its stream request. |
| 12875 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 12876 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12877 | HttpNetworkSessionPeer peer(session); |
| 12878 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12879 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12880 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12881 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 12882 | |
| 12883 | HttpRequestInfo request; |
| 12884 | TestCompletionCallback callback; |
| 12885 | EXPECT_EQ(ERR_IO_PENDING, |
| 12886 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12887 | |
| 12888 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12889 | fake_factory->last_stream_request(); |
| 12890 | ASSERT_TRUE(fake_request != NULL); |
| 12891 | EXPECT_EQ(LOW, fake_request->priority()); |
| 12892 | |
| 12893 | trans.SetPriority(LOWEST); |
| 12894 | ASSERT_TRUE(fake_request != NULL); |
| 12895 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 12896 | } |
| 12897 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12898 | // Make sure that HttpNetworkTransaction passes on its priority |
| 12899 | // updates to its stream. |
| 12900 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 12901 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12902 | HttpNetworkSessionPeer peer(session); |
| 12903 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12904 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12905 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12906 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 12907 | |
| 12908 | HttpRequestInfo request; |
| 12909 | TestCompletionCallback callback; |
| 12910 | EXPECT_EQ(ERR_IO_PENDING, |
| 12911 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12912 | |
| 12913 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12914 | fake_factory->last_stream_request(); |
| 12915 | ASSERT_TRUE(fake_request != NULL); |
| 12916 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 12917 | ASSERT_TRUE(fake_stream != NULL); |
| 12918 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 12919 | |
| 12920 | trans.SetPriority(LOWEST); |
| 12921 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 12922 | } |
| 12923 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12924 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 12925 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 12926 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 12927 | // that the different schemes work. |
| 12928 | std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"}; |
| 12929 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 12930 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12931 | HttpNetworkSessionPeer peer(session); |
| 12932 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 12933 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 12934 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12935 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 12936 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12937 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 12938 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 12939 | &websocket_stream_create_helper); |
| 12940 | |
| 12941 | HttpRequestInfo request; |
| 12942 | TestCompletionCallback callback; |
| 12943 | request.method = "GET"; |
| 12944 | request.url = GURL(test_cases[i]); |
| 12945 | |
| 12946 | EXPECT_EQ(ERR_IO_PENDING, |
| 12947 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 12948 | |
| 12949 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 12950 | fake_factory->last_stream_request(); |
| 12951 | ASSERT_TRUE(fake_request != NULL); |
| 12952 | EXPECT_EQ(&websocket_stream_create_helper, |
| 12953 | fake_request->websocket_stream_create_helper()); |
| 12954 | } |
| 12955 | } |
| 12956 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 12957 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 12958 | // if the transport socket pool is stalled on the global socket limit. |
| 12959 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 12960 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12961 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12962 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12963 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12964 | |
| 12965 | // Set up SSL request. |
| 12966 | |
| 12967 | HttpRequestInfo ssl_request; |
| 12968 | ssl_request.method = "GET"; |
| 12969 | ssl_request.url = GURL("https://www.google.com/"); |
| 12970 | |
| 12971 | MockWrite ssl_writes[] = { |
| 12972 | MockWrite("GET / HTTP/1.1\r\n" |
| 12973 | "Host: www.google.com\r\n" |
| 12974 | "Connection: keep-alive\r\n\r\n"), |
| 12975 | }; |
| 12976 | MockRead ssl_reads[] = { |
| 12977 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12978 | MockRead("Content-Length: 11\r\n\r\n"), |
| 12979 | MockRead("hello world"), |
| 12980 | MockRead(SYNCHRONOUS, OK), |
| 12981 | }; |
| 12982 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 12983 | ssl_writes, arraysize(ssl_writes)); |
| 12984 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 12985 | |
| 12986 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12987 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12988 | |
| 12989 | // Set up HTTP request. |
| 12990 | |
| 12991 | HttpRequestInfo http_request; |
| 12992 | http_request.method = "GET"; |
| 12993 | http_request.url = GURL("http://www.google.com/"); |
| 12994 | |
| 12995 | MockWrite http_writes[] = { |
| 12996 | MockWrite("GET / HTTP/1.1\r\n" |
| 12997 | "Host: www.google.com\r\n" |
| 12998 | "Connection: keep-alive\r\n\r\n"), |
| 12999 | }; |
| 13000 | MockRead http_reads[] = { |
| 13001 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13002 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13003 | MockRead("falafel"), |
| 13004 | MockRead(SYNCHRONOUS, OK), |
| 13005 | }; |
| 13006 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13007 | http_writes, arraysize(http_writes)); |
| 13008 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13009 | |
| 13010 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13011 | |
| 13012 | // Start the SSL request. |
| 13013 | TestCompletionCallback ssl_callback; |
| 13014 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13015 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13016 | ASSERT_EQ(ERR_IO_PENDING, |
| 13017 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13018 | BoundNetLog())); |
| 13019 | |
| 13020 | // Start the HTTP request. Pool should stall. |
| 13021 | TestCompletionCallback http_callback; |
| 13022 | scoped_ptr<HttpTransaction> http_trans( |
| 13023 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13024 | ASSERT_EQ(ERR_IO_PENDING, |
| 13025 | http_trans->Start(&http_request, http_callback.callback(), |
| 13026 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13027 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13028 | |
| 13029 | // Wait for response from SSL request. |
| 13030 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13031 | std::string response_data; |
| 13032 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13033 | EXPECT_EQ("hello world", response_data); |
| 13034 | |
| 13035 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13036 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13037 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13038 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13039 | |
| 13040 | // The HTTP request can now complete. |
| 13041 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13042 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13043 | EXPECT_EQ("falafel", response_data); |
| 13044 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13045 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13046 | } |
| 13047 | |
| 13048 | // Tests that when a SSL connection is established but there's no corresponding |
| 13049 | // request that needs it, the new socket is closed if the transport socket pool |
| 13050 | // is stalled on the global socket limit. |
| 13051 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13052 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13053 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13054 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13055 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13056 | |
| 13057 | // Set up an ssl request. |
| 13058 | |
| 13059 | HttpRequestInfo ssl_request; |
| 13060 | ssl_request.method = "GET"; |
| 13061 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13062 | |
| 13063 | // No data will be sent on the SSL socket. |
| 13064 | StaticSocketDataProvider ssl_data; |
| 13065 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13066 | |
| 13067 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13069 | |
| 13070 | // Set up HTTP request. |
| 13071 | |
| 13072 | HttpRequestInfo http_request; |
| 13073 | http_request.method = "GET"; |
| 13074 | http_request.url = GURL("http://www.google.com/"); |
| 13075 | |
| 13076 | MockWrite http_writes[] = { |
| 13077 | MockWrite("GET / HTTP/1.1\r\n" |
| 13078 | "Host: www.google.com\r\n" |
| 13079 | "Connection: keep-alive\r\n\r\n"), |
| 13080 | }; |
| 13081 | MockRead http_reads[] = { |
| 13082 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13083 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13084 | MockRead("falafel"), |
| 13085 | MockRead(SYNCHRONOUS, OK), |
| 13086 | }; |
| 13087 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13088 | http_writes, arraysize(http_writes)); |
| 13089 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13090 | |
| 13091 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13092 | |
| 13093 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13094 | // cancelled when a normal transaction is cancelled. |
| 13095 | net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13096 | net::SSLConfig ssl_config; |
| 13097 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 13098 | http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY, |
| 13099 | ssl_config, ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13100 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13101 | |
| 13102 | // Start the HTTP request. Pool should stall. |
| 13103 | TestCompletionCallback http_callback; |
| 13104 | scoped_ptr<HttpTransaction> http_trans( |
| 13105 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13106 | ASSERT_EQ(ERR_IO_PENDING, |
| 13107 | http_trans->Start(&http_request, http_callback.callback(), |
| 13108 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13109 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13110 | |
| 13111 | // The SSL connection will automatically be closed once the connection is |
| 13112 | // established, to let the HTTP request start. |
| 13113 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13114 | std::string response_data; |
| 13115 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13116 | EXPECT_EQ("falafel", response_data); |
| 13117 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13118 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13119 | } |
| 13120 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13121 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13122 | ScopedVector<UploadElementReader> element_readers; |
| 13123 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13124 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13125 | |
| 13126 | HttpRequestInfo request; |
| 13127 | request.method = "POST"; |
| 13128 | request.url = GURL("http://www.foo.com/"); |
| 13129 | request.upload_data_stream = &upload_data_stream; |
| 13130 | request.load_flags = 0; |
| 13131 | |
| 13132 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13133 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13134 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13135 | // Send headers successfully, but get an error while sending the body. |
| 13136 | MockWrite data_writes[] = { |
| 13137 | MockWrite("POST / HTTP/1.1\r\n" |
| 13138 | "Host: www.foo.com\r\n" |
| 13139 | "Connection: keep-alive\r\n" |
| 13140 | "Content-Length: 3\r\n\r\n"), |
| 13141 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13142 | }; |
| 13143 | |
| 13144 | MockRead data_reads[] = { |
| 13145 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13146 | MockRead("hello world"), |
| 13147 | MockRead(SYNCHRONOUS, OK), |
| 13148 | }; |
| 13149 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13150 | arraysize(data_writes)); |
| 13151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13152 | |
| 13153 | TestCompletionCallback callback; |
| 13154 | |
| 13155 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13156 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13157 | |
| 13158 | rv = callback.WaitForResult(); |
| 13159 | EXPECT_EQ(OK, rv); |
| 13160 | |
| 13161 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13162 | ASSERT_TRUE(response != NULL); |
| 13163 | |
| 13164 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13165 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13166 | |
| 13167 | std::string response_data; |
| 13168 | rv = ReadTransaction(trans.get(), &response_data); |
| 13169 | EXPECT_EQ(OK, rv); |
| 13170 | EXPECT_EQ("hello world", response_data); |
| 13171 | } |
| 13172 | |
| 13173 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 13174 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 13175 | TEST_P(HttpNetworkTransactionTest, |
| 13176 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 13177 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13178 | MockWrite data_writes[] = { |
| 13179 | MockWrite("GET / HTTP/1.1\r\n" |
| 13180 | "Host: www.foo.com\r\n" |
| 13181 | "Connection: keep-alive\r\n\r\n"), |
| 13182 | MockWrite("POST / HTTP/1.1\r\n" |
| 13183 | "Host: www.foo.com\r\n" |
| 13184 | "Connection: keep-alive\r\n" |
| 13185 | "Content-Length: 3\r\n\r\n"), |
| 13186 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13187 | }; |
| 13188 | |
| 13189 | MockRead data_reads[] = { |
| 13190 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 13191 | "Content-Length: 14\r\n\r\n"), |
| 13192 | MockRead("first response"), |
| 13193 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 13194 | "Content-Length: 15\r\n\r\n"), |
| 13195 | MockRead("second response"), |
| 13196 | MockRead(SYNCHRONOUS, OK), |
| 13197 | }; |
| 13198 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13199 | arraysize(data_writes)); |
| 13200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13201 | |
| 13202 | TestCompletionCallback callback; |
| 13203 | HttpRequestInfo request1; |
| 13204 | request1.method = "GET"; |
| 13205 | request1.url = GURL("http://www.foo.com/"); |
| 13206 | request1.load_flags = 0; |
| 13207 | |
| 13208 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13210 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 13211 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13212 | |
| 13213 | rv = callback.WaitForResult(); |
| 13214 | EXPECT_EQ(OK, rv); |
| 13215 | |
| 13216 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13217 | ASSERT_TRUE(response1 != NULL); |
| 13218 | |
| 13219 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 13220 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 13221 | |
| 13222 | std::string response_data1; |
| 13223 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 13224 | EXPECT_EQ(OK, rv); |
| 13225 | EXPECT_EQ("first response", response_data1); |
| 13226 | // Delete the transaction to release the socket back into the socket pool. |
| 13227 | trans1.reset(); |
| 13228 | |
| 13229 | ScopedVector<UploadElementReader> element_readers; |
| 13230 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13231 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13232 | |
| 13233 | HttpRequestInfo request2; |
| 13234 | request2.method = "POST"; |
| 13235 | request2.url = GURL("http://www.foo.com/"); |
| 13236 | request2.upload_data_stream = &upload_data_stream; |
| 13237 | request2.load_flags = 0; |
| 13238 | |
| 13239 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13241 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 13242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13243 | |
| 13244 | rv = callback.WaitForResult(); |
| 13245 | EXPECT_EQ(OK, rv); |
| 13246 | |
| 13247 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 13248 | ASSERT_TRUE(response2 != NULL); |
| 13249 | |
| 13250 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 13251 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 13252 | |
| 13253 | std::string response_data2; |
| 13254 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 13255 | EXPECT_EQ(OK, rv); |
| 13256 | EXPECT_EQ("second response", response_data2); |
| 13257 | } |
| 13258 | |
| 13259 | TEST_P(HttpNetworkTransactionTest, |
| 13260 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 13261 | ScopedVector<UploadElementReader> element_readers; |
| 13262 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13263 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13264 | |
| 13265 | HttpRequestInfo request; |
| 13266 | request.method = "POST"; |
| 13267 | request.url = GURL("http://www.foo.com/"); |
| 13268 | request.upload_data_stream = &upload_data_stream; |
| 13269 | request.load_flags = 0; |
| 13270 | |
| 13271 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13272 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13273 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13274 | // Send headers successfully, but get an error while sending the body. |
| 13275 | MockWrite data_writes[] = { |
| 13276 | MockWrite("POST / HTTP/1.1\r\n" |
| 13277 | "Host: www.foo.com\r\n" |
| 13278 | "Connection: keep-alive\r\n" |
| 13279 | "Content-Length: 3\r\n\r\n" |
| 13280 | "fo"), |
| 13281 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13282 | }; |
| 13283 | |
| 13284 | MockRead data_reads[] = { |
| 13285 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13286 | MockRead("hello world"), |
| 13287 | MockRead(SYNCHRONOUS, OK), |
| 13288 | }; |
| 13289 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13290 | arraysize(data_writes)); |
| 13291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13292 | |
| 13293 | TestCompletionCallback callback; |
| 13294 | |
| 13295 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13296 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13297 | |
| 13298 | rv = callback.WaitForResult(); |
| 13299 | EXPECT_EQ(OK, rv); |
| 13300 | |
| 13301 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13302 | ASSERT_TRUE(response != NULL); |
| 13303 | |
| 13304 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13305 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13306 | |
| 13307 | std::string response_data; |
| 13308 | rv = ReadTransaction(trans.get(), &response_data); |
| 13309 | EXPECT_EQ(OK, rv); |
| 13310 | EXPECT_EQ("hello world", response_data); |
| 13311 | } |
| 13312 | |
| 13313 | // This tests the more common case than the previous test, where headers and |
| 13314 | // body are not merged into a single request. |
| 13315 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 13316 | ScopedVector<UploadElementReader> element_readers; |
| 13317 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13318 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13319 | |
| 13320 | HttpRequestInfo request; |
| 13321 | request.method = "POST"; |
| 13322 | request.url = GURL("http://www.foo.com/"); |
| 13323 | request.upload_data_stream = &upload_data_stream; |
| 13324 | request.load_flags = 0; |
| 13325 | |
| 13326 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13327 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13328 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13329 | // Send headers successfully, but get an error while sending the body. |
| 13330 | MockWrite data_writes[] = { |
| 13331 | MockWrite("POST / HTTP/1.1\r\n" |
| 13332 | "Host: www.foo.com\r\n" |
| 13333 | "Connection: keep-alive\r\n" |
| 13334 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 13335 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13336 | }; |
| 13337 | |
| 13338 | MockRead data_reads[] = { |
| 13339 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13340 | MockRead("hello world"), |
| 13341 | MockRead(SYNCHRONOUS, OK), |
| 13342 | }; |
| 13343 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13344 | arraysize(data_writes)); |
| 13345 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13346 | |
| 13347 | TestCompletionCallback callback; |
| 13348 | |
| 13349 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13351 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 13352 | // they can't be merged with the body in a single send. Not currently |
| 13353 | // necessary since a chunked body is never merged with headers, but this makes |
| 13354 | // the test more future proof. |
| 13355 | base::RunLoop().RunUntilIdle(); |
| 13356 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13357 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13358 | |
| 13359 | rv = callback.WaitForResult(); |
| 13360 | EXPECT_EQ(OK, rv); |
| 13361 | |
| 13362 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13363 | ASSERT_TRUE(response != NULL); |
| 13364 | |
| 13365 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13366 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13367 | |
| 13368 | std::string response_data; |
| 13369 | rv = ReadTransaction(trans.get(), &response_data); |
| 13370 | EXPECT_EQ(OK, rv); |
| 13371 | EXPECT_EQ("hello world", response_data); |
| 13372 | } |
| 13373 | |
| 13374 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 13375 | ScopedVector<UploadElementReader> element_readers; |
| 13376 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13377 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13378 | |
| 13379 | HttpRequestInfo request; |
| 13380 | request.method = "POST"; |
| 13381 | request.url = GURL("http://www.foo.com/"); |
| 13382 | request.upload_data_stream = &upload_data_stream; |
| 13383 | request.load_flags = 0; |
| 13384 | |
| 13385 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13386 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13387 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13388 | |
| 13389 | MockWrite data_writes[] = { |
| 13390 | MockWrite("POST / HTTP/1.1\r\n" |
| 13391 | "Host: www.foo.com\r\n" |
| 13392 | "Connection: keep-alive\r\n" |
| 13393 | "Content-Length: 3\r\n\r\n"), |
| 13394 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13395 | }; |
| 13396 | |
| 13397 | MockRead data_reads[] = { |
| 13398 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13399 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13400 | MockRead("hello world"), |
| 13401 | MockRead(SYNCHRONOUS, OK), |
| 13402 | }; |
| 13403 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13404 | arraysize(data_writes)); |
| 13405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13406 | |
| 13407 | TestCompletionCallback callback; |
| 13408 | |
| 13409 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13410 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13411 | |
| 13412 | rv = callback.WaitForResult(); |
| 13413 | EXPECT_EQ(OK, rv); |
| 13414 | |
| 13415 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13416 | ASSERT_TRUE(response != NULL); |
| 13417 | |
| 13418 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13419 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13420 | |
| 13421 | std::string response_data; |
| 13422 | rv = ReadTransaction(trans.get(), &response_data); |
| 13423 | EXPECT_EQ(OK, rv); |
| 13424 | EXPECT_EQ("hello world", response_data); |
| 13425 | } |
| 13426 | |
| 13427 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 13428 | ScopedVector<UploadElementReader> element_readers; |
| 13429 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13430 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13431 | |
| 13432 | HttpRequestInfo request; |
| 13433 | request.method = "POST"; |
| 13434 | request.url = GURL("http://www.foo.com/"); |
| 13435 | request.upload_data_stream = &upload_data_stream; |
| 13436 | request.load_flags = 0; |
| 13437 | |
| 13438 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13439 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13440 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13441 | // Send headers successfully, but get an error while sending the body. |
| 13442 | MockWrite data_writes[] = { |
| 13443 | MockWrite("POST / HTTP/1.1\r\n" |
| 13444 | "Host: www.foo.com\r\n" |
| 13445 | "Connection: keep-alive\r\n" |
| 13446 | "Content-Length: 3\r\n\r\n"), |
| 13447 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13448 | }; |
| 13449 | |
| 13450 | MockRead data_reads[] = { |
| 13451 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 13452 | MockRead("hello world"), |
| 13453 | MockRead(SYNCHRONOUS, OK), |
| 13454 | }; |
| 13455 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13456 | arraysize(data_writes)); |
| 13457 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13458 | |
| 13459 | TestCompletionCallback callback; |
| 13460 | |
| 13461 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13463 | |
| 13464 | rv = callback.WaitForResult(); |
| 13465 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13466 | |
| 13467 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13468 | EXPECT_TRUE(response == NULL); |
| 13469 | } |
| 13470 | |
| 13471 | TEST_P(HttpNetworkTransactionTest, |
| 13472 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 13473 | ScopedVector<UploadElementReader> element_readers; |
| 13474 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13475 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13476 | |
| 13477 | HttpRequestInfo request; |
| 13478 | request.method = "POST"; |
| 13479 | request.url = GURL("http://www.foo.com/"); |
| 13480 | request.upload_data_stream = &upload_data_stream; |
| 13481 | request.load_flags = 0; |
| 13482 | |
| 13483 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13484 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13485 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13486 | // Send headers successfully, but get an error while sending the body. |
| 13487 | MockWrite data_writes[] = { |
| 13488 | MockWrite("POST / HTTP/1.1\r\n" |
| 13489 | "Host: www.foo.com\r\n" |
| 13490 | "Connection: keep-alive\r\n" |
| 13491 | "Content-Length: 3\r\n\r\n"), |
| 13492 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13493 | }; |
| 13494 | |
| 13495 | MockRead data_reads[] = { |
| 13496 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 13497 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 13498 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 13499 | MockRead("Content-Length: 0\r\n\r\n"), |
| 13500 | MockRead(SYNCHRONOUS, OK), |
| 13501 | }; |
| 13502 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13503 | arraysize(data_writes)); |
| 13504 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13505 | |
| 13506 | TestCompletionCallback callback; |
| 13507 | |
| 13508 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13509 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13510 | |
| 13511 | rv = callback.WaitForResult(); |
| 13512 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13513 | |
| 13514 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13515 | EXPECT_TRUE(response == NULL); |
| 13516 | } |
| 13517 | |
| 13518 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 13519 | ScopedVector<UploadElementReader> element_readers; |
| 13520 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13521 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13522 | |
| 13523 | HttpRequestInfo request; |
| 13524 | request.method = "POST"; |
| 13525 | request.url = GURL("http://www.foo.com/"); |
| 13526 | request.upload_data_stream = &upload_data_stream; |
| 13527 | request.load_flags = 0; |
| 13528 | |
| 13529 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13530 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13531 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13532 | // Send headers successfully, but get an error while sending the body. |
| 13533 | MockWrite data_writes[] = { |
| 13534 | MockWrite("POST / HTTP/1.1\r\n" |
| 13535 | "Host: www.foo.com\r\n" |
| 13536 | "Connection: keep-alive\r\n" |
| 13537 | "Content-Length: 3\r\n\r\n"), |
| 13538 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13539 | }; |
| 13540 | |
| 13541 | MockRead data_reads[] = { |
| 13542 | MockRead("HTTP 0.9 rocks!"), |
| 13543 | MockRead(SYNCHRONOUS, OK), |
| 13544 | }; |
| 13545 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13546 | arraysize(data_writes)); |
| 13547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13548 | |
| 13549 | TestCompletionCallback callback; |
| 13550 | |
| 13551 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13552 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13553 | |
| 13554 | rv = callback.WaitForResult(); |
| 13555 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13556 | |
| 13557 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13558 | EXPECT_TRUE(response == NULL); |
| 13559 | } |
| 13560 | |
| 13561 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 13562 | ScopedVector<UploadElementReader> element_readers; |
| 13563 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13564 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13565 | |
| 13566 | HttpRequestInfo request; |
| 13567 | request.method = "POST"; |
| 13568 | request.url = GURL("http://www.foo.com/"); |
| 13569 | request.upload_data_stream = &upload_data_stream; |
| 13570 | request.load_flags = 0; |
| 13571 | |
| 13572 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13573 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13574 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13575 | // Send headers successfully, but get an error while sending the body. |
| 13576 | MockWrite data_writes[] = { |
| 13577 | MockWrite("POST / HTTP/1.1\r\n" |
| 13578 | "Host: www.foo.com\r\n" |
| 13579 | "Connection: keep-alive\r\n" |
| 13580 | "Content-Length: 3\r\n\r\n"), |
| 13581 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13582 | }; |
| 13583 | |
| 13584 | MockRead data_reads[] = { |
| 13585 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 13586 | MockRead(SYNCHRONOUS, OK), |
| 13587 | }; |
| 13588 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13589 | arraysize(data_writes)); |
| 13590 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13591 | |
| 13592 | TestCompletionCallback callback; |
| 13593 | |
| 13594 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13595 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13596 | |
| 13597 | rv = callback.WaitForResult(); |
| 13598 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13599 | |
| 13600 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13601 | EXPECT_TRUE(response == NULL); |
| 13602 | } |
| 13603 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13604 | // Verify that proxy headers are not sent to the destination server when |
| 13605 | // establishing a tunnel for a secure WebSocket connection. |
| 13606 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 13607 | HttpRequestInfo request; |
| 13608 | request.method = "GET"; |
| 13609 | request.url = GURL("wss://www.google.com/"); |
| 13610 | AddWebSocketHeaders(&request.extra_headers); |
| 13611 | |
| 13612 | // Configure against proxy server "myproxy:70". |
| 13613 | session_deps_.proxy_service.reset( |
| 13614 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 13615 | |
| 13616 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13617 | |
| 13618 | // Since a proxy is configured, try to establish a tunnel. |
| 13619 | MockWrite data_writes[] = { |
| 13620 | MockWrite( |
| 13621 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 13622 | "Host: www.google.com\r\n" |
| 13623 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13624 | |
| 13625 | // After calling trans->RestartWithAuth(), this is the request we should |
| 13626 | // be issuing -- the final header line contains the credentials. |
| 13627 | MockWrite( |
| 13628 | "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 13629 | "Host: www.google.com\r\n" |
| 13630 | "Proxy-Connection: keep-alive\r\n" |
| 13631 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 13632 | |
| 13633 | MockWrite( |
| 13634 | "GET / HTTP/1.1\r\n" |
| 13635 | "Host: www.google.com\r\n" |
| 13636 | "Connection: Upgrade\r\n" |
| 13637 | "Upgrade: websocket\r\n" |
| 13638 | "Origin: http://www.google.com\r\n" |
| 13639 | "Sec-WebSocket-Version: 13\r\n" |
| 13640 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 13641 | }; |
| 13642 | |
| 13643 | // The proxy responds to the connect with a 407, using a persistent |
| 13644 | // connection. |
| 13645 | MockRead data_reads[] = { |
| 13646 | // No credentials. |
| 13647 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 13648 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 13649 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 13650 | |
| 13651 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13652 | |
| 13653 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 13654 | MockRead("Upgrade: websocket\r\n"), |
| 13655 | MockRead("Connection: Upgrade\r\n"), |
| 13656 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 13657 | }; |
| 13658 | |
| 13659 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13660 | arraysize(data_writes)); |
| 13661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13662 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13664 | |
| 13665 | scoped_ptr<HttpTransaction> trans( |
| 13666 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13667 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 13668 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 13669 | &websocket_stream_create_helper); |
| 13670 | |
| 13671 | { |
| 13672 | TestCompletionCallback callback; |
| 13673 | |
| 13674 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13675 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13676 | |
| 13677 | rv = callback.WaitForResult(); |
| 13678 | EXPECT_EQ(OK, rv); |
| 13679 | } |
| 13680 | |
| 13681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13682 | ASSERT_TRUE(response); |
| 13683 | ASSERT_TRUE(response->headers.get()); |
| 13684 | EXPECT_EQ(407, response->headers->response_code()); |
| 13685 | |
| 13686 | { |
| 13687 | TestCompletionCallback callback; |
| 13688 | |
| 13689 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 13690 | callback.callback()); |
| 13691 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13692 | |
| 13693 | rv = callback.WaitForResult(); |
| 13694 | EXPECT_EQ(OK, rv); |
| 13695 | } |
| 13696 | |
| 13697 | response = trans->GetResponseInfo(); |
| 13698 | ASSERT_TRUE(response); |
| 13699 | ASSERT_TRUE(response->headers.get()); |
| 13700 | |
| 13701 | EXPECT_EQ(101, response->headers->response_code()); |
| 13702 | |
| 13703 | trans.reset(); |
| 13704 | session->CloseAllConnections(); |
| 13705 | } |
| 13706 | |
| 13707 | // Verify that proxy headers are not sent to the destination server when |
| 13708 | // establishing a tunnel for an insecure WebSocket connection. |
| 13709 | // This requires the authentication info to be injected into the auth cache |
| 13710 | // due to crbug.com/395064 |
| 13711 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 13712 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 13713 | HttpRequestInfo request; |
| 13714 | request.method = "GET"; |
| 13715 | request.url = GURL("ws://www.google.com/"); |
| 13716 | AddWebSocketHeaders(&request.extra_headers); |
| 13717 | |
| 13718 | // Configure against proxy server "myproxy:70". |
| 13719 | session_deps_.proxy_service.reset( |
| 13720 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 13721 | |
| 13722 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13723 | |
| 13724 | MockWrite data_writes[] = { |
| 13725 | // Try to establish a tunnel for the WebSocket connection, with |
| 13726 | // credentials. Because WebSockets have a separate set of socket pools, |
| 13727 | // they cannot and will not use the same TCP/IP connection as the |
| 13728 | // preflight HTTP request. |
| 13729 | MockWrite( |
| 13730 | "CONNECT www.google.com:80 HTTP/1.1\r\n" |
| 13731 | "Host: www.google.com\r\n" |
| 13732 | "Proxy-Connection: keep-alive\r\n" |
| 13733 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 13734 | |
| 13735 | MockWrite( |
| 13736 | "GET / HTTP/1.1\r\n" |
| 13737 | "Host: www.google.com\r\n" |
| 13738 | "Connection: Upgrade\r\n" |
| 13739 | "Upgrade: websocket\r\n" |
| 13740 | "Origin: http://www.google.com\r\n" |
| 13741 | "Sec-WebSocket-Version: 13\r\n" |
| 13742 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 13743 | }; |
| 13744 | |
| 13745 | MockRead data_reads[] = { |
| 13746 | // HTTP CONNECT with credentials. |
| 13747 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13748 | |
| 13749 | // WebSocket connection established inside tunnel. |
| 13750 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 13751 | MockRead("Upgrade: websocket\r\n"), |
| 13752 | MockRead("Connection: Upgrade\r\n"), |
| 13753 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 13754 | }; |
| 13755 | |
| 13756 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13757 | arraysize(data_writes)); |
| 13758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13759 | |
| 13760 | session->http_auth_cache()->Add( |
| 13761 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 13762 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 13763 | |
| 13764 | scoped_ptr<HttpTransaction> trans( |
| 13765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13766 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 13767 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 13768 | &websocket_stream_create_helper); |
| 13769 | |
| 13770 | TestCompletionCallback callback; |
| 13771 | |
| 13772 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13774 | |
| 13775 | rv = callback.WaitForResult(); |
| 13776 | EXPECT_EQ(OK, rv); |
| 13777 | |
| 13778 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13779 | ASSERT_TRUE(response); |
| 13780 | ASSERT_TRUE(response->headers.get()); |
| 13781 | |
| 13782 | EXPECT_EQ(101, response->headers->response_code()); |
| 13783 | |
| 13784 | trans.reset(); |
| 13785 | session->CloseAllConnections(); |
| 13786 | } |
| 13787 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 13788 | } // namespace net |