[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" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 21 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 23 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 24 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 25 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 26 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 27 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 28 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 30 | #include "net/base/load_timing_info.h" |
| 31 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 32 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 33 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 34 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 35 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 36 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 37 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 38 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 39 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 40 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 41 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 42 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 45 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 46 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 47 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 48 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 49 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 50 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 51 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 52 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 53 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 54 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 55 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 56 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 57 | #include "net/log/test_net_log_entry.h" |
| 58 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 59 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 60 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 61 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 62 | #include "net/proxy/proxy_resolver.h" |
| 63 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 64 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 65 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 66 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 67 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 68 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 69 | #include "net/socket/socket_test_util.h" |
| 70 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 71 | #include "net/spdy/spdy_framer.h" |
| 72 | #include "net/spdy/spdy_session.h" |
| 73 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 74 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 75 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 76 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_config_service_defaults.h" |
| 78 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 79 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 80 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 81 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 82 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 83 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 84 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 85 | using base::ASCIIToUTF16; |
| 86 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 87 | //----------------------------------------------------------------------------- |
| 88 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 89 | namespace net { |
| 90 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 91 | namespace { |
| 92 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 93 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 94 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 95 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 96 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 97 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 98 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 99 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 100 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 101 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 102 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 103 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 104 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 105 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 106 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 107 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 108 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 109 | } |
| 110 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 111 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 112 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 113 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 114 | } |
| 115 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 116 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 117 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 118 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 121 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 122 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 123 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 124 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 125 | if (!params) |
| 126 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 127 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 128 | if (!params->GetList("headers", &header_list)) |
| 129 | return false; |
| 130 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 131 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 132 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 133 | return true; |
| 134 | } |
| 135 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 136 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 137 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 138 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 139 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 140 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 141 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 142 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 143 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 144 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 145 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 146 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 147 | |
| 148 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 149 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 150 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 152 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 153 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 154 | } |
| 155 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 157 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 158 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 159 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 160 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | |
| 163 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 164 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 165 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 166 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 167 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 168 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 169 | load_timing_info.send_start); |
| 170 | |
| 171 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 172 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 173 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 175 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 180 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 185 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
| 187 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 188 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 189 | load_timing_info.proxy_resolve_end); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 191 | load_timing_info.send_start); |
| 192 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 194 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 196 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 201 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 202 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | int connect_timing_flags) { |
| 204 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 205 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | |
| 207 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 208 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 209 | load_timing_info.proxy_resolve_end); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 211 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 212 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 213 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 215 | load_timing_info.send_start); |
| 216 | |
| 217 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 219 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 221 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 222 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 223 | } |
| 224 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 226 | headers->SetHeader("Connection", "Upgrade"); |
| 227 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 228 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 229 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 230 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 231 | } |
| 232 | |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 233 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
| 234 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 235 | } |
| 236 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 237 | } // namespace |
| 238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 239 | class HttpNetworkTransactionTest |
| 240 | : public PlatformTest, |
| 241 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 242 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 243 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | // Important to restore the per-pool limit first, since the pool limit must |
| 245 | // always be greater than group limit, and the tests reduce both limits. |
| 246 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 247 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 248 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 250 | } |
| 251 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 252 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 253 | HttpNetworkTransactionTest() |
| 254 | : spdy_util_(GetParam()), |
| 255 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 256 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 257 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 258 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 260 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 261 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 262 | struct SimpleGetHelperResult { |
| 263 | int rv; |
| 264 | std::string status_line; |
| 265 | std::string response_data; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 266 | int64 totalReceivedBytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 267 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 268 | ConnectionAttempts connection_attempts; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 269 | }; |
| 270 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 271 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 272 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 273 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 274 | } |
| 275 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 276 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 277 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[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 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 280 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 281 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 282 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 283 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 284 | } |
| 285 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 286 | const char* GetAlternateProtocolFromParam() { |
| 287 | return |
| 288 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 289 | } |
| 290 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 291 | std::string GetAlternativeServiceHttpHeader() { |
| 292 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 293 | "=\"www.example.com:443\"\r\n"; |
| 294 | } |
| 295 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 296 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 297 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 298 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 299 | } |
| 300 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 301 | // Either |write_failure| specifies a write failure or |read_failure| |
| 302 | // specifies a read failure when using a reused socket. In either case, the |
| 303 | // failure should cause the network transaction to resend the request, and the |
| 304 | // other argument should be NULL. |
| 305 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 306 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 307 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 308 | // Either |write_failure| specifies a write failure or |read_failure| |
| 309 | // specifies a read failure when using a reused socket. In either case, the |
| 310 | // failure should cause the network transaction to resend the request, and the |
| 311 | // other argument should be NULL. |
| 312 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 313 | const MockRead* read_failure, |
| 314 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 315 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 316 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 317 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 318 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 319 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 320 | HttpRequestInfo request; |
| 321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 322 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 323 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 324 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 325 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 326 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 327 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 328 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 330 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 331 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 332 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 333 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 335 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 336 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 337 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 338 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 340 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 341 | out.rv = callback.WaitForResult(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 342 | |
| 343 | // Even in the failure cases that use this function, connections are always |
| 344 | // successfully established before the error. |
| 345 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 346 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 347 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 348 | if (out.rv != OK) |
| 349 | return out; |
| 350 | |
| 351 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 352 | // Can't use ASSERT_* inside helper functions like this, so |
| 353 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 354 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 355 | out.rv = ERR_UNEXPECTED; |
| 356 | return out; |
| 357 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 358 | out.status_line = response->headers->GetStatusLine(); |
| 359 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 360 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 361 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 362 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 363 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 364 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 365 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 366 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 367 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 368 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 369 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 370 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 371 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 372 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 373 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 374 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 375 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 376 | std::string line; |
| 377 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 378 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 379 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 380 | HttpRequestHeaders request_headers; |
| 381 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 382 | std::string value; |
| 383 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 384 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 385 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 386 | EXPECT_EQ("keep-alive", value); |
| 387 | |
| 388 | std::string response_headers; |
| 389 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 390 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 391 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 392 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 393 | out.totalReceivedBytes = trans->GetTotalReceivedBytes(); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 394 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 395 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 396 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 397 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 398 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 399 | size_t reads_count) { |
| 400 | StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 401 | StaticSocketDataProvider* data[] = { &reads }; |
| 402 | return SimpleGetHelperForData(data, 1); |
| 403 | } |
| 404 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 405 | int64 ReadsSize(MockRead data_reads[], size_t reads_count) { |
| 406 | int64 size = 0; |
| 407 | for (size_t i = 0; i < reads_count; ++i) |
| 408 | size += data_reads[i].data_len; |
| 409 | return size; |
| 410 | } |
| 411 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 412 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 413 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 414 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 415 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 416 | |
| 417 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 418 | |
| 419 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 420 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 421 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 422 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 423 | |
| 424 | // Original socket limits. Some tests set these. Safest to always restore |
| 425 | // them once each test has been run. |
| 426 | int old_max_group_sockets_; |
| 427 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 428 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 429 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 430 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 431 | HttpNetworkTransactionTest, |
| 432 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 433 | kProtoHTTP2_14, |
| 434 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 435 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 436 | namespace { |
| 437 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 438 | class BeforeNetworkStartHandler { |
| 439 | public: |
| 440 | explicit BeforeNetworkStartHandler(bool defer) |
| 441 | : defer_on_before_network_start_(defer), |
| 442 | observed_before_network_start_(false) {} |
| 443 | |
| 444 | void OnBeforeNetworkStart(bool* defer) { |
| 445 | *defer = defer_on_before_network_start_; |
| 446 | observed_before_network_start_ = true; |
| 447 | } |
| 448 | |
| 449 | bool observed_before_network_start() const { |
| 450 | return observed_before_network_start_; |
| 451 | } |
| 452 | |
| 453 | private: |
| 454 | const bool defer_on_before_network_start_; |
| 455 | bool observed_before_network_start_; |
| 456 | |
| 457 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 458 | }; |
| 459 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 460 | class BeforeProxyHeadersSentHandler { |
| 461 | public: |
| 462 | BeforeProxyHeadersSentHandler() |
| 463 | : observed_before_proxy_headers_sent_(false) {} |
| 464 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 465 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 466 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 467 | observed_before_proxy_headers_sent_ = true; |
| 468 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 469 | } |
| 470 | |
| 471 | bool observed_before_proxy_headers_sent() const { |
| 472 | return observed_before_proxy_headers_sent_; |
| 473 | } |
| 474 | |
| 475 | std::string observed_proxy_server_uri() const { |
| 476 | return observed_proxy_server_uri_; |
| 477 | } |
| 478 | |
| 479 | private: |
| 480 | bool observed_before_proxy_headers_sent_; |
| 481 | std::string observed_proxy_server_uri_; |
| 482 | |
| 483 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 484 | }; |
| 485 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 486 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 487 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 488 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 489 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 490 | const int sizeof_row = strlen(row); |
| 491 | const int num_rows = static_cast<int>( |
| 492 | ceil(static_cast<float>(size) / sizeof_row)); |
| 493 | const int sizeof_data = num_rows * sizeof_row; |
| 494 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 495 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 496 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 497 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 498 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 499 | } |
| 500 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 501 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 502 | // Alternative functions that eliminate randomness and dependency on the local |
| 503 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 504 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 505 | static const uint8 bytes[] = { |
| 506 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 507 | }; |
| 508 | static size_t current_byte = 0; |
| 509 | for (size_t i = 0; i < n; ++i) { |
| 510 | output[i] = bytes[current_byte++]; |
| 511 | current_byte %= arraysize(bytes); |
| 512 | } |
| 513 | } |
| 514 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 515 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 516 | static const uint8 bytes[] = { |
| 517 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 518 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 519 | }; |
| 520 | static size_t current_byte = 0; |
| 521 | for (size_t i = 0; i < n; ++i) { |
| 522 | output[i] = bytes[current_byte++]; |
| 523 | current_byte %= arraysize(bytes); |
| 524 | } |
| 525 | } |
| 526 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 527 | std::string MockGetHostName() { |
| 528 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 529 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 530 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 531 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 532 | template<typename ParentPool> |
| 533 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 534 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 535 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 536 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 537 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 538 | const std::string last_group_name_received() const { |
| 539 | return last_group_name_; |
| 540 | } |
| 541 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 542 | int RequestSocket(const std::string& group_name, |
| 543 | const void* socket_params, |
| 544 | RequestPriority priority, |
| 545 | ClientSocketHandle* handle, |
| 546 | const CompletionCallback& callback, |
| 547 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 548 | last_group_name_ = group_name; |
| 549 | return ERR_IO_PENDING; |
| 550 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 551 | void CancelRequest(const std::string& group_name, |
| 552 | ClientSocketHandle* handle) override {} |
| 553 | void ReleaseSocket(const std::string& group_name, |
| 554 | scoped_ptr<StreamSocket> socket, |
| 555 | int id) override {} |
| 556 | void CloseIdleSockets() override {} |
| 557 | int IdleSocketCount() const override { return 0; } |
| 558 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 559 | return 0; |
| 560 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 561 | LoadState GetLoadState(const std::string& group_name, |
| 562 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 563 | return LOAD_STATE_IDLE; |
| 564 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 565 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 566 | return base::TimeDelta(); |
| 567 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 568 | |
| 569 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 570 | std::string last_group_name_; |
| 571 | }; |
| 572 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 573 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 574 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 575 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 576 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 577 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 578 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 579 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 580 | CaptureGroupNameSSLSocketPool; |
| 581 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 582 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 583 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 584 | HostResolver* host_resolver, |
| 585 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 586 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 587 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 588 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 589 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 590 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 591 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 592 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 593 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 594 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 595 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 596 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 597 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 598 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 599 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 600 | : SSLClientSocketPool(0, |
| 601 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 602 | cert_verifier, |
| 603 | NULL, |
| 604 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 605 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 606 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 607 | std::string(), |
| 608 | NULL, |
| 609 | NULL, |
| 610 | NULL, |
| 611 | NULL, |
| 612 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 613 | NULL) { |
| 614 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 615 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 616 | //----------------------------------------------------------------------------- |
| 617 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 618 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 619 | // configured for common cases. |
| 620 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 621 | if (!auth_challenge) |
| 622 | return false; |
| 623 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 624 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 625 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 626 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 627 | return true; |
| 628 | } |
| 629 | |
| 630 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 631 | if (!auth_challenge) |
| 632 | return false; |
| 633 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 634 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 635 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 636 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 637 | return true; |
| 638 | } |
| 639 | |
| 640 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 641 | if (!auth_challenge) |
| 642 | return false; |
| 643 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 644 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 645 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 646 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 647 | return true; |
| 648 | } |
| 649 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 650 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 651 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 652 | if (!auth_challenge) |
| 653 | return false; |
| 654 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 655 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 656 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 657 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 658 | return true; |
| 659 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 660 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 661 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 662 | } // namespace |
| 663 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 664 | TEST_P(HttpNetworkTransactionTest, Basic) { |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 665 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 666 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 667 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 668 | } |
| 669 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 670 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 671 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 672 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 673 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 674 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 675 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 676 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 677 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 678 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 679 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 680 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 681 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 682 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 683 | EXPECT_EQ(0u, out.connection_attempts.size()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 687 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 688 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 689 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 690 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 691 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 692 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 693 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 694 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 695 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 696 | EXPECT_EQ("hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 697 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 698 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 702 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 703 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 704 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 705 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 706 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 707 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 708 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 709 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 710 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 711 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 712 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 713 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 717 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 719 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 720 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 721 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 722 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 723 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 724 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 726 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 727 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 728 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | // 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] | 732 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 733 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 734 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 735 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 736 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 737 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 738 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 739 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 740 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 741 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 742 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 743 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 747 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 748 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 749 | MockRead("\n"), |
| 750 | MockRead("\n"), |
| 751 | MockRead("Q"), |
| 752 | MockRead("J"), |
| 753 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 755 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 756 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 757 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 758 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 759 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 760 | EXPECT_EQ("DATA", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 761 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 762 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 766 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 767 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 768 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 769 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 770 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 771 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 772 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 773 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 774 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 775 | EXPECT_EQ("HTT", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 776 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 777 | EXPECT_EQ(reads_size, out.totalReceivedBytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 778 | } |
| 779 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 780 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 781 | // persistent connection. The response should still terminate since a 204 |
| 782 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 783 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 784 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 785 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 786 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 787 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 789 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 790 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 791 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 792 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 793 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 794 | EXPECT_EQ("", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 795 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 796 | int64 response_size = reads_size - strlen(junk); |
| 797 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 798 | } |
| 799 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 800 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 801 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 802 | std::string final_chunk = "0\r\n\r\n"; |
| 803 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 804 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 805 | MockRead data_reads[] = { |
| 806 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 807 | MockRead("5\r\nHello\r\n"), |
| 808 | MockRead("1\r\n"), |
| 809 | MockRead(" \r\n"), |
| 810 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 811 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 812 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 813 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 814 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 815 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 816 | EXPECT_EQ(OK, out.rv); |
| 817 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 818 | EXPECT_EQ("Hello world", out.response_data); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 819 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 820 | int64 response_size = reads_size - extra_data.size(); |
| 821 | EXPECT_EQ(response_size, out.totalReceivedBytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 822 | } |
| 823 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 824 | // Next tests deal with http://crbug.com/56344. |
| 825 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 826 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 827 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 828 | MockRead data_reads[] = { |
| 829 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 830 | MockRead("Content-Length: 10\r\n"), |
| 831 | MockRead("Content-Length: 5\r\n\r\n"), |
| 832 | }; |
| 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
| 835 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 836 | } |
| 837 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 838 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 839 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 840 | MockRead data_reads[] = { |
| 841 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 842 | MockRead("Content-Length: 5\r\n"), |
| 843 | MockRead("Content-Length: 5\r\n\r\n"), |
| 844 | MockRead("Hello"), |
| 845 | }; |
| 846 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 847 | arraysize(data_reads)); |
| 848 | EXPECT_EQ(OK, out.rv); |
| 849 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 850 | EXPECT_EQ("Hello", out.response_data); |
| 851 | } |
| 852 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 853 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 854 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 855 | // More than 2 dupes. |
| 856 | { |
| 857 | MockRead data_reads[] = { |
| 858 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 859 | MockRead("Content-Length: 5\r\n"), |
| 860 | MockRead("Content-Length: 5\r\n"), |
| 861 | MockRead("Content-Length: 5\r\n\r\n"), |
| 862 | MockRead("Hello"), |
| 863 | }; |
| 864 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 865 | arraysize(data_reads)); |
| 866 | EXPECT_EQ(OK, out.rv); |
| 867 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 868 | EXPECT_EQ("Hello", out.response_data); |
| 869 | } |
| 870 | // HTTP/1.0 |
| 871 | { |
| 872 | MockRead data_reads[] = { |
| 873 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 874 | MockRead("Content-Length: 5\r\n"), |
| 875 | MockRead("Content-Length: 5\r\n"), |
| 876 | MockRead("Content-Length: 5\r\n\r\n"), |
| 877 | MockRead("Hello"), |
| 878 | }; |
| 879 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 880 | arraysize(data_reads)); |
| 881 | EXPECT_EQ(OK, out.rv); |
| 882 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 883 | EXPECT_EQ("Hello", out.response_data); |
| 884 | } |
| 885 | // 2 dupes and one mismatched. |
| 886 | { |
| 887 | MockRead data_reads[] = { |
| 888 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 889 | MockRead("Content-Length: 10\r\n"), |
| 890 | MockRead("Content-Length: 10\r\n"), |
| 891 | MockRead("Content-Length: 5\r\n\r\n"), |
| 892 | }; |
| 893 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 894 | arraysize(data_reads)); |
| 895 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 896 | } |
| 897 | } |
| 898 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 899 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 900 | MultipleContentLengthHeadersTransferEncoding) { |
| 901 | MockRead data_reads[] = { |
| 902 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 903 | MockRead("Content-Length: 666\r\n"), |
| 904 | MockRead("Content-Length: 1337\r\n"), |
| 905 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 906 | MockRead("5\r\nHello\r\n"), |
| 907 | MockRead("1\r\n"), |
| 908 | MockRead(" \r\n"), |
| 909 | MockRead("5\r\nworld\r\n"), |
| 910 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 911 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 912 | }; |
| 913 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 914 | arraysize(data_reads)); |
| 915 | EXPECT_EQ(OK, out.rv); |
| 916 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 917 | EXPECT_EQ("Hello world", out.response_data); |
| 918 | } |
| 919 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 920 | // Next tests deal with http://crbug.com/98895. |
| 921 | |
| 922 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 923 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 924 | MockRead data_reads[] = { |
| 925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 926 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 927 | MockRead("Content-Length: 5\r\n\r\n"), |
| 928 | MockRead("Hello"), |
| 929 | }; |
| 930 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 931 | arraysize(data_reads)); |
| 932 | EXPECT_EQ(OK, out.rv); |
| 933 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 934 | EXPECT_EQ("Hello", out.response_data); |
| 935 | } |
| 936 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 937 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 938 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 939 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 940 | MockRead data_reads[] = { |
| 941 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 942 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 943 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 944 | MockRead("Content-Length: 5\r\n\r\n"), |
| 945 | MockRead("Hello"), |
| 946 | }; |
| 947 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 948 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 949 | EXPECT_EQ(OK, out.rv); |
| 950 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 951 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 955 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 956 | MockRead data_reads[] = { |
| 957 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 958 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 959 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 960 | MockRead("Content-Length: 5\r\n\r\n"), |
| 961 | MockRead("Hello"), |
| 962 | }; |
| 963 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 964 | arraysize(data_reads)); |
| 965 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 966 | } |
| 967 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 968 | // Checks that two identical Location headers result in no error. |
| 969 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 970 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 971 | MockRead data_reads[] = { |
| 972 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 973 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 974 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 975 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 976 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 977 | }; |
| 978 | |
| 979 | HttpRequestInfo request; |
| 980 | request.method = "GET"; |
| 981 | request.url = GURL("http://redirect.com/"); |
| 982 | request.load_flags = 0; |
| 983 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 984 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 985 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 986 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 987 | |
| 988 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 991 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 993 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 994 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 995 | |
| 996 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 997 | |
| 998 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 999 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1000 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1001 | std::string url; |
| 1002 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1003 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1004 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1007 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1008 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1009 | MockRead data_reads[] = { |
| 1010 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1011 | MockRead("Location: http://good.com/\r\n"), |
| 1012 | MockRead("Location: http://evil.com/\r\n"), |
| 1013 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1014 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1015 | }; |
| 1016 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1017 | arraysize(data_reads)); |
| 1018 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1019 | } |
| 1020 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1021 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1022 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1023 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1024 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1025 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1026 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1027 | request.load_flags = 0; |
| 1028 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1029 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1030 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1031 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1032 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1033 | trans->SetBeforeProxyHeadersSentCallback( |
| 1034 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1035 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1036 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1037 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame^] | 1038 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1039 | "Host: www.example.org\r\n" |
| 1040 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1041 | }; |
| 1042 | MockRead data_reads1[] = { |
| 1043 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1044 | MockRead("Server: Blah\r\n"), |
| 1045 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1046 | |
| 1047 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1048 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1049 | }; |
| 1050 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1051 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1052 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1053 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1055 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1057 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1059 | |
| 1060 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1061 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1062 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1063 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1064 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1065 | |
| 1066 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1067 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1068 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1069 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1070 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1071 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1072 | |
| 1073 | std::string server_header; |
| 1074 | void* iter = NULL; |
| 1075 | bool has_server_header = response->headers->EnumerateHeader( |
| 1076 | &iter, "Server", &server_header); |
| 1077 | EXPECT_TRUE(has_server_header); |
| 1078 | EXPECT_EQ("Blah", server_header); |
| 1079 | |
| 1080 | // Reading should give EOF right away, since there is no message body |
| 1081 | // (despite non-zero content-length). |
| 1082 | std::string response_data; |
| 1083 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1084 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1085 | EXPECT_EQ("", response_data); |
| 1086 | } |
| 1087 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1088 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1089 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1090 | |
| 1091 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1092 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1093 | MockRead("hello"), |
| 1094 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1095 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1096 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1097 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1098 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1099 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1100 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1101 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1102 | "hello", "world" |
| 1103 | }; |
| 1104 | |
| 1105 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1106 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1107 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1108 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1109 | request.load_flags = 0; |
| 1110 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1111 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1112 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1114 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1116 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1117 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1118 | |
| 1119 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1120 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1121 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1122 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1123 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1124 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1125 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1126 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1127 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1128 | |
| 1129 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1130 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1131 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1132 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1136 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1137 | ScopedVector<UploadElementReader> element_readers; |
| 1138 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1139 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1140 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1141 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1142 | request.method = "POST"; |
| 1143 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1144 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1145 | request.load_flags = 0; |
| 1146 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1147 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1148 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1149 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1150 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1151 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1152 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1153 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1154 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1155 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1156 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1157 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1160 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1162 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1163 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | |
| 1165 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1167 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1168 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1169 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1171 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1172 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1173 | |
| 1174 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1175 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1176 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1177 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1178 | } |
| 1179 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1180 | // This test is almost the same as Ignores100 above, but the response contains |
| 1181 | // 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] | 1182 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1183 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1184 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1185 | request.method = "GET"; |
| 1186 | request.url = GURL("http://www.foo.com/"); |
| 1187 | request.load_flags = 0; |
| 1188 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1189 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1190 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1191 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1192 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1193 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1194 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1195 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1196 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1197 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1198 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1199 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1202 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1204 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1205 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1206 | |
| 1207 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1208 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1209 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1210 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1211 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1212 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1213 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1214 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1215 | |
| 1216 | std::string response_data; |
| 1217 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1218 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1219 | EXPECT_EQ("hello world", response_data); |
| 1220 | } |
| 1221 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1222 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1223 | HttpRequestInfo request; |
| 1224 | request.method = "POST"; |
| 1225 | request.url = GURL("http://www.foo.com/"); |
| 1226 | request.load_flags = 0; |
| 1227 | |
| 1228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1229 | scoped_ptr<HttpTransaction> trans( |
| 1230 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1231 | |
| 1232 | MockRead data_reads[] = { |
| 1233 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1234 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1235 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1236 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1237 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1238 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1239 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1240 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1241 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1242 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1243 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1244 | rv = callback.WaitForResult(); |
| 1245 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1246 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1247 | std::string response_data; |
| 1248 | rv = ReadTransaction(trans.get(), &response_data); |
| 1249 | EXPECT_EQ(OK, rv); |
| 1250 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1251 | } |
| 1252 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1253 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1254 | HttpRequestInfo request; |
| 1255 | request.method = "POST"; |
| 1256 | request.url = GURL("http://www.foo.com/"); |
| 1257 | request.load_flags = 0; |
| 1258 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1259 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1260 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1262 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1263 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1264 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1265 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1266 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1267 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1269 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1271 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1272 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1273 | |
| 1274 | rv = callback.WaitForResult(); |
| 1275 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1276 | } |
| 1277 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1278 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1279 | const MockWrite* write_failure, |
| 1280 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1281 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1282 | request.method = "GET"; |
| 1283 | request.url = GURL("http://www.foo.com/"); |
| 1284 | request.load_flags = 0; |
| 1285 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1286 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1287 | session_deps_.net_log = &net_log; |
| 1288 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1289 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1290 | // Written data for successfully sending both requests. |
| 1291 | MockWrite data1_writes[] = { |
| 1292 | MockWrite("GET / HTTP/1.1\r\n" |
| 1293 | "Host: www.foo.com\r\n" |
| 1294 | "Connection: keep-alive\r\n\r\n"), |
| 1295 | MockWrite("GET / HTTP/1.1\r\n" |
| 1296 | "Host: www.foo.com\r\n" |
| 1297 | "Connection: keep-alive\r\n\r\n") |
| 1298 | }; |
| 1299 | |
| 1300 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1302 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1303 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1304 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1306 | |
| 1307 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1308 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1309 | data1_writes[1] = *write_failure; |
| 1310 | } else { |
| 1311 | ASSERT_TRUE(read_failure); |
| 1312 | data1_reads[2] = *read_failure; |
| 1313 | } |
| 1314 | |
| 1315 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1316 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1317 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | |
| 1319 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1320 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1321 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1322 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1324 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1325 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1326 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1327 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | "hello", "world" |
| 1329 | }; |
| 1330 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1331 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1333 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1335 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1336 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1338 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1340 | |
| 1341 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1342 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1344 | LoadTimingInfo load_timing_info; |
| 1345 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1346 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1347 | if (i == 0) { |
| 1348 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1349 | } else { |
| 1350 | // The second request should be using a new socket. |
| 1351 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1352 | } |
| 1353 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1354 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1355 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1357 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1358 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
| 1360 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1361 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1362 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1363 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | } |
| 1365 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1366 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1367 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1368 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1369 | const MockRead* read_failure, |
| 1370 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1371 | HttpRequestInfo request; |
| 1372 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1373 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1374 | request.load_flags = 0; |
| 1375 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1376 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1377 | session_deps_.net_log = &net_log; |
| 1378 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1379 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1380 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1381 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1382 | if (use_spdy) { |
| 1383 | ssl1.SetNextProto(GetParam()); |
| 1384 | ssl2.SetNextProto(GetParam()); |
| 1385 | } |
| 1386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1387 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1388 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1389 | // SPDY versions of the request and response. |
| 1390 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1391 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1392 | scoped_ptr<SpdyFrame> spdy_response( |
| 1393 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1394 | scoped_ptr<SpdyFrame> spdy_data( |
| 1395 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1396 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1397 | // HTTP/1.1 versions of the request and response. |
| 1398 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1399 | "Host: www.foo.com\r\n" |
| 1400 | "Connection: keep-alive\r\n\r\n"; |
| 1401 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1402 | const char kHttpData[] = "hello"; |
| 1403 | |
| 1404 | std::vector<MockRead> data1_reads; |
| 1405 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1406 | if (write_failure) { |
| 1407 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1408 | data1_writes.push_back(*write_failure); |
| 1409 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1410 | } else { |
| 1411 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1412 | if (use_spdy) { |
| 1413 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1414 | } else { |
| 1415 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1416 | } |
| 1417 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1418 | } |
| 1419 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1420 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1421 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1422 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1423 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1424 | std::vector<MockRead> data2_reads; |
| 1425 | std::vector<MockWrite> data2_writes; |
| 1426 | |
| 1427 | if (use_spdy) { |
| 1428 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1429 | |
| 1430 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1431 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1432 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1433 | } else { |
| 1434 | data2_writes.push_back( |
| 1435 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1436 | |
| 1437 | data2_reads.push_back( |
| 1438 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1439 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1440 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1441 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1442 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1443 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1444 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1445 | |
| 1446 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1447 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1448 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1449 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 1450 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1451 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1452 | // Wait for the preconnect to complete. |
| 1453 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1454 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1455 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1456 | |
| 1457 | // Make the request. |
| 1458 | TestCompletionCallback callback; |
| 1459 | |
| 1460 | scoped_ptr<HttpTransaction> trans( |
| 1461 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1462 | |
| 1463 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1464 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1465 | |
| 1466 | rv = callback.WaitForResult(); |
| 1467 | EXPECT_EQ(OK, rv); |
| 1468 | |
| 1469 | LoadTimingInfo load_timing_info; |
| 1470 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1471 | TestLoadTimingNotReused( |
| 1472 | load_timing_info, |
| 1473 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1474 | |
| 1475 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1476 | ASSERT_TRUE(response != NULL); |
| 1477 | |
| 1478 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1479 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1480 | |
| 1481 | std::string response_data; |
| 1482 | rv = ReadTransaction(trans.get(), &response_data); |
| 1483 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1484 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1487 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1488 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1489 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1490 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1491 | } |
| 1492 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1493 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1494 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1495 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1496 | } |
| 1497 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1498 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1499 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1500 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1501 | } |
| 1502 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1503 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1504 | // if the socket was a reused keep alive socket. |
| 1505 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1506 | MockRead read_failure(SYNCHRONOUS, |
| 1507 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1508 | "Connection: Keep-Alive\r\n" |
| 1509 | "Content-Length: 6\r\n\r\n" |
| 1510 | "Pickle"); |
| 1511 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1512 | } |
| 1513 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1514 | TEST_P(HttpNetworkTransactionTest, |
| 1515 | PreconnectErrorNotConnectedOnWrite) { |
| 1516 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1517 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1521 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1522 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1526 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1527 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1528 | } |
| 1529 | |
| 1530 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1531 | MockRead read_failure(ASYNC, OK); // EOF |
| 1532 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1533 | } |
| 1534 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1535 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1536 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1537 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1538 | MockRead read_failure(SYNCHRONOUS, |
| 1539 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1540 | "Connection: Keep-Alive\r\n" |
| 1541 | "Content-Length: 6\r\n\r\n" |
| 1542 | "Pickle"); |
| 1543 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1544 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1545 | } |
| 1546 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1547 | TEST_P(HttpNetworkTransactionTest, |
| 1548 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1549 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1550 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1551 | } |
| 1552 | |
| 1553 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1554 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1555 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1556 | } |
| 1557 | |
| 1558 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1559 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1560 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1561 | } |
| 1562 | |
| 1563 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1564 | MockRead read_failure(ASYNC, OK); // EOF |
| 1565 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1566 | } |
| 1567 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1568 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1569 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1571 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1572 | request.load_flags = 0; |
| 1573 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1574 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1575 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1576 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1577 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1578 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1579 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1580 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1581 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1582 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1583 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1584 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1585 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1587 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1589 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1590 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1591 | |
| 1592 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1593 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | // What do various browsers do when the server closes a non-keepalive |
| 1597 | // connection without sending any response header or body? |
| 1598 | // |
| 1599 | // IE7: error page |
| 1600 | // Safari 3.1.2 (Windows): error page |
| 1601 | // Firefox 3.0.1: blank page |
| 1602 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1603 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1604 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1605 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1606 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1607 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1608 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1609 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1610 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1611 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1612 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1613 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1614 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1615 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1616 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1617 | // Test that network access can be deferred and resumed. |
| 1618 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1619 | HttpRequestInfo request; |
| 1620 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1621 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1622 | request.load_flags = 0; |
| 1623 | |
| 1624 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1625 | scoped_ptr<HttpTransaction> trans( |
| 1626 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1627 | |
| 1628 | // Defer on OnBeforeNetworkStart. |
| 1629 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1630 | trans->SetBeforeNetworkStartCallback( |
| 1631 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1632 | base::Unretained(&net_start_handler))); |
| 1633 | |
| 1634 | MockRead data_reads[] = { |
| 1635 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1636 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1637 | MockRead("hello"), |
| 1638 | MockRead(SYNCHRONOUS, 0), |
| 1639 | }; |
| 1640 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1641 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1642 | |
| 1643 | TestCompletionCallback callback; |
| 1644 | |
| 1645 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1646 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1647 | base::MessageLoop::current()->RunUntilIdle(); |
| 1648 | |
| 1649 | // Should have deferred for network start. |
| 1650 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1651 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1652 | |
| 1653 | trans->ResumeNetworkStart(); |
| 1654 | rv = callback.WaitForResult(); |
| 1655 | EXPECT_EQ(OK, rv); |
| 1656 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1657 | |
| 1658 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1659 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1660 | if (rv == ERR_IO_PENDING) |
| 1661 | rv = callback.WaitForResult(); |
| 1662 | EXPECT_EQ(5, rv); |
| 1663 | trans.reset(); |
| 1664 | } |
| 1665 | |
| 1666 | // Test that network use can be deferred and canceled. |
| 1667 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1668 | HttpRequestInfo request; |
| 1669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1670 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1671 | request.load_flags = 0; |
| 1672 | |
| 1673 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1674 | scoped_ptr<HttpTransaction> trans( |
| 1675 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1676 | |
| 1677 | // Defer on OnBeforeNetworkStart. |
| 1678 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1679 | trans->SetBeforeNetworkStartCallback( |
| 1680 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1681 | base::Unretained(&net_start_handler))); |
| 1682 | |
| 1683 | TestCompletionCallback callback; |
| 1684 | |
| 1685 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1687 | base::MessageLoop::current()->RunUntilIdle(); |
| 1688 | |
| 1689 | // Should have deferred for network start. |
| 1690 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1691 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1692 | } |
| 1693 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1694 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1695 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1696 | // destructor in such situations. |
| 1697 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1698 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1699 | HttpRequestInfo request; |
| 1700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1701 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1702 | request.load_flags = 0; |
| 1703 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1704 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1705 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1706 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1707 | |
| 1708 | MockRead data_reads[] = { |
| 1709 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1710 | MockRead("Connection: keep-alive\r\n"), |
| 1711 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1712 | MockRead("hello"), |
| 1713 | MockRead(SYNCHRONOUS, 0), |
| 1714 | }; |
| 1715 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1716 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1717 | |
| 1718 | TestCompletionCallback callback; |
| 1719 | |
| 1720 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1722 | |
| 1723 | rv = callback.WaitForResult(); |
| 1724 | EXPECT_EQ(OK, rv); |
| 1725 | |
| 1726 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1727 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1728 | if (rv == ERR_IO_PENDING) |
| 1729 | rv = callback.WaitForResult(); |
| 1730 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1731 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1732 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1733 | |
| 1734 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1735 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1736 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1737 | } |
| 1738 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1739 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1740 | HttpRequestInfo request; |
| 1741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1742 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1743 | request.load_flags = 0; |
| 1744 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1745 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1746 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1747 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1748 | |
| 1749 | MockRead data_reads[] = { |
| 1750 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1751 | MockRead("Connection: keep-alive\r\n"), |
| 1752 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1753 | MockRead(SYNCHRONOUS, 0), |
| 1754 | }; |
| 1755 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1757 | |
| 1758 | TestCompletionCallback callback; |
| 1759 | |
| 1760 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1762 | |
| 1763 | rv = callback.WaitForResult(); |
| 1764 | EXPECT_EQ(OK, rv); |
| 1765 | |
| 1766 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1767 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1768 | if (rv == ERR_IO_PENDING) |
| 1769 | rv = callback.WaitForResult(); |
| 1770 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1771 | |
| 1772 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1773 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1774 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1775 | } |
| 1776 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1777 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1778 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1779 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1780 | HttpRequestInfo request; |
| 1781 | request.method = "GET"; |
| 1782 | request.url = GURL("http://www.foo.com/"); |
| 1783 | request.load_flags = 0; |
| 1784 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1785 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1786 | session_deps_.net_log = &net_log; |
| 1787 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1788 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1789 | // Note that because all these reads happen in the same |
| 1790 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1791 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1792 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1793 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1794 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1795 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1796 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1797 | "Content-Length: 0\r\n\r\n"), |
| 1798 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1799 | "Content-Length: 5\r\n\r\n" |
| 1800 | "hello"), |
| 1801 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1802 | "Content-Length: 0\r\n\r\n"), |
| 1803 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1804 | "Content-Length: 5\r\n\r\n" |
| 1805 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1806 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1807 | MockRead("hello"), |
| 1808 | }; |
| 1809 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1810 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1811 | |
| 1812 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1813 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1814 | }; |
| 1815 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1816 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1817 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1818 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1819 | std::string response_lines[kNumUnreadBodies]; |
| 1820 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1821 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1822 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1823 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1824 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1825 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1826 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1827 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1828 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1829 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1830 | |
| 1831 | rv = callback.WaitForResult(); |
| 1832 | EXPECT_EQ(OK, rv); |
| 1833 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1834 | LoadTimingInfo load_timing_info; |
| 1835 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1836 | if (i == 0) { |
| 1837 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1838 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1839 | } else { |
| 1840 | TestLoadTimingReused(load_timing_info); |
| 1841 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1842 | } |
| 1843 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1844 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1845 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1846 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1847 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1848 | response_lines[i] = response->headers->GetStatusLine(); |
| 1849 | |
| 1850 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1851 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1852 | |
| 1853 | const char* const kStatusLines[] = { |
| 1854 | "HTTP/1.1 204 No Content", |
| 1855 | "HTTP/1.1 205 Reset Content", |
| 1856 | "HTTP/1.1 304 Not Modified", |
| 1857 | "HTTP/1.1 302 Found", |
| 1858 | "HTTP/1.1 302 Found", |
| 1859 | "HTTP/1.1 301 Moved Permanently", |
| 1860 | "HTTP/1.1 301 Moved Permanently", |
| 1861 | }; |
| 1862 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1863 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1864 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1865 | |
| 1866 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1867 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1869 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1870 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1871 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1872 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1873 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1874 | rv = callback.WaitForResult(); |
| 1875 | EXPECT_EQ(OK, rv); |
| 1876 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1877 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1878 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1879 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1880 | std::string response_data; |
| 1881 | rv = ReadTransaction(trans.get(), &response_data); |
| 1882 | EXPECT_EQ(OK, rv); |
| 1883 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1884 | } |
| 1885 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1886 | // Test the request-challenge-retry sequence for basic auth. |
| 1887 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1888 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1889 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1890 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1891 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1892 | request.load_flags = 0; |
| 1893 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1894 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1895 | session_deps_.net_log = &log; |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1896 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1897 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1898 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1899 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1900 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1901 | MockWrite( |
| 1902 | "GET / HTTP/1.1\r\n" |
| 1903 | "Host: www.example.org\r\n" |
| 1904 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1905 | }; |
| 1906 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1907 | MockRead data_reads1[] = { |
| 1908 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1909 | // Give a couple authenticate options (only the middle one is actually |
| 1910 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1911 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1912 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1913 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1915 | // Large content-length -- won't matter, as connection will be reset. |
| 1916 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1917 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1918 | }; |
| 1919 | |
| 1920 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1921 | // be issuing -- the final header line contains the credentials. |
| 1922 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1923 | MockWrite( |
| 1924 | "GET / HTTP/1.1\r\n" |
| 1925 | "Host: www.example.org\r\n" |
| 1926 | "Connection: keep-alive\r\n" |
| 1927 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1928 | }; |
| 1929 | |
| 1930 | // Lastly, the server responds with the actual content. |
| 1931 | MockRead data_reads2[] = { |
| 1932 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1933 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1934 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1935 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1936 | }; |
| 1937 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1938 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1939 | data_writes1, arraysize(data_writes1)); |
| 1940 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1941 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1942 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1943 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1945 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1947 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1948 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1949 | |
| 1950 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1951 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1952 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1953 | LoadTimingInfo load_timing_info1; |
| 1954 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1955 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1956 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1957 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 1958 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1959 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1960 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1961 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1962 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1964 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1966 | rv = trans->RestartWithAuth( |
| 1967 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1968 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1969 | |
| 1970 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1971 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1972 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1973 | LoadTimingInfo load_timing_info2; |
| 1974 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 1975 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1976 | // The load timing after restart should have a new socket ID, and times after |
| 1977 | // those of the first load timing. |
| 1978 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 1979 | load_timing_info2.connect_timing.connect_start); |
| 1980 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 1981 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1982 | int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); |
| 1983 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 1984 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1985 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1986 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1987 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1988 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1989 | } |
| 1990 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1991 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1992 | HttpRequestInfo request; |
| 1993 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1994 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1995 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 1996 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 1997 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1998 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1999 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2000 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2001 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2002 | MockWrite( |
| 2003 | "GET / HTTP/1.1\r\n" |
| 2004 | "Host: www.example.org\r\n" |
| 2005 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2006 | }; |
| 2007 | |
| 2008 | MockRead data_reads[] = { |
| 2009 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2010 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2011 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2012 | // Large content-length -- won't matter, as connection will be reset. |
| 2013 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2014 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2015 | }; |
| 2016 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2017 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2018 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2020 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2022 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2023 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2024 | |
| 2025 | rv = callback.WaitForResult(); |
| 2026 | EXPECT_EQ(0, rv); |
| 2027 | |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2028 | int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); |
| 2029 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2030 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2031 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2032 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2033 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2034 | } |
| 2035 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2036 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2037 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2038 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2039 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2040 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2041 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2042 | request.load_flags = 0; |
| 2043 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2044 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2045 | session_deps_.net_log = &log; |
| 2046 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2047 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2048 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2049 | MockWrite( |
| 2050 | "GET / HTTP/1.1\r\n" |
| 2051 | "Host: www.example.org\r\n" |
| 2052 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2053 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2054 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2055 | // be issuing -- the final header line contains the credentials. |
| 2056 | MockWrite( |
| 2057 | "GET / HTTP/1.1\r\n" |
| 2058 | "Host: www.example.org\r\n" |
| 2059 | "Connection: keep-alive\r\n" |
| 2060 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2061 | }; |
| 2062 | |
| 2063 | MockRead data_reads1[] = { |
| 2064 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2065 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2066 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2067 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2068 | MockRead("Unauthorized\r\n"), |
| 2069 | |
| 2070 | // Lastly, the server responds with the actual content. |
| 2071 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2072 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2073 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2074 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2075 | }; |
| 2076 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2077 | // If there is a regression where we disconnect a Keep-Alive |
| 2078 | // connection during an auth roundtrip, we'll end up reading this. |
| 2079 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2080 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2081 | }; |
| 2082 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2083 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2084 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2085 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2086 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2087 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2088 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2090 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2091 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2092 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2093 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2094 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2096 | |
| 2097 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2098 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2099 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2100 | LoadTimingInfo load_timing_info1; |
| 2101 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2102 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2103 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2104 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2105 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2106 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2108 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2110 | rv = trans->RestartWithAuth( |
| 2111 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2112 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2113 | |
| 2114 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2115 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2116 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2117 | LoadTimingInfo load_timing_info2; |
| 2118 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2119 | TestLoadTimingReused(load_timing_info2); |
| 2120 | // The load timing after restart should have the same socket ID, and times |
| 2121 | // those of the first load timing. |
| 2122 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2123 | load_timing_info2.send_start); |
| 2124 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2125 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2126 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2127 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2128 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2129 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2130 | |
| 2131 | std::string response_data; |
| 2132 | rv = ReadTransaction(trans.get(), &response_data); |
| 2133 | EXPECT_EQ(OK, rv); |
| 2134 | int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); |
| 2135 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2139 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2140 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2141 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2142 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2143 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2144 | request.load_flags = 0; |
| 2145 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2146 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2147 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2148 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2149 | MockWrite( |
| 2150 | "GET / HTTP/1.1\r\n" |
| 2151 | "Host: www.example.org\r\n" |
| 2152 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2153 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2154 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2155 | // be issuing -- the final header line contains the credentials. |
| 2156 | MockWrite( |
| 2157 | "GET / HTTP/1.1\r\n" |
| 2158 | "Host: www.example.org\r\n" |
| 2159 | "Connection: keep-alive\r\n" |
| 2160 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2161 | }; |
| 2162 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2163 | MockRead data_reads1[] = { |
| 2164 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2165 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2166 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2167 | |
| 2168 | // Lastly, the server responds with the actual content. |
| 2169 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2170 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2171 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2172 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2173 | }; |
| 2174 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2175 | // An incorrect reconnect would cause this to be read. |
| 2176 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2177 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2178 | }; |
| 2179 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2180 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2181 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2182 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2183 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2184 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2185 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2187 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2188 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2189 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2191 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[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 = callback1.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 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2198 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2199 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2201 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2203 | rv = trans->RestartWithAuth( |
| 2204 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2205 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2206 | |
| 2207 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2208 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2209 | |
| 2210 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2211 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2212 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2213 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2217 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2218 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2219 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2221 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2222 | request.load_flags = 0; |
| 2223 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2224 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2225 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2226 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2227 | MockWrite( |
| 2228 | "GET / HTTP/1.1\r\n" |
| 2229 | "Host: www.example.org\r\n" |
| 2230 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2231 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2232 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2233 | // be issuing -- the final header line contains the credentials. |
| 2234 | MockWrite( |
| 2235 | "GET / HTTP/1.1\r\n" |
| 2236 | "Host: www.example.org\r\n" |
| 2237 | "Connection: keep-alive\r\n" |
| 2238 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2239 | }; |
| 2240 | |
| 2241 | // Respond with 5 kb of response body. |
| 2242 | std::string large_body_string("Unauthorized"); |
| 2243 | large_body_string.append(5 * 1024, ' '); |
| 2244 | large_body_string.append("\r\n"); |
| 2245 | |
| 2246 | MockRead data_reads1[] = { |
| 2247 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2248 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2249 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2250 | // 5134 = 12 + 5 * 1024 + 2 |
| 2251 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2252 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2253 | |
| 2254 | // Lastly, the server responds with the actual content. |
| 2255 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2256 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2257 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2258 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2259 | }; |
| 2260 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2261 | // An incorrect reconnect would cause this to be read. |
| 2262 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2263 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2264 | }; |
| 2265 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2266 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2267 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2268 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2269 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2270 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2271 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2273 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2274 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2275 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2276 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2277 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2278 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2279 | |
| 2280 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2281 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2282 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2283 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2284 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2285 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2287 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2289 | rv = trans->RestartWithAuth( |
| 2290 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2292 | |
| 2293 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2294 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2295 | |
| 2296 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2297 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2298 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2299 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2303 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2304 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2305 | HttpRequestInfo request; |
| 2306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2307 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2308 | request.load_flags = 0; |
| 2309 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2310 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2311 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2312 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2313 | MockWrite( |
| 2314 | "GET / HTTP/1.1\r\n" |
| 2315 | "Host: www.example.org\r\n" |
| 2316 | "Connection: keep-alive\r\n\r\n"), |
| 2317 | // This simulates the seemingly successful write to a closed connection |
| 2318 | // if the bug is not fixed. |
| 2319 | MockWrite( |
| 2320 | "GET / HTTP/1.1\r\n" |
| 2321 | "Host: www.example.org\r\n" |
| 2322 | "Connection: keep-alive\r\n" |
| 2323 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2324 | }; |
| 2325 | |
| 2326 | MockRead data_reads1[] = { |
| 2327 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2328 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2329 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2330 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2331 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2332 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2333 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2334 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2335 | }; |
| 2336 | |
| 2337 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2338 | // be issuing -- the final header line contains the credentials. |
| 2339 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2340 | MockWrite( |
| 2341 | "GET / HTTP/1.1\r\n" |
| 2342 | "Host: www.example.org\r\n" |
| 2343 | "Connection: keep-alive\r\n" |
| 2344 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2345 | }; |
| 2346 | |
| 2347 | // Lastly, the server responds with the actual content. |
| 2348 | MockRead data_reads2[] = { |
| 2349 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2350 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2351 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2352 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2353 | }; |
| 2354 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2355 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2356 | data_writes1, arraysize(data_writes1)); |
| 2357 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2358 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2359 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2360 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2361 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2362 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2363 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2364 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2365 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2366 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2367 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2368 | |
| 2369 | rv = callback1.WaitForResult(); |
| 2370 | EXPECT_EQ(OK, rv); |
| 2371 | |
| 2372 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2373 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2374 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2376 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2378 | rv = trans->RestartWithAuth( |
| 2379 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2380 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2381 | |
| 2382 | rv = callback2.WaitForResult(); |
| 2383 | EXPECT_EQ(OK, rv); |
| 2384 | |
| 2385 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2386 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2387 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2388 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2389 | } |
| 2390 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2391 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2392 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2393 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2394 | HttpRequestInfo request; |
| 2395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2396 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2397 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2398 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2399 | |
| 2400 | // Configure against proxy server "myproxy:70". |
| 2401 | session_deps_.proxy_service.reset( |
| 2402 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2403 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2404 | session_deps_.net_log = log.bound().net_log(); |
| 2405 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2406 | |
| 2407 | // Since we have proxy, should try to establish tunnel. |
| 2408 | MockWrite data_writes1[] = { |
| 2409 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2410 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2411 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2412 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2413 | |
| 2414 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2415 | // be issuing -- the final header line contains the credentials. |
| 2416 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2417 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2418 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2419 | "Proxy-Connection: keep-alive\r\n" |
| 2420 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2421 | |
| 2422 | MockWrite( |
| 2423 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2424 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2425 | "Connection: keep-alive\r\n\r\n"), |
| 2426 | }; |
| 2427 | |
| 2428 | // The proxy responds to the connect with a 407, using a persistent |
| 2429 | // connection. |
| 2430 | MockRead data_reads1[] = { |
| 2431 | // No credentials. |
| 2432 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2433 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 2434 | |
| 2435 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2436 | |
| 2437 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2438 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2439 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2440 | MockRead(SYNCHRONOUS, "hello"), |
| 2441 | }; |
| 2442 | |
| 2443 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2444 | data_writes1, arraysize(data_writes1)); |
| 2445 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2446 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2448 | |
| 2449 | TestCompletionCallback callback1; |
| 2450 | |
| 2451 | scoped_ptr<HttpTransaction> trans( |
| 2452 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2453 | |
| 2454 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2455 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2456 | |
| 2457 | rv = callback1.WaitForResult(); |
| 2458 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2459 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2460 | log.GetEntries(&entries); |
| 2461 | size_t pos = ExpectLogContainsSomewhere( |
| 2462 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2463 | NetLog::PHASE_NONE); |
| 2464 | ExpectLogContainsSomewhere( |
| 2465 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2466 | NetLog::PHASE_NONE); |
| 2467 | |
| 2468 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2469 | ASSERT_TRUE(response != NULL); |
| 2470 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2471 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2472 | EXPECT_EQ(407, response->headers->response_code()); |
| 2473 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2474 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2475 | |
| 2476 | LoadTimingInfo load_timing_info; |
| 2477 | // CONNECT requests and responses are handled at the connect job level, so |
| 2478 | // the transaction does not yet have a connection. |
| 2479 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2480 | |
| 2481 | TestCompletionCallback callback2; |
| 2482 | |
| 2483 | rv = |
| 2484 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2485 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2486 | |
| 2487 | rv = callback2.WaitForResult(); |
| 2488 | EXPECT_EQ(OK, rv); |
| 2489 | |
| 2490 | response = trans->GetResponseInfo(); |
| 2491 | ASSERT_TRUE(response != NULL); |
| 2492 | |
| 2493 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2494 | EXPECT_EQ(200, response->headers->response_code()); |
| 2495 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2496 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2497 | |
| 2498 | // The password prompt info should not be set. |
| 2499 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2500 | |
| 2501 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2502 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2503 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2504 | |
| 2505 | trans.reset(); |
| 2506 | session->CloseAllConnections(); |
| 2507 | } |
| 2508 | |
| 2509 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2510 | // that requires a restart when setting up an SSL tunnel. |
| 2511 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2512 | HttpRequestInfo request; |
| 2513 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2514 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2515 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2516 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2517 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2518 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2519 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2520 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2521 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2522 | session_deps_.net_log = log.bound().net_log(); |
| 2523 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2524 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2525 | // Since we have proxy, should try to establish tunnel. |
| 2526 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2527 | MockWrite( |
| 2528 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2529 | "Host: www.example.org\r\n" |
| 2530 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2531 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2532 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2533 | // be issuing -- the final header line contains the credentials. |
| 2534 | MockWrite( |
| 2535 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2536 | "Host: www.example.org\r\n" |
| 2537 | "Proxy-Connection: keep-alive\r\n" |
| 2538 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2539 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2540 | MockWrite( |
| 2541 | "GET / HTTP/1.1\r\n" |
| 2542 | "Host: www.example.org\r\n" |
| 2543 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2544 | }; |
| 2545 | |
| 2546 | // The proxy responds to the connect with a 407, using a persistent |
| 2547 | // connection. |
| 2548 | MockRead data_reads1[] = { |
| 2549 | // No credentials. |
| 2550 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2551 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2552 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2553 | |
| 2554 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2555 | |
| 2556 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2557 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2558 | MockRead("Content-Length: 5\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2559 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2560 | }; |
| 2561 | |
| 2562 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2563 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2564 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2565 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2568 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2569 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2570 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2571 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2572 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2573 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2574 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2575 | |
| 2576 | rv = callback1.WaitForResult(); |
| 2577 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2578 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2579 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2580 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2581 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2582 | NetLog::PHASE_NONE); |
| 2583 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2584 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2585 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2586 | NetLog::PHASE_NONE); |
| 2587 | |
| 2588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2589 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2590 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2591 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2592 | EXPECT_EQ(407, response->headers->response_code()); |
| 2593 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2594 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2595 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2596 | LoadTimingInfo load_timing_info; |
| 2597 | // CONNECT requests and responses are handled at the connect job level, so |
| 2598 | // the transaction does not yet have a connection. |
| 2599 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2601 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2603 | rv = trans->RestartWithAuth( |
| 2604 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2605 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2606 | |
| 2607 | rv = callback2.WaitForResult(); |
| 2608 | EXPECT_EQ(OK, rv); |
| 2609 | |
| 2610 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2611 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2612 | |
| 2613 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2614 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2615 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2616 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2617 | |
| 2618 | // The password prompt info should not be set. |
| 2619 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2620 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2621 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2622 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2623 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2624 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2625 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2626 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2627 | } |
| 2628 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2629 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2630 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2631 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2632 | HttpRequestInfo request; |
| 2633 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2634 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2635 | // Ensure that proxy authentication is attempted even |
| 2636 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2637 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2638 | |
| 2639 | // Configure against proxy server "myproxy:70". |
| 2640 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2641 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2642 | session_deps_.net_log = log.bound().net_log(); |
| 2643 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2644 | |
| 2645 | scoped_ptr<HttpTransaction> trans( |
| 2646 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2647 | |
| 2648 | // Since we have proxy, should try to establish tunnel. |
| 2649 | MockWrite data_writes1[] = { |
| 2650 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2651 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2652 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2653 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2654 | |
| 2655 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2656 | // be issuing -- the final header line contains the credentials. |
| 2657 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2658 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2659 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2660 | "Proxy-Connection: keep-alive\r\n" |
| 2661 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2662 | }; |
| 2663 | |
| 2664 | // The proxy responds to the connect with a 407, using a persistent |
| 2665 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2666 | MockRead data_reads1[] = { |
| 2667 | // No credentials. |
| 2668 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2669 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2670 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2671 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2672 | MockRead("0123456789"), |
| 2673 | |
| 2674 | // Wrong credentials (wrong password). |
| 2675 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2676 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2677 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2678 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2679 | // No response body because the test stops reading here. |
| 2680 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2681 | }; |
| 2682 | |
| 2683 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2684 | data_writes1, arraysize(data_writes1)); |
| 2685 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2686 | |
| 2687 | TestCompletionCallback callback1; |
| 2688 | |
| 2689 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2690 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2691 | |
| 2692 | rv = callback1.WaitForResult(); |
| 2693 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2694 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2695 | log.GetEntries(&entries); |
| 2696 | size_t pos = ExpectLogContainsSomewhere( |
| 2697 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2698 | NetLog::PHASE_NONE); |
| 2699 | ExpectLogContainsSomewhere( |
| 2700 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2701 | NetLog::PHASE_NONE); |
| 2702 | |
| 2703 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2704 | ASSERT_TRUE(response); |
| 2705 | ASSERT_TRUE(response->headers); |
| 2706 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2707 | EXPECT_EQ(407, response->headers->response_code()); |
| 2708 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2709 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2710 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2711 | |
| 2712 | TestCompletionCallback callback2; |
| 2713 | |
| 2714 | // Wrong password (should be "bar"). |
| 2715 | rv = |
| 2716 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2718 | |
| 2719 | rv = callback2.WaitForResult(); |
| 2720 | EXPECT_EQ(OK, rv); |
| 2721 | |
| 2722 | response = trans->GetResponseInfo(); |
| 2723 | ASSERT_TRUE(response); |
| 2724 | ASSERT_TRUE(response->headers); |
| 2725 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2726 | EXPECT_EQ(407, response->headers->response_code()); |
| 2727 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2728 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2729 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2730 | |
| 2731 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2732 | // out of scope. |
| 2733 | session->CloseAllConnections(); |
| 2734 | } |
| 2735 | |
| 2736 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2737 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2738 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2739 | HttpRequestInfo request; |
| 2740 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2741 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2742 | // Ensure that proxy authentication is attempted even |
| 2743 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2744 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2745 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2746 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2747 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2748 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2749 | session_deps_.net_log = log.bound().net_log(); |
| 2750 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2751 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2752 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2753 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2754 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2755 | // Since we have proxy, should try to establish tunnel. |
| 2756 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2757 | MockWrite( |
| 2758 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2759 | "Host: www.example.org\r\n" |
| 2760 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2761 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2762 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2763 | // be issuing -- the final header line contains the credentials. |
| 2764 | MockWrite( |
| 2765 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2766 | "Host: www.example.org\r\n" |
| 2767 | "Proxy-Connection: keep-alive\r\n" |
| 2768 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2769 | }; |
| 2770 | |
| 2771 | // The proxy responds to the connect with a 407, using a persistent |
| 2772 | // connection. |
| 2773 | MockRead data_reads1[] = { |
| 2774 | // No credentials. |
| 2775 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2776 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2777 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2778 | MockRead("0123456789"), |
| 2779 | |
| 2780 | // Wrong credentials (wrong password). |
| 2781 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2782 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2783 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2784 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2785 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | }; |
| 2787 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2788 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2789 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2790 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2792 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2794 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2795 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | |
| 2797 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2798 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2799 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2800 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2801 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2802 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2803 | NetLog::PHASE_NONE); |
| 2804 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2805 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2806 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2807 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2808 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2809 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2810 | ASSERT_TRUE(response); |
| 2811 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2812 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2813 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2814 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2815 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2816 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2818 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | |
| 2820 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2821 | rv = trans->RestartWithAuth( |
| 2822 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2824 | |
| 2825 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2826 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2827 | |
| 2828 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2829 | ASSERT_TRUE(response); |
| 2830 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2831 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2832 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2833 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2834 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2835 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2836 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2837 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2838 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2839 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2840 | } |
| 2841 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2842 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 2843 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2844 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2845 | HttpRequestInfo request; |
| 2846 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2847 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2848 | request.load_flags = 0; |
| 2849 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2850 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2851 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2852 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2853 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2854 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2855 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2856 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2857 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2858 | // Since we have proxy, should try to establish tunnel. |
| 2859 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2860 | MockWrite( |
| 2861 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2862 | "Host: www.example.org\r\n" |
| 2863 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2864 | }; |
| 2865 | |
| 2866 | // The proxy responds to the connect with a 407. |
| 2867 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2868 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2869 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2870 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2871 | MockRead("0123456789"), // Should not be reached. |
| 2872 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2873 | }; |
| 2874 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2875 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2876 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2879 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2881 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2882 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2883 | |
| 2884 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2885 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2886 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2887 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2888 | ASSERT_TRUE(response); |
| 2889 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2890 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2891 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2892 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2893 | |
| 2894 | std::string response_data; |
| 2895 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2896 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2897 | |
| 2898 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2899 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 2900 | } |
| 2901 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2902 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 2903 | // caller when the proxy responds to CONNECT with 407. |
| 2904 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 2905 | HttpRequestInfo request; |
| 2906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2907 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2908 | request.load_flags = 0; |
| 2909 | |
| 2910 | // Configure against proxy server "myproxy:70". |
| 2911 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
| 2912 | |
| 2913 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2914 | |
| 2915 | scoped_ptr<HttpTransaction> trans( |
| 2916 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2917 | |
| 2918 | // Since we have proxy, should try to establish tunnel. |
| 2919 | MockWrite data_writes[] = { |
| 2920 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2921 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2922 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2923 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2924 | }; |
| 2925 | |
| 2926 | // The proxy responds to the connect with a 407. |
| 2927 | MockRead data_reads[] = { |
| 2928 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2929 | MockRead("X-Foo: bar\r\n"), |
| 2930 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 2931 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2932 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2933 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2934 | }; |
| 2935 | |
| 2936 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2937 | arraysize(data_writes)); |
| 2938 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2939 | |
| 2940 | TestCompletionCallback callback; |
| 2941 | |
| 2942 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 2943 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2944 | |
| 2945 | rv = callback.WaitForResult(); |
| 2946 | EXPECT_EQ(OK, rv); |
| 2947 | |
| 2948 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2949 | ASSERT_TRUE(response); |
| 2950 | ASSERT_TRUE(response->headers); |
| 2951 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2952 | EXPECT_EQ(407, response->headers->response_code()); |
| 2953 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2954 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 2955 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 2956 | |
| 2957 | std::string response_data; |
| 2958 | rv = ReadTransaction(trans.get(), &response_data); |
| 2959 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 2960 | |
| 2961 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 2962 | session->CloseAllConnections(); |
| 2963 | } |
| 2964 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2965 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 2966 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2967 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2968 | HttpRequestInfo request; |
| 2969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2970 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2971 | request.load_flags = 0; |
| 2972 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2973 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 2974 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2975 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2976 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2977 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2978 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2979 | MockWrite( |
| 2980 | "GET / HTTP/1.1\r\n" |
| 2981 | "Host: www.example.org\r\n" |
| 2982 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2983 | }; |
| 2984 | |
| 2985 | MockRead data_reads1[] = { |
| 2986 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 2987 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2988 | // Large content-length -- won't matter, as connection will be reset. |
| 2989 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2990 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2991 | }; |
| 2992 | |
| 2993 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2994 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2995 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2997 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 2998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2999 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3000 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3001 | |
| 3002 | rv = callback.WaitForResult(); |
| 3003 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3004 | } |
| 3005 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3006 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3007 | // through a non-authenticating proxy. The request should fail with |
| 3008 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3009 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3010 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3011 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3012 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3013 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3014 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3015 | HttpRequestInfo request; |
| 3016 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3017 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3018 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3019 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3020 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3021 | session_deps_.net_log = log.bound().net_log(); |
| 3022 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3023 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3024 | // Since we have proxy, should try to establish tunnel. |
| 3025 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3026 | MockWrite( |
| 3027 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3028 | "Host: www.example.org\r\n" |
| 3029 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3030 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3031 | MockWrite( |
| 3032 | "GET / HTTP/1.1\r\n" |
| 3033 | "Host: www.example.org\r\n" |
| 3034 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3035 | }; |
| 3036 | |
| 3037 | MockRead data_reads1[] = { |
| 3038 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3039 | |
| 3040 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3041 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3042 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3043 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3044 | }; |
| 3045 | |
| 3046 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3047 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3048 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3049 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3052 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3053 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3054 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3057 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3059 | |
| 3060 | rv = callback1.WaitForResult(); |
| 3061 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3062 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3063 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3064 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3065 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3066 | NetLog::PHASE_NONE); |
| 3067 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3068 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3069 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3070 | NetLog::PHASE_NONE); |
| 3071 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3072 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3073 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3074 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3075 | HttpRequestInfo request1; |
| 3076 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3077 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3078 | |
| 3079 | HttpRequestInfo request2; |
| 3080 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3081 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3082 | |
| 3083 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3084 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3085 | ProxyService::CreateFixed("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3086 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3087 | session_deps_.net_log = log.bound().net_log(); |
| 3088 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3089 | |
| 3090 | // Since we have proxy, should try to establish tunnel. |
| 3091 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3092 | MockWrite( |
| 3093 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3094 | "Host: www.example.org\r\n" |
| 3095 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3096 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3097 | MockWrite( |
| 3098 | "GET /1 HTTP/1.1\r\n" |
| 3099 | "Host: www.example.org\r\n" |
| 3100 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3101 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3102 | MockWrite( |
| 3103 | "GET /2 HTTP/1.1\r\n" |
| 3104 | "Host: www.example.org\r\n" |
| 3105 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3106 | }; |
| 3107 | |
| 3108 | // The proxy responds to the connect with a 407, using a persistent |
| 3109 | // connection. |
| 3110 | MockRead data_reads1[] = { |
| 3111 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3112 | |
| 3113 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3114 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3115 | MockRead(SYNCHRONOUS, "1"), |
| 3116 | |
| 3117 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3118 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3119 | MockRead(SYNCHRONOUS, "22"), |
| 3120 | }; |
| 3121 | |
| 3122 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3123 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3124 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3125 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3127 | |
| 3128 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3129 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3131 | |
| 3132 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3133 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3134 | |
| 3135 | rv = callback1.WaitForResult(); |
| 3136 | EXPECT_EQ(OK, rv); |
| 3137 | |
| 3138 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3139 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3140 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3141 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3142 | |
| 3143 | LoadTimingInfo load_timing_info1; |
| 3144 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3145 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3146 | |
| 3147 | trans1.reset(); |
| 3148 | |
| 3149 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3150 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3151 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3152 | |
| 3153 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3155 | |
| 3156 | rv = callback2.WaitForResult(); |
| 3157 | EXPECT_EQ(OK, rv); |
| 3158 | |
| 3159 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3160 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3161 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3162 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3163 | |
| 3164 | LoadTimingInfo load_timing_info2; |
| 3165 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3166 | TestLoadTimingReused(load_timing_info2); |
| 3167 | |
| 3168 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3169 | |
| 3170 | trans2.reset(); |
| 3171 | session->CloseAllConnections(); |
| 3172 | } |
| 3173 | |
| 3174 | // 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] | 3175 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3176 | HttpRequestInfo request1; |
| 3177 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3178 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3179 | |
| 3180 | HttpRequestInfo request2; |
| 3181 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3182 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3183 | |
| 3184 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3185 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3186 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3187 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3188 | session_deps_.net_log = log.bound().net_log(); |
| 3189 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3190 | |
| 3191 | // Since we have proxy, should try to establish tunnel. |
| 3192 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3193 | MockWrite( |
| 3194 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3195 | "Host: www.example.org\r\n" |
| 3196 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3197 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3198 | MockWrite( |
| 3199 | "GET /1 HTTP/1.1\r\n" |
| 3200 | "Host: www.example.org\r\n" |
| 3201 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3202 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3203 | MockWrite( |
| 3204 | "GET /2 HTTP/1.1\r\n" |
| 3205 | "Host: www.example.org\r\n" |
| 3206 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3207 | }; |
| 3208 | |
| 3209 | // The proxy responds to the connect with a 407, using a persistent |
| 3210 | // connection. |
| 3211 | MockRead data_reads1[] = { |
| 3212 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3213 | |
| 3214 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3215 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3216 | MockRead(SYNCHRONOUS, "1"), |
| 3217 | |
| 3218 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3219 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3220 | MockRead(SYNCHRONOUS, "22"), |
| 3221 | }; |
| 3222 | |
| 3223 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3224 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3225 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3226 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3228 | |
| 3229 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3230 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3231 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3232 | |
| 3233 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3234 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3235 | |
| 3236 | rv = callback1.WaitForResult(); |
| 3237 | EXPECT_EQ(OK, rv); |
| 3238 | |
| 3239 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3240 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3241 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3242 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3243 | |
| 3244 | LoadTimingInfo load_timing_info1; |
| 3245 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3246 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3247 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3248 | |
| 3249 | trans1.reset(); |
| 3250 | |
| 3251 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3252 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3253 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3254 | |
| 3255 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3256 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3257 | |
| 3258 | rv = callback2.WaitForResult(); |
| 3259 | EXPECT_EQ(OK, rv); |
| 3260 | |
| 3261 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3262 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3263 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3264 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3265 | |
| 3266 | LoadTimingInfo load_timing_info2; |
| 3267 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3268 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3269 | |
| 3270 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3271 | |
| 3272 | trans2.reset(); |
| 3273 | session->CloseAllConnections(); |
| 3274 | } |
| 3275 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3276 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3277 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3278 | HttpRequestInfo request; |
| 3279 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3280 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3281 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3282 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3283 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3284 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3285 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3286 | session_deps_.net_log = log.bound().net_log(); |
| 3287 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3288 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3289 | // Since we have proxy, should use full url |
| 3290 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3291 | MockWrite( |
| 3292 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3293 | "Host: www.example.org\r\n" |
| 3294 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3295 | }; |
| 3296 | |
| 3297 | MockRead data_reads1[] = { |
| 3298 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3299 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3300 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3301 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3302 | }; |
| 3303 | |
| 3304 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3305 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3306 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3307 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3310 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3311 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3312 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3313 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3315 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3316 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3317 | |
| 3318 | rv = callback1.WaitForResult(); |
| 3319 | EXPECT_EQ(OK, rv); |
| 3320 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3321 | LoadTimingInfo load_timing_info; |
| 3322 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3323 | TestLoadTimingNotReused(load_timing_info, |
| 3324 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3325 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3326 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 3327 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3328 | |
| 3329 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3330 | EXPECT_EQ(200, response->headers->response_code()); |
| 3331 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3332 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3333 | |
| 3334 | // The password prompt info should not be set. |
| 3335 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3336 | } |
| 3337 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3338 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3339 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3340 | HttpRequestInfo request; |
| 3341 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3342 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3343 | request.load_flags = 0; |
| 3344 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3345 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3346 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3347 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3348 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3349 | session_deps_.net_log = log.bound().net_log(); |
| 3350 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3351 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3352 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3353 | scoped_ptr<SpdyFrame> req( |
| 3354 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3355 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3356 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3357 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3358 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3359 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3360 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3361 | }; |
| 3362 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3363 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3364 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3365 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3366 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3367 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3368 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3371 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3372 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3373 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3376 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3377 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3378 | |
| 3379 | rv = callback1.WaitForResult(); |
| 3380 | EXPECT_EQ(OK, rv); |
| 3381 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3382 | LoadTimingInfo load_timing_info; |
| 3383 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3384 | TestLoadTimingNotReused(load_timing_info, |
| 3385 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 3386 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3387 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3388 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3389 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3390 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3391 | |
| 3392 | std::string response_data; |
| 3393 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3394 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 3395 | } |
| 3396 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3397 | // Verifies that a session which races and wins against the owning transaction |
| 3398 | // (completing prior to host resolution), doesn't fail the transaction. |
| 3399 | // Regression test for crbug.com/334413. |
| 3400 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 3401 | HttpRequestInfo request; |
| 3402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3404 | request.load_flags = 0; |
| 3405 | |
| 3406 | // Configure SPDY proxy server "proxy:70". |
| 3407 | session_deps_.proxy_service.reset( |
| 3408 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3409 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3410 | session_deps_.net_log = log.bound().net_log(); |
| 3411 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3412 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3413 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3414 | scoped_ptr<SpdyFrame> req( |
| 3415 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3416 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3417 | |
| 3418 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3419 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3420 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3421 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3422 | }; |
| 3423 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3424 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3425 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 3426 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 3427 | |
| 3428 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3429 | ssl.SetNextProto(GetParam()); |
| 3430 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3431 | |
| 3432 | TestCompletionCallback callback1; |
| 3433 | |
| 3434 | scoped_ptr<HttpTransaction> trans( |
| 3435 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3436 | |
| 3437 | // Stall the hostname resolution begun by the transaction. |
| 3438 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 3439 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3440 | |
| 3441 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3442 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3443 | |
| 3444 | // Race a session to the proxy, which completes first. |
| 3445 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 3446 | SpdySessionKey key( |
| 3447 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 3448 | base::WeakPtr<SpdySession> spdy_session = |
| 3449 | CreateSecureSpdySession(session, key, log.bound()); |
| 3450 | |
| 3451 | // Unstall the resolution begun by the transaction. |
| 3452 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 3453 | session_deps_.host_resolver->ResolveAllPending(); |
| 3454 | |
| 3455 | EXPECT_FALSE(callback1.have_result()); |
| 3456 | rv = callback1.WaitForResult(); |
| 3457 | EXPECT_EQ(OK, rv); |
| 3458 | |
| 3459 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3460 | ASSERT_TRUE(response != NULL); |
| 3461 | ASSERT_TRUE(response->headers.get() != NULL); |
| 3462 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3463 | |
| 3464 | std::string response_data; |
| 3465 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3466 | EXPECT_EQ(kUploadData, response_data); |
| 3467 | } |
| 3468 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3469 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3470 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3471 | HttpRequestInfo request; |
| 3472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3473 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3474 | request.load_flags = 0; |
| 3475 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3476 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3477 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3478 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3479 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3480 | session_deps_.net_log = log.bound().net_log(); |
| 3481 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3482 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3483 | // The first request will be a bare GET, the second request will be a |
| 3484 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3485 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3486 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3487 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3488 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3489 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3490 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3491 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 3492 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 3493 | false, |
| 3494 | 3, |
| 3495 | LOWEST, |
| 3496 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3497 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3498 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3499 | }; |
| 3500 | |
| 3501 | // The first response is a 407 proxy authentication challenge, and the second |
| 3502 | // response will be a 200 response since the second request includes a valid |
| 3503 | // Authorization header. |
| 3504 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3505 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3506 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3507 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3508 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3509 | "407 Proxy Authentication Required", |
| 3510 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 3511 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3512 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3513 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3514 | scoped_ptr<SpdyFrame> resp_data( |
| 3515 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3516 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3517 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3518 | CreateMockRead(*resp_authentication, 1), |
| 3519 | CreateMockRead(*body_authentication, 2), |
| 3520 | CreateMockRead(*resp_data, 4), |
| 3521 | CreateMockRead(*body_data, 5), |
| 3522 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3523 | }; |
| 3524 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3525 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3526 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3527 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3528 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3529 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3530 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3533 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3534 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3535 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3536 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3537 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3538 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3539 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3540 | |
| 3541 | rv = callback1.WaitForResult(); |
| 3542 | EXPECT_EQ(OK, rv); |
| 3543 | |
| 3544 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 3545 | |
| 3546 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3547 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3548 | EXPECT_EQ(407, response->headers->response_code()); |
| 3549 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3550 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3552 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3554 | rv = trans->RestartWithAuth( |
| 3555 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3556 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3557 | |
| 3558 | rv = callback2.WaitForResult(); |
| 3559 | EXPECT_EQ(OK, rv); |
| 3560 | |
| 3561 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 3562 | |
| 3563 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3564 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 3565 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 3566 | // The password prompt info should not be set. |
| 3567 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 3568 | } |
| 3569 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3570 | // 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] | 3571 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3572 | HttpRequestInfo request; |
| 3573 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3574 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3575 | request.load_flags = 0; |
| 3576 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3577 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3578 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3579 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3580 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3581 | session_deps_.net_log = log.bound().net_log(); |
| 3582 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3583 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3584 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3585 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3586 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3587 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3588 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3589 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3590 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3591 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3592 | const char get[] = |
| 3593 | "GET / HTTP/1.1\r\n" |
| 3594 | "Host: www.example.org\r\n" |
| 3595 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3596 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3597 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 3598 | scoped_ptr<SpdyFrame> conn_resp( |
| 3599 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3600 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 3601 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3602 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3603 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3604 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3605 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3606 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3607 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3608 | |
| 3609 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3610 | CreateMockWrite(*connect, 0), |
| 3611 | CreateMockWrite(*wrapped_get, 2), |
| 3612 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3613 | }; |
| 3614 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3615 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3616 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3617 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 3618 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 3619 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 3620 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3621 | }; |
| 3622 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3623 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3624 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3625 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3626 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3627 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3628 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3630 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3633 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3635 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3636 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3637 | |
| 3638 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3639 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3640 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3641 | LoadTimingInfo load_timing_info; |
| 3642 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3643 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3644 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3645 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3646 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3647 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3648 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3649 | |
| 3650 | std::string response_data; |
| 3651 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 3652 | EXPECT_EQ("1234567890", response_data); |
| 3653 | } |
| 3654 | |
| 3655 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3656 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3657 | HttpRequestInfo request; |
| 3658 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3659 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3660 | request.load_flags = 0; |
| 3661 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3662 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3663 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3664 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3665 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3666 | session_deps_.net_log = log.bound().net_log(); |
| 3667 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3668 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3669 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3670 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3671 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3672 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3673 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3674 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 3675 | // fetch https://www.example.org/ via SPDY |
| 3676 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3677 | scoped_ptr<SpdyFrame> get( |
| 3678 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3679 | scoped_ptr<SpdyFrame> wrapped_get( |
| 3680 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 3681 | scoped_ptr<SpdyFrame> conn_resp( |
| 3682 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3683 | scoped_ptr<SpdyFrame> get_resp( |
| 3684 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3685 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3686 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 3687 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3688 | scoped_ptr<SpdyFrame> wrapped_body( |
| 3689 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3690 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3691 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3692 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3693 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3694 | |
| 3695 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3696 | CreateMockWrite(*connect, 0), |
| 3697 | CreateMockWrite(*wrapped_get, 2), |
| 3698 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 3699 | CreateMockWrite(*window_update_body, 7), |
| 3700 | }; |
| 3701 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3702 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3703 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 3704 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3705 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3706 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3707 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3708 | }; |
| 3709 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3710 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3711 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3712 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3713 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3714 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3715 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3717 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3718 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3721 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3723 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3724 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3725 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3726 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 3727 | base::MessageLoop::current()->RunUntilIdle(); |
| 3728 | // Now allow the read of the response to complete. |
| 3729 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3730 | rv = callback1.WaitForResult(); |
| 3731 | EXPECT_EQ(OK, rv); |
| 3732 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3733 | LoadTimingInfo load_timing_info; |
| 3734 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3735 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3736 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3737 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3738 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3739 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3740 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3741 | |
| 3742 | std::string response_data; |
| 3743 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3744 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3748 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3749 | HttpRequestInfo request; |
| 3750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3751 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3752 | request.load_flags = 0; |
| 3753 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3754 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3755 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 3756 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3757 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3758 | session_deps_.net_log = log.bound().net_log(); |
| 3759 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3760 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3761 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3763 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3764 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3765 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3766 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3767 | scoped_ptr<SpdyFrame> get( |
| 3768 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3769 | |
| 3770 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3771 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3772 | }; |
| 3773 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3774 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 3775 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3776 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3777 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3778 | }; |
| 3779 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 3780 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3781 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3782 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3783 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3784 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3785 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3787 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3788 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3791 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3793 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3794 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3795 | |
| 3796 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3797 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3798 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 3799 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 3800 | } |
| 3801 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3802 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3803 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3804 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3805 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 3806 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3807 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3808 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3809 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3810 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3811 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3812 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3813 | |
| 3814 | HttpRequestInfo request1; |
| 3815 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3816 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3817 | request1.load_flags = 0; |
| 3818 | |
| 3819 | HttpRequestInfo request2; |
| 3820 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3821 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3822 | request2.load_flags = 0; |
| 3823 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3824 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3825 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3826 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3827 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3828 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3829 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3830 | // Fetch https://www.example.org/ via HTTP. |
| 3831 | const char get1[] = |
| 3832 | "GET / HTTP/1.1\r\n" |
| 3833 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3834 | "Connection: keep-alive\r\n\r\n"; |
| 3835 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3836 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3837 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3838 | "Content-Length: 1\r\n\r\n"; |
| 3839 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3840 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3841 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3842 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3843 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3844 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3845 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3846 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3847 | SpdyHeaderBlock connect2_block; |
| 3848 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 3849 | if (GetParam() >= kProtoHTTP2MinimumVersion) { |
| 3850 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 3851 | } else { |
| 3852 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
| 3853 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
| 3854 | } |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3855 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3856 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3857 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3858 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3859 | scoped_ptr<SpdyFrame> conn_resp2( |
| 3860 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3861 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3862 | // Fetch https://mail.example.org/ via HTTP. |
| 3863 | const char get2[] = |
| 3864 | "GET / HTTP/1.1\r\n" |
| 3865 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3866 | "Connection: keep-alive\r\n\r\n"; |
| 3867 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3868 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3869 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3870 | "Content-Length: 2\r\n\r\n"; |
| 3871 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3872 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3873 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3874 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3875 | |
| 3876 | MockWrite spdy_writes[] = { |
| 3877 | CreateMockWrite(*connect1, 0), |
| 3878 | CreateMockWrite(*wrapped_get1, 2), |
| 3879 | CreateMockWrite(*connect2, 5), |
| 3880 | CreateMockWrite(*wrapped_get2, 7), |
| 3881 | }; |
| 3882 | |
| 3883 | MockRead spdy_reads[] = { |
| 3884 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 3885 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 3886 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 3887 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 3888 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 3889 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 3890 | MockRead(ASYNC, 0, 10), |
| 3891 | }; |
| 3892 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3893 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 3894 | arraysize(spdy_writes)); |
| 3895 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3896 | |
| 3897 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3898 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3900 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3902 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3904 | |
| 3905 | TestCompletionCallback callback; |
| 3906 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3907 | scoped_ptr<HttpTransaction> trans( |
[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 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3910 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3911 | |
| 3912 | LoadTimingInfo load_timing_info; |
| 3913 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3914 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3915 | |
| 3916 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3917 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3918 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3919 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3920 | |
| 3921 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3922 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3923 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 3924 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3925 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3926 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3928 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3929 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3930 | |
| 3931 | LoadTimingInfo load_timing_info2; |
| 3932 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3933 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 3934 | // to be created, so the socket's load timing looks like a fresh connection. |
| 3935 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3936 | |
| 3937 | // The requests should have different IDs, since they each are using their own |
| 3938 | // separate stream. |
| 3939 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 3940 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3941 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 3942 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 3946 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3947 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3948 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 3949 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3950 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3951 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3952 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3953 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3954 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 3955 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3956 | |
| 3957 | HttpRequestInfo request1; |
| 3958 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3959 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3960 | request1.load_flags = 0; |
| 3961 | |
| 3962 | HttpRequestInfo request2; |
| 3963 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3964 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3965 | request2.load_flags = 0; |
| 3966 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3967 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 3968 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3969 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3970 | scoped_ptr<SpdyFrame> conn_resp1( |
| 3971 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3972 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3973 | // Fetch https://www.example.org/ via HTTP. |
| 3974 | const char get1[] = |
| 3975 | "GET / HTTP/1.1\r\n" |
| 3976 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3977 | "Connection: keep-alive\r\n\r\n"; |
| 3978 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3979 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3980 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3981 | "Content-Length: 1\r\n\r\n"; |
| 3982 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3983 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3984 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 3985 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3986 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3987 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3988 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3989 | // Fetch https://www.example.org/2 via HTTP. |
| 3990 | const char get2[] = |
| 3991 | "GET /2 HTTP/1.1\r\n" |
| 3992 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3993 | "Connection: keep-alive\r\n\r\n"; |
| 3994 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3995 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 3996 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 3997 | "Content-Length: 2\r\n\r\n"; |
| 3998 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3999 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4000 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4001 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4002 | |
| 4003 | MockWrite spdy_writes[] = { |
| 4004 | CreateMockWrite(*connect1, 0), |
| 4005 | CreateMockWrite(*wrapped_get1, 2), |
| 4006 | CreateMockWrite(*wrapped_get2, 5), |
| 4007 | }; |
| 4008 | |
| 4009 | MockRead spdy_reads[] = { |
| 4010 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4011 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4012 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4013 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4014 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4015 | MockRead(ASYNC, 0, 8), |
| 4016 | }; |
| 4017 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4018 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4019 | arraysize(spdy_writes)); |
| 4020 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4021 | |
| 4022 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4023 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4025 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4026 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4027 | |
| 4028 | TestCompletionCallback callback; |
| 4029 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4030 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4031 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4032 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4034 | |
| 4035 | rv = callback.WaitForResult(); |
| 4036 | EXPECT_EQ(OK, rv); |
| 4037 | |
| 4038 | LoadTimingInfo load_timing_info; |
| 4039 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4040 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4041 | |
| 4042 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4043 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4044 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4045 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4046 | |
| 4047 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4048 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4049 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4050 | trans.reset(); |
| 4051 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4052 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4053 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4054 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4055 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4056 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4057 | rv = callback.WaitForResult(); |
| 4058 | EXPECT_EQ(OK, rv); |
| 4059 | |
| 4060 | LoadTimingInfo load_timing_info2; |
| 4061 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4062 | TestLoadTimingReused(load_timing_info2); |
| 4063 | |
| 4064 | // The requests should have the same ID. |
| 4065 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4066 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4067 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4071 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4072 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4073 | // Configure against https proxy server "proxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4074 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4075 | "https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4076 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4077 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4078 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4079 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4080 | |
| 4081 | HttpRequestInfo request1; |
| 4082 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4083 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4084 | request1.load_flags = 0; |
| 4085 | |
| 4086 | HttpRequestInfo request2; |
| 4087 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4088 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4089 | request2.load_flags = 0; |
| 4090 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4091 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4092 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4093 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4094 | scoped_ptr<SpdyFrame> get1( |
| 4095 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4096 | scoped_ptr<SpdyFrame> get_resp1( |
| 4097 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4098 | scoped_ptr<SpdyFrame> body1( |
| 4099 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4100 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4101 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4102 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4103 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4104 | scoped_ptr<SpdyFrame> get2( |
| 4105 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4106 | scoped_ptr<SpdyFrame> get_resp2( |
| 4107 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4108 | scoped_ptr<SpdyFrame> body2( |
| 4109 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4110 | |
| 4111 | MockWrite spdy_writes[] = { |
| 4112 | CreateMockWrite(*get1, 0), |
| 4113 | CreateMockWrite(*get2, 3), |
| 4114 | }; |
| 4115 | |
| 4116 | MockRead spdy_reads[] = { |
| 4117 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4118 | CreateMockRead(*body1, 2, ASYNC), |
| 4119 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4120 | CreateMockRead(*body2, 5, ASYNC), |
| 4121 | MockRead(ASYNC, 0, 6), |
| 4122 | }; |
| 4123 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4124 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4125 | arraysize(spdy_writes)); |
| 4126 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4127 | |
| 4128 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4129 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4130 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4131 | |
| 4132 | TestCompletionCallback callback; |
| 4133 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4134 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4135 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4136 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4137 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4138 | |
| 4139 | LoadTimingInfo load_timing_info; |
| 4140 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4141 | TestLoadTimingNotReused(load_timing_info, |
| 4142 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4143 | |
| 4144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4145 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4146 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4147 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4148 | |
| 4149 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4150 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4151 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4152 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4153 | // Delete the first request, so the second one can reuse the socket. |
| 4154 | trans.reset(); |
| 4155 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4156 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4157 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4158 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4159 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4160 | |
| 4161 | LoadTimingInfo load_timing_info2; |
| 4162 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4163 | TestLoadTimingReused(load_timing_info2); |
| 4164 | |
| 4165 | // The requests should have the same ID. |
| 4166 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4167 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4168 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4169 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4170 | } |
| 4171 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4172 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4173 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4174 | HttpRequestInfo request; |
| 4175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4176 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4177 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4178 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4179 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4180 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4181 | session_deps_.proxy_service.reset( |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4182 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4183 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4184 | session_deps_.net_log = log.bound().net_log(); |
| 4185 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4186 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4187 | // Since we have proxy, should use full url |
| 4188 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4189 | MockWrite( |
| 4190 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4191 | "Host: www.example.org\r\n" |
| 4192 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4193 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4194 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4195 | // be issuing -- the final header line contains the credentials. |
| 4196 | MockWrite( |
| 4197 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4198 | "Host: www.example.org\r\n" |
| 4199 | "Proxy-Connection: keep-alive\r\n" |
| 4200 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4201 | }; |
| 4202 | |
| 4203 | // The proxy responds to the GET with a 407, using a persistent |
| 4204 | // connection. |
| 4205 | MockRead data_reads1[] = { |
| 4206 | // No credentials. |
| 4207 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4208 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4209 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4210 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4211 | |
| 4212 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4213 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4214 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4215 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4216 | }; |
| 4217 | |
| 4218 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4219 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4221 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4222 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4224 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4225 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4226 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4227 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4228 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4229 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4230 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4231 | |
| 4232 | rv = callback1.WaitForResult(); |
| 4233 | EXPECT_EQ(OK, rv); |
| 4234 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4235 | LoadTimingInfo load_timing_info; |
| 4236 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4237 | TestLoadTimingNotReused(load_timing_info, |
| 4238 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4239 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4240 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4241 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4242 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4243 | EXPECT_EQ(407, response->headers->response_code()); |
| 4244 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4245 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4247 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4249 | rv = trans->RestartWithAuth( |
| 4250 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4251 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4252 | |
| 4253 | rv = callback2.WaitForResult(); |
| 4254 | EXPECT_EQ(OK, rv); |
| 4255 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4256 | load_timing_info = LoadTimingInfo(); |
| 4257 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4258 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4259 | TestLoadTimingReused(load_timing_info); |
| 4260 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4261 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4262 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4263 | |
| 4264 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4265 | EXPECT_EQ(200, response->headers->response_code()); |
| 4266 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4267 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4268 | |
| 4269 | // The password prompt info should not be set. |
| 4270 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4271 | } |
| 4272 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4273 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4274 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4275 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4276 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4277 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4278 | request.load_flags = 0; |
| 4279 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4280 | // Configure against proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4281 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4282 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4283 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4284 | // Since we have proxy, should try to establish tunnel. |
| 4285 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4286 | MockWrite( |
| 4287 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4288 | "Host: www.example.org\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"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4495 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 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[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4506 | MockWrite( |
| 4507 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4508 | "Host: www.example.org\r\n" |
| 4509 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 4510 | }; |
| 4511 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4512 | MockRead data_reads1[] = { |
| 4513 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 4514 | // Give a couple authenticate options (only the middle one is actually |
| 4515 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 4516 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4517 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4518 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 4519 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4520 | // Large content-length -- won't matter, as connection will be reset. |
| 4521 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4522 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4523 | }; |
| 4524 | |
| 4525 | // After calling trans->RestartWithAuth() the first time, this is the |
| 4526 | // request we should be issuing -- the final header line contains the |
| 4527 | // proxy's credentials. |
| 4528 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4529 | MockWrite( |
| 4530 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4531 | "Host: www.example.org\r\n" |
| 4532 | "Proxy-Connection: keep-alive\r\n" |
| 4533 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4534 | }; |
| 4535 | |
| 4536 | // Now the proxy server lets the request pass through to origin server. |
| 4537 | // The origin server responds with a 401. |
| 4538 | MockRead data_reads2[] = { |
| 4539 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 4540 | // Note: We are using the same realm-name as the proxy server. This is |
| 4541 | // completely valid, as realms are unique across hosts. |
| 4542 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4543 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4544 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4545 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4546 | }; |
| 4547 | |
| 4548 | // After calling trans->RestartWithAuth() the second time, we should send |
| 4549 | // the credentials for both the proxy and origin server. |
| 4550 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4551 | MockWrite( |
| 4552 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4553 | "Host: www.example.org\r\n" |
| 4554 | "Proxy-Connection: keep-alive\r\n" |
| 4555 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4556 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4557 | }; |
| 4558 | |
| 4559 | // Lastly we get the desired content. |
| 4560 | MockRead data_reads3[] = { |
| 4561 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 4562 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4563 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4564 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4565 | }; |
| 4566 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4567 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4568 | data_writes1, arraysize(data_writes1)); |
| 4569 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4570 | data_writes2, arraysize(data_writes2)); |
| 4571 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4572 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4573 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4574 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4575 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4577 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4579 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4581 | |
| 4582 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4583 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4584 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4586 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4587 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4589 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4591 | rv = trans->RestartWithAuth( |
| 4592 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4593 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4594 | |
| 4595 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4596 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4597 | |
| 4598 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4599 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4600 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4601 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4602 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4603 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4604 | rv = trans->RestartWithAuth( |
| 4605 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4606 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4607 | |
| 4608 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4609 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4610 | |
| 4611 | response = trans->GetResponseInfo(); |
| 4612 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4613 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 4614 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4615 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4616 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 4617 | // can't hook into its internals to cause it to generate predictable NTLM |
| 4618 | // authorization headers. |
| 4619 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4620 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 4621 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 4622 | // bytes in the debugger. |
| 4623 | |
| 4624 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4625 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4626 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4627 | request.method = "GET"; |
| 4628 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 4629 | |
| 4630 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 4631 | // to other auth schemes. |
| 4632 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4633 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4634 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 4635 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4636 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4637 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4638 | MockWrite data_writes1[] = { |
| 4639 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4640 | "Host: 172.22.68.17\r\n" |
| 4641 | "Connection: keep-alive\r\n\r\n"), |
| 4642 | }; |
| 4643 | |
| 4644 | MockRead data_reads1[] = { |
| 4645 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4646 | // Negotiate and NTLM are often requested together. However, we only want |
| 4647 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4648 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4649 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4650 | MockRead("Connection: close\r\n"), |
| 4651 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4652 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4653 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4654 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4655 | }; |
| 4656 | |
| 4657 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4658 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4659 | // request we should be issuing -- the final header line contains a Type |
| 4660 | // 1 message. |
| 4661 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4662 | "Host: 172.22.68.17\r\n" |
| 4663 | "Connection: keep-alive\r\n" |
| 4664 | "Authorization: NTLM " |
| 4665 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4666 | |
| 4667 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4668 | // (the credentials for the origin server). The second request continues |
| 4669 | // on the same connection. |
| 4670 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4671 | "Host: 172.22.68.17\r\n" |
| 4672 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4673 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4674 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4675 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 4676 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 4677 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4678 | }; |
| 4679 | |
| 4680 | MockRead data_reads2[] = { |
| 4681 | // The origin server responds with a Type 2 message. |
| 4682 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4683 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4684 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4685 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4686 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4687 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4688 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4689 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4690 | "BtAAAAAAA=\r\n"), |
| 4691 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4692 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4693 | MockRead("You are not authorized to view this page\r\n"), |
| 4694 | |
| 4695 | // Lastly we get the desired content. |
| 4696 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4697 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4698 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4699 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4700 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4701 | }; |
| 4702 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4703 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4704 | data_writes1, arraysize(data_writes1)); |
| 4705 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4706 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4707 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4708 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4710 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4711 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4712 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4713 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4715 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4716 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4717 | |
| 4718 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4719 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4720 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4721 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4722 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4723 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4724 | ASSERT_FALSE(response == NULL); |
| 4725 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4727 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4728 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4729 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4730 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4731 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4732 | |
| 4733 | rv = callback2.WaitForResult(); |
| 4734 | EXPECT_EQ(OK, rv); |
| 4735 | |
| 4736 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4737 | |
| 4738 | response = trans->GetResponseInfo(); |
| 4739 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4740 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4742 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4744 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4746 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4747 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4748 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4749 | |
| 4750 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4751 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 4752 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4753 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4754 | } |
| 4755 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4756 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4757 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4758 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4759 | request.method = "GET"; |
| 4760 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 4761 | request.load_flags = 0; |
| 4762 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4763 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 4764 | MockGetHostName); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4765 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4766 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4767 | MockWrite data_writes1[] = { |
| 4768 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4769 | "Host: 172.22.68.17\r\n" |
| 4770 | "Connection: keep-alive\r\n\r\n"), |
| 4771 | }; |
| 4772 | |
| 4773 | MockRead data_reads1[] = { |
| 4774 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 4775 | // Negotiate and NTLM are often requested together. However, we only want |
| 4776 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 4777 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4778 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4779 | MockRead("Connection: close\r\n"), |
| 4780 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4781 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4782 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4783 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4784 | }; |
| 4785 | |
| 4786 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4787 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4788 | // request we should be issuing -- the final header line contains a Type |
| 4789 | // 1 message. |
| 4790 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4791 | "Host: 172.22.68.17\r\n" |
| 4792 | "Connection: keep-alive\r\n" |
| 4793 | "Authorization: NTLM " |
| 4794 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4795 | |
| 4796 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4797 | // (the credentials for the origin server). The second request continues |
| 4798 | // on the same connection. |
| 4799 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4800 | "Host: 172.22.68.17\r\n" |
| 4801 | "Connection: keep-alive\r\n" |
| 4802 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4803 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4804 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 4805 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 4806 | "4Ww7b7E=\r\n\r\n"), |
| 4807 | }; |
| 4808 | |
| 4809 | MockRead data_reads2[] = { |
| 4810 | // The origin server responds with a Type 2 message. |
| 4811 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4812 | MockRead("WWW-Authenticate: NTLM " |
| 4813 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 4814 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4815 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4816 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4817 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4818 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4819 | "BtAAAAAAA=\r\n"), |
| 4820 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4821 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4822 | MockRead("You are not authorized to view this page\r\n"), |
| 4823 | |
| 4824 | // Wrong password. |
| 4825 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4826 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 4827 | MockRead("Connection: close\r\n"), |
| 4828 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4829 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4830 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4831 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4832 | }; |
| 4833 | |
| 4834 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4835 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4836 | // request we should be issuing -- the final header line contains a Type |
| 4837 | // 1 message. |
| 4838 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4839 | "Host: 172.22.68.17\r\n" |
| 4840 | "Connection: keep-alive\r\n" |
| 4841 | "Authorization: NTLM " |
| 4842 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 4843 | |
| 4844 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 4845 | // (the credentials for the origin server). The second request continues |
| 4846 | // on the same connection. |
| 4847 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 4848 | "Host: 172.22.68.17\r\n" |
| 4849 | "Connection: keep-alive\r\n" |
| 4850 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 4851 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 4852 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 4853 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 4854 | "+4MUm7c=\r\n\r\n"), |
| 4855 | }; |
| 4856 | |
| 4857 | MockRead data_reads3[] = { |
| 4858 | // The origin server responds with a Type 2 message. |
| 4859 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 4860 | MockRead("WWW-Authenticate: NTLM " |
| 4861 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 4862 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 4863 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 4864 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 4865 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 4866 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 4867 | "BtAAAAAAA=\r\n"), |
| 4868 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 4869 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4870 | MockRead("You are not authorized to view this page\r\n"), |
| 4871 | |
| 4872 | // Lastly we get the desired content. |
| 4873 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4874 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 4875 | MockRead("Content-Length: 13\r\n\r\n"), |
| 4876 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4877 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4878 | }; |
| 4879 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4880 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4881 | data_writes1, arraysize(data_writes1)); |
| 4882 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4883 | data_writes2, arraysize(data_writes2)); |
| 4884 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4885 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4886 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4887 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4888 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4890 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4891 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4892 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4893 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4894 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4895 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4897 | |
| 4898 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4899 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4900 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4901 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4902 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4903 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4904 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4905 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4906 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4907 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4908 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4909 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4910 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4911 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4912 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4913 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4914 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4915 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4916 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4917 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4918 | TestCompletionCallback callback3; |
| 4919 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4921 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4922 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4923 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4924 | |
| 4925 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4926 | ASSERT_FALSE(response == NULL); |
| 4927 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4928 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4929 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4930 | |
| 4931 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 4932 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4933 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4934 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4935 | |
| 4936 | rv = callback4.WaitForResult(); |
| 4937 | EXPECT_EQ(OK, rv); |
| 4938 | |
| 4939 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4941 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 4942 | |
| 4943 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4944 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4945 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4946 | |
| 4947 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4948 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 4949 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4950 | response = trans->GetResponseInfo(); |
| 4951 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4952 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 4953 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 4954 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 4955 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4956 | // Test reading a server response which has only headers, and no body. |
| 4957 | // After some maximum number of bytes is consumed, the transaction should |
| 4958 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4959 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4960 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4962 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4963 | request.load_flags = 0; |
| 4964 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 4965 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4966 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 4967 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4968 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4969 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 4970 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 4971 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4972 | |
| 4973 | MockRead data_reads[] = { |
| 4974 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4975 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4976 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4977 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4978 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4979 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4982 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4984 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4985 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 4986 | |
| 4987 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4988 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 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"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4998 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 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[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5011 | MockWrite( |
| 5012 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5013 | "Host: www.example.org\r\n" |
| 5014 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5015 | }; |
| 5016 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5017 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5018 | // connection. Usually a proxy would return 501 (not implemented), |
| 5019 | // or 200 (tunnel established). |
| 5020 | MockRead data_reads1[] = { |
| 5021 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5022 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5023 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5024 | }; |
| 5025 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5026 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5027 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5028 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5030 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5032 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5034 | |
| 5035 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5036 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5037 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5038 | // Empty the current queue. This is necessary because idle sockets are |
| 5039 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5040 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5041 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5042 | // We now check to make sure the TCPClientSocket was not added back to |
| 5043 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5044 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5045 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5046 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5047 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5048 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5049 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5050 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5051 | // 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] | 5052 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5053 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5054 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5055 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5056 | request.load_flags = 0; |
| 5057 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5058 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5059 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5060 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5062 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5063 | MockRead data_reads[] = { |
| 5064 | // A part of the response body is received with the response headers. |
| 5065 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5066 | // The rest of the response body is received in two parts. |
| 5067 | MockRead("lo"), |
| 5068 | MockRead(" world"), |
| 5069 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5070 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5071 | }; |
| 5072 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5073 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5074 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5076 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5078 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5079 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5080 | |
| 5081 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5082 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5083 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5084 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5085 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5086 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5087 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5088 | std::string status_line = response->headers->GetStatusLine(); |
| 5089 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5090 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5091 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5092 | |
| 5093 | std::string response_data; |
| 5094 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5095 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5096 | EXPECT_EQ("hello world", response_data); |
| 5097 | |
| 5098 | // Empty the current queue. This is necessary because idle sockets are |
| 5099 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5100 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5101 | |
| 5102 | // 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] | 5103 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5104 | } |
| 5105 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5106 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5107 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5108 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5109 | HttpRequestInfo request; |
| 5110 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5111 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5112 | request.load_flags = 0; |
| 5113 | |
| 5114 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5115 | MockWrite( |
| 5116 | "GET / HTTP/1.1\r\n" |
| 5117 | "Host: www.example.org\r\n" |
| 5118 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5119 | }; |
| 5120 | |
| 5121 | MockRead data_reads[] = { |
| 5122 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5123 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5124 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5125 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5126 | }; |
| 5127 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5128 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5130 | |
| 5131 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5132 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5135 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5136 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5137 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5138 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5139 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5141 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5142 | |
| 5143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5144 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5145 | |
| 5146 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5147 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5148 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5149 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5150 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5151 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5152 | |
| 5153 | std::string response_data; |
| 5154 | rv = ReadTransaction(trans.get(), &response_data); |
| 5155 | EXPECT_EQ(OK, rv); |
| 5156 | EXPECT_EQ("hello world", response_data); |
| 5157 | |
| 5158 | // Empty the current queue. This is necessary because idle sockets are |
| 5159 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5160 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5161 | |
| 5162 | // 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] | 5163 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5167 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5168 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5169 | HttpRequestInfo request; |
| 5170 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5171 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5172 | request.load_flags = 0; |
| 5173 | |
| 5174 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5175 | MockWrite( |
| 5176 | "GET / HTTP/1.1\r\n" |
| 5177 | "Host: www.example.org\r\n" |
| 5178 | "Connection: keep-alive\r\n\r\n"), |
| 5179 | MockWrite( |
| 5180 | "GET / HTTP/1.1\r\n" |
| 5181 | "Host: www.example.org\r\n" |
| 5182 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5183 | }; |
| 5184 | |
| 5185 | MockRead data_reads[] = { |
| 5186 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5187 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5188 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5189 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5190 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5191 | }; |
| 5192 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5193 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5194 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5197 | |
| 5198 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5199 | data_writes, arraysize(data_writes)); |
| 5200 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5201 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5202 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5203 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5205 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5206 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5207 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5208 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5211 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5212 | |
| 5213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5214 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5215 | |
| 5216 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5217 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5218 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5219 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5220 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5221 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5222 | |
| 5223 | std::string response_data; |
| 5224 | rv = ReadTransaction(trans.get(), &response_data); |
| 5225 | EXPECT_EQ(OK, rv); |
| 5226 | EXPECT_EQ("hello world", response_data); |
| 5227 | |
| 5228 | // Empty the current queue. This is necessary because idle sockets are |
| 5229 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5230 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5231 | |
| 5232 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5233 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5234 | |
| 5235 | // Now start the second transaction, which should reuse the previous socket. |
| 5236 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5237 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5239 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5240 | |
| 5241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5242 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5243 | |
| 5244 | response = trans->GetResponseInfo(); |
| 5245 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5246 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5247 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5248 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5249 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5250 | |
| 5251 | rv = ReadTransaction(trans.get(), &response_data); |
| 5252 | EXPECT_EQ(OK, rv); |
| 5253 | EXPECT_EQ("hello world", response_data); |
| 5254 | |
| 5255 | // Empty the current queue. This is necessary because idle sockets are |
| 5256 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5257 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5258 | |
| 5259 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5260 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5261 | } |
| 5262 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5263 | // Make sure that we recycle a socket after a zero-length response. |
| 5264 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5265 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5266 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5268 | request.url = GURL( |
| 5269 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5270 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5271 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5272 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5273 | request.load_flags = 0; |
| 5274 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5275 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5276 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5277 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5279 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5280 | MockRead data_reads[] = { |
| 5281 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5282 | "Content-Length: 0\r\n" |
| 5283 | "Content-Type: text/html\r\n\r\n"), |
| 5284 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5285 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5286 | }; |
| 5287 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5288 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5291 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5293 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5294 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5295 | |
| 5296 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5297 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5298 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5300 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5301 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5302 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5303 | std::string status_line = response->headers->GetStatusLine(); |
| 5304 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5305 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5306 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5307 | |
| 5308 | std::string response_data; |
| 5309 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5310 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5311 | EXPECT_EQ("", response_data); |
| 5312 | |
| 5313 | // Empty the current queue. This is necessary because idle sockets are |
| 5314 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5315 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5316 | |
| 5317 | // 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] | 5318 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5319 | } |
| 5320 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5321 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5322 | ScopedVector<UploadElementReader> element_readers; |
| 5323 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5324 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5325 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5326 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5327 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 5328 | // after use. |
| 5329 | request[0].method = "GET"; |
| 5330 | request[0].url = GURL("http://www.google.com/"); |
| 5331 | request[0].load_flags = 0; |
| 5332 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 5333 | // transaction 1. The first attempts fails when writing the POST data. |
| 5334 | // This causes the transaction to retry with a new socket. The second |
| 5335 | // attempt succeeds. |
| 5336 | request[1].method = "POST"; |
| 5337 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 5338 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5339 | request[1].load_flags = 0; |
| 5340 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5341 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5342 | |
| 5343 | // The first socket is used for transaction 1 and the first attempt of |
| 5344 | // transaction 2. |
| 5345 | |
| 5346 | // The response of transaction 1. |
| 5347 | MockRead data_reads1[] = { |
| 5348 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 5349 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5350 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5351 | }; |
| 5352 | // The mock write results of transaction 1 and the first attempt of |
| 5353 | // transaction 2. |
| 5354 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5355 | MockWrite(SYNCHRONOUS, 64), // GET |
| 5356 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5357 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5358 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5359 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5360 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5361 | |
| 5362 | // The second socket is used for the second attempt of transaction 2. |
| 5363 | |
| 5364 | // The response of transaction 2. |
| 5365 | MockRead data_reads2[] = { |
| 5366 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 5367 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5368 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5369 | }; |
| 5370 | // The mock write results of the second attempt of transaction 2. |
| 5371 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5372 | MockWrite(SYNCHRONOUS, 93), // POST |
| 5373 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5374 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5375 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5376 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5377 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5378 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5379 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5380 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 5381 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5382 | "hello world", "welcome" |
| 5383 | }; |
| 5384 | |
| 5385 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5386 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5387 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5389 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5391 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5392 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5393 | |
| 5394 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5395 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5396 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5398 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5399 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5400 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5401 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5402 | |
| 5403 | std::string response_data; |
| 5404 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5405 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5406 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 5407 | } |
| 5408 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5409 | |
| 5410 | // Test the request-challenge-retry sequence for basic auth when there is |
| 5411 | // 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] | 5412 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5413 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5414 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5415 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5416 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 5417 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5418 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5419 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5420 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5421 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5422 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 5423 | // The password contains an escaped character -- for this test to pass it |
| 5424 | // will need to be unescaped by HttpNetworkTransaction. |
| 5425 | EXPECT_EQ("b%40r", request.url.password()); |
| 5426 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5427 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5428 | MockWrite( |
| 5429 | "GET / HTTP/1.1\r\n" |
| 5430 | "Host: www.example.org\r\n" |
| 5431 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5432 | }; |
| 5433 | |
| 5434 | MockRead data_reads1[] = { |
| 5435 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5436 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5437 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5438 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5439 | }; |
| 5440 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5441 | // After the challenge above, the transaction will be restarted using the |
| 5442 | // identity from the url (foo, b@r) to answer the challenge. |
| 5443 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5444 | MockWrite( |
| 5445 | "GET / HTTP/1.1\r\n" |
| 5446 | "Host: www.example.org\r\n" |
| 5447 | "Connection: keep-alive\r\n" |
| 5448 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5449 | }; |
| 5450 | |
| 5451 | MockRead data_reads2[] = { |
| 5452 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5453 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5454 | MockRead(SYNCHRONOUS, OK), |
| 5455 | }; |
| 5456 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5457 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5458 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5459 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5460 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5461 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5462 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5464 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5465 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5466 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5467 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5468 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5469 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5470 | |
| 5471 | TestCompletionCallback callback2; |
| 5472 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5473 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5474 | rv = callback2.WaitForResult(); |
| 5475 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5476 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5477 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5478 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5479 | ASSERT_TRUE(response != NULL); |
| 5480 | |
| 5481 | // There is no challenge info, since the identity in URL worked. |
| 5482 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5483 | |
| 5484 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5485 | |
| 5486 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5487 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 5491 | // incorrect identity in the URL. The identity from the URL should be used only |
| 5492 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5493 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5494 | HttpRequestInfo request; |
| 5495 | request.method = "GET"; |
| 5496 | // Note: the URL has a username:password in it. The password "baz" is |
| 5497 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5498 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5499 | |
| 5500 | request.load_flags = LOAD_NORMAL; |
| 5501 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5502 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5503 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5504 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5505 | |
| 5506 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5507 | MockWrite( |
| 5508 | "GET / HTTP/1.1\r\n" |
| 5509 | "Host: www.example.org\r\n" |
| 5510 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5511 | }; |
| 5512 | |
| 5513 | MockRead data_reads1[] = { |
| 5514 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5515 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5516 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5517 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5518 | }; |
| 5519 | |
| 5520 | // After the challenge above, the transaction will be restarted using the |
| 5521 | // identity from the url (foo, baz) to answer the challenge. |
| 5522 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5523 | MockWrite( |
| 5524 | "GET / HTTP/1.1\r\n" |
| 5525 | "Host: www.example.org\r\n" |
| 5526 | "Connection: keep-alive\r\n" |
| 5527 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5528 | }; |
| 5529 | |
| 5530 | MockRead data_reads2[] = { |
| 5531 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5532 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5533 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5534 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5535 | }; |
| 5536 | |
| 5537 | // After the challenge above, the transaction will be restarted using the |
| 5538 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 5539 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5540 | MockWrite( |
| 5541 | "GET / HTTP/1.1\r\n" |
| 5542 | "Host: www.example.org\r\n" |
| 5543 | "Connection: keep-alive\r\n" |
| 5544 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5545 | }; |
| 5546 | |
| 5547 | MockRead data_reads3[] = { |
| 5548 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5549 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5550 | MockRead(SYNCHRONOUS, OK), |
| 5551 | }; |
| 5552 | |
| 5553 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5554 | data_writes1, arraysize(data_writes1)); |
| 5555 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5556 | data_writes2, arraysize(data_writes2)); |
| 5557 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5558 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5560 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5561 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 5562 | |
| 5563 | TestCompletionCallback callback1; |
| 5564 | |
| 5565 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5566 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5567 | |
| 5568 | rv = callback1.WaitForResult(); |
| 5569 | EXPECT_EQ(OK, rv); |
| 5570 | |
| 5571 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5572 | TestCompletionCallback callback2; |
| 5573 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 5574 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5575 | rv = callback2.WaitForResult(); |
| 5576 | EXPECT_EQ(OK, rv); |
| 5577 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5578 | |
| 5579 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5580 | ASSERT_TRUE(response != NULL); |
| 5581 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5582 | |
| 5583 | TestCompletionCallback callback3; |
| 5584 | rv = trans->RestartWithAuth( |
| 5585 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5587 | rv = callback3.WaitForResult(); |
| 5588 | EXPECT_EQ(OK, rv); |
| 5589 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5590 | |
| 5591 | response = trans->GetResponseInfo(); |
| 5592 | ASSERT_TRUE(response != NULL); |
| 5593 | |
| 5594 | // There is no challenge info, since the identity worked. |
| 5595 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5596 | |
| 5597 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5598 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5599 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5600 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5601 | } |
| 5602 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5603 | |
| 5604 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 5605 | // correct identity in the URL, but its use is being suppressed. The identity |
| 5606 | // from the URL should never be used. |
| 5607 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 5608 | HttpRequestInfo request; |
| 5609 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5610 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5611 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 5612 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5613 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5614 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5616 | |
| 5617 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5618 | MockWrite( |
| 5619 | "GET / HTTP/1.1\r\n" |
| 5620 | "Host: www.example.org\r\n" |
| 5621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5622 | }; |
| 5623 | |
| 5624 | MockRead data_reads1[] = { |
| 5625 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5627 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5628 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 5629 | }; |
| 5630 | |
| 5631 | // After the challenge above, the transaction will be restarted using the |
| 5632 | // identity supplied by the user, not the one in the URL, to answer the |
| 5633 | // challenge. |
| 5634 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5635 | MockWrite( |
| 5636 | "GET / HTTP/1.1\r\n" |
| 5637 | "Host: www.example.org\r\n" |
| 5638 | "Connection: keep-alive\r\n" |
| 5639 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5640 | }; |
| 5641 | |
| 5642 | MockRead data_reads3[] = { |
| 5643 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5644 | MockRead("Content-Length: 100\r\n\r\n"), |
| 5645 | MockRead(SYNCHRONOUS, OK), |
| 5646 | }; |
| 5647 | |
| 5648 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5649 | data_writes1, arraysize(data_writes1)); |
| 5650 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5651 | data_writes3, arraysize(data_writes3)); |
| 5652 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5653 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5654 | |
| 5655 | TestCompletionCallback callback1; |
| 5656 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 5657 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5658 | rv = callback1.WaitForResult(); |
| 5659 | EXPECT_EQ(OK, rv); |
| 5660 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5661 | |
| 5662 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5663 | ASSERT_TRUE(response != NULL); |
| 5664 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 5665 | |
| 5666 | TestCompletionCallback callback3; |
| 5667 | rv = trans->RestartWithAuth( |
| 5668 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 5669 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5670 | rv = callback3.WaitForResult(); |
| 5671 | EXPECT_EQ(OK, rv); |
| 5672 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5673 | |
| 5674 | response = trans->GetResponseInfo(); |
| 5675 | ASSERT_TRUE(response != NULL); |
| 5676 | |
| 5677 | // There is no challenge info, since the identity worked. |
| 5678 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5679 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5680 | |
| 5681 | // Empty the current queue. |
| 5682 | base::MessageLoop::current()->RunUntilIdle(); |
| 5683 | } |
| 5684 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5685 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5686 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5687 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5688 | |
| 5689 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 5690 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5691 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5693 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5694 | request.load_flags = 0; |
| 5695 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5696 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5697 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5698 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5699 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5700 | MockWrite( |
| 5701 | "GET /x/y/z HTTP/1.1\r\n" |
| 5702 | "Host: www.example.org\r\n" |
| 5703 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5704 | }; |
| 5705 | |
| 5706 | MockRead data_reads1[] = { |
| 5707 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5708 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5709 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5710 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5711 | }; |
| 5712 | |
| 5713 | // Resend with authorization (username=foo, password=bar) |
| 5714 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5715 | MockWrite( |
| 5716 | "GET /x/y/z HTTP/1.1\r\n" |
| 5717 | "Host: www.example.org\r\n" |
| 5718 | "Connection: keep-alive\r\n" |
| 5719 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5720 | }; |
| 5721 | |
| 5722 | // Sever accepts the authorization. |
| 5723 | MockRead data_reads2[] = { |
| 5724 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5725 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5726 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5727 | }; |
| 5728 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5729 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5730 | data_writes1, arraysize(data_writes1)); |
| 5731 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5732 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5733 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5734 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5735 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5736 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5738 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5739 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5740 | |
| 5741 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5742 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5743 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5744 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5745 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5746 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5748 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5750 | rv = trans->RestartWithAuth( |
| 5751 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5752 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5753 | |
| 5754 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5755 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5756 | |
| 5757 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5758 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5759 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5760 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5761 | } |
| 5762 | |
| 5763 | // ------------------------------------------------------------------------ |
| 5764 | |
| 5765 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 5766 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5767 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5768 | request.method = "GET"; |
| 5769 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 5770 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5771 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5772 | request.load_flags = 0; |
| 5773 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5774 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5775 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5776 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5777 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5778 | MockWrite( |
| 5779 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5780 | "Host: www.example.org\r\n" |
| 5781 | "Connection: keep-alive\r\n" |
| 5782 | // Send preemptive authorization for MyRealm1 |
| 5783 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5784 | }; |
| 5785 | |
| 5786 | // The server didn't like the preemptive authorization, and |
| 5787 | // challenges us for a different realm (MyRealm2). |
| 5788 | MockRead data_reads1[] = { |
| 5789 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5790 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 5791 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5792 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5793 | }; |
| 5794 | |
| 5795 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 5796 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5797 | MockWrite( |
| 5798 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 5799 | "Host: www.example.org\r\n" |
| 5800 | "Connection: keep-alive\r\n" |
| 5801 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5802 | }; |
| 5803 | |
| 5804 | // Sever accepts the authorization. |
| 5805 | MockRead data_reads2[] = { |
| 5806 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5807 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5808 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5809 | }; |
| 5810 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5811 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5812 | data_writes1, arraysize(data_writes1)); |
| 5813 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5814 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5815 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5816 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5818 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5820 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5822 | |
| 5823 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5824 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5825 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5826 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5827 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5828 | ASSERT_TRUE(response->auth_challenge.get()); |
| 5829 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5830 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5831 | response->auth_challenge->challenger.ToString()); |
| 5832 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 5833 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5835 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5837 | rv = trans->RestartWithAuth( |
| 5838 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5839 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5840 | |
| 5841 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5842 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5843 | |
| 5844 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5845 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5846 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5847 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5848 | } |
| 5849 | |
| 5850 | // ------------------------------------------------------------------------ |
| 5851 | |
| 5852 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 5853 | // succeed with preemptive authorization. |
| 5854 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5855 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5857 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5858 | request.load_flags = 0; |
| 5859 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5860 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5862 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5863 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5864 | MockWrite( |
| 5865 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 5866 | "Host: www.example.org\r\n" |
| 5867 | "Connection: keep-alive\r\n" |
| 5868 | // The authorization for MyRealm1 gets sent preemptively |
| 5869 | // (since the url is in the same protection space) |
| 5870 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5871 | }; |
| 5872 | |
| 5873 | // Sever accepts the preemptive authorization |
| 5874 | MockRead data_reads1[] = { |
| 5875 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5876 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5877 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5878 | }; |
| 5879 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5880 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5881 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5882 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5884 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5886 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5887 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5888 | |
| 5889 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5890 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5891 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5892 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5893 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5894 | |
| 5895 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5896 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5897 | } |
| 5898 | |
| 5899 | // ------------------------------------------------------------------------ |
| 5900 | |
| 5901 | // Transaction 4: request another URL in MyRealm (however the |
| 5902 | // url is not known to belong to the protection space, so no pre-auth). |
| 5903 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5904 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5906 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5907 | request.load_flags = 0; |
| 5908 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5909 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5910 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5911 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5912 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5913 | MockWrite( |
| 5914 | "GET /x/1 HTTP/1.1\r\n" |
| 5915 | "Host: www.example.org\r\n" |
| 5916 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5917 | }; |
| 5918 | |
| 5919 | MockRead data_reads1[] = { |
| 5920 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5921 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5922 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5923 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5924 | }; |
| 5925 | |
| 5926 | // Resend with authorization from MyRealm's cache. |
| 5927 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5928 | MockWrite( |
| 5929 | "GET /x/1 HTTP/1.1\r\n" |
| 5930 | "Host: www.example.org\r\n" |
| 5931 | "Connection: keep-alive\r\n" |
| 5932 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5933 | }; |
| 5934 | |
| 5935 | // Sever accepts the authorization. |
| 5936 | MockRead data_reads2[] = { |
| 5937 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5938 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5939 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5940 | }; |
| 5941 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5942 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5943 | data_writes1, arraysize(data_writes1)); |
| 5944 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5945 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5946 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5947 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5948 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5949 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5951 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5952 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5953 | |
| 5954 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5955 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5956 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5957 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5958 | TestCompletionCallback callback2; |
| 5959 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5960 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5961 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5962 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5963 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5964 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5965 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5966 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5967 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5968 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5969 | } |
| 5970 | |
| 5971 | // ------------------------------------------------------------------------ |
| 5972 | |
| 5973 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 5974 | // cached identity. Should invalidate and re-prompt. |
| 5975 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5976 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5978 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5979 | request.load_flags = 0; |
| 5980 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5981 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5982 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5983 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5984 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5985 | MockWrite( |
| 5986 | "GET /p/q/t HTTP/1.1\r\n" |
| 5987 | "Host: www.example.org\r\n" |
| 5988 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5989 | }; |
| 5990 | |
| 5991 | MockRead data_reads1[] = { |
| 5992 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5993 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5994 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5995 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5996 | }; |
| 5997 | |
| 5998 | // Resend with authorization from cache for MyRealm. |
| 5999 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6000 | MockWrite( |
| 6001 | "GET /p/q/t HTTP/1.1\r\n" |
| 6002 | "Host: www.example.org\r\n" |
| 6003 | "Connection: keep-alive\r\n" |
| 6004 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6005 | }; |
| 6006 | |
| 6007 | // Sever rejects the authorization. |
| 6008 | MockRead data_reads2[] = { |
| 6009 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6010 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6011 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6012 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6013 | }; |
| 6014 | |
| 6015 | // At this point we should prompt for new credentials for MyRealm. |
| 6016 | // Restart with username=foo3, password=foo4. |
| 6017 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6018 | MockWrite( |
| 6019 | "GET /p/q/t HTTP/1.1\r\n" |
| 6020 | "Host: www.example.org\r\n" |
| 6021 | "Connection: keep-alive\r\n" |
| 6022 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6023 | }; |
| 6024 | |
| 6025 | // Sever accepts the authorization. |
| 6026 | MockRead data_reads3[] = { |
| 6027 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6028 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6029 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6030 | }; |
| 6031 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6032 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6033 | data_writes1, arraysize(data_writes1)); |
| 6034 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6035 | data_writes2, arraysize(data_writes2)); |
| 6036 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6037 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6038 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6039 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6040 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6042 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6044 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6046 | |
| 6047 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6048 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6049 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6050 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6051 | TestCompletionCallback callback2; |
| 6052 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6053 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6054 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6055 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6056 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6057 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6058 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6059 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6060 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6062 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6064 | rv = trans->RestartWithAuth( |
| 6065 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6067 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6068 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6069 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6070 | |
| 6071 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6072 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6073 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6074 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6075 | } |
| 6076 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6077 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6078 | // Tests that nonce count increments when multiple auth attempts |
| 6079 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6080 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6081 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6082 | new HttpAuthHandlerDigest::Factory(); |
| 6083 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6084 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6085 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6086 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
| 6087 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6088 | |
| 6089 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6090 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6091 | HttpRequestInfo request; |
| 6092 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6093 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6094 | request.load_flags = 0; |
| 6095 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6096 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6098 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6099 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6100 | MockWrite( |
| 6101 | "GET /x/y/z HTTP/1.1\r\n" |
| 6102 | "Host: www.example.org\r\n" |
| 6103 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6104 | }; |
| 6105 | |
| 6106 | MockRead data_reads1[] = { |
| 6107 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6108 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6109 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6110 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6111 | }; |
| 6112 | |
| 6113 | // Resend with authorization (username=foo, password=bar) |
| 6114 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6115 | MockWrite( |
| 6116 | "GET /x/y/z HTTP/1.1\r\n" |
| 6117 | "Host: www.example.org\r\n" |
| 6118 | "Connection: keep-alive\r\n" |
| 6119 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6120 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6121 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6122 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6123 | }; |
| 6124 | |
| 6125 | // Sever accepts the authorization. |
| 6126 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6127 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6128 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6129 | }; |
| 6130 | |
| 6131 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6132 | data_writes1, arraysize(data_writes1)); |
| 6133 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6134 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6135 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6136 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6138 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6140 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6141 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6142 | |
| 6143 | rv = callback1.WaitForResult(); |
| 6144 | EXPECT_EQ(OK, rv); |
| 6145 | |
| 6146 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6147 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6148 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6150 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6152 | rv = trans->RestartWithAuth( |
| 6153 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6155 | |
| 6156 | rv = callback2.WaitForResult(); |
| 6157 | EXPECT_EQ(OK, rv); |
| 6158 | |
| 6159 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6160 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6161 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6162 | } |
| 6163 | |
| 6164 | // ------------------------------------------------------------------------ |
| 6165 | |
| 6166 | // Transaction 2: Request another resource in digestive's protection space. |
| 6167 | // This will preemptively add an Authorization header which should have an |
| 6168 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6169 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6170 | HttpRequestInfo request; |
| 6171 | request.method = "GET"; |
| 6172 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6173 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6174 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6175 | request.load_flags = 0; |
| 6176 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6177 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6178 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6179 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6180 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6181 | MockWrite( |
| 6182 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6183 | "Host: www.example.org\r\n" |
| 6184 | "Connection: keep-alive\r\n" |
| 6185 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6186 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6187 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6188 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6189 | }; |
| 6190 | |
| 6191 | // Sever accepts the authorization. |
| 6192 | MockRead data_reads1[] = { |
| 6193 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6194 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6195 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6196 | }; |
| 6197 | |
| 6198 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6199 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6200 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6202 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6204 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6205 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6206 | |
| 6207 | rv = callback1.WaitForResult(); |
| 6208 | EXPECT_EQ(OK, rv); |
| 6209 | |
| 6210 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6211 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6212 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6213 | } |
| 6214 | } |
| 6215 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6216 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6217 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6218 | // Create a transaction (the dependencies aren't important). |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6219 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6220 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6221 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6222 | |
| 6223 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6224 | trans->read_buf_ = new IOBuffer(15); |
| 6225 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6226 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6227 | |
| 6228 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6229 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6230 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6231 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6232 | response->response_time = base::Time::Now(); |
| 6233 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6234 | |
| 6235 | { // Setup state for response_.vary_data |
| 6236 | HttpRequestInfo request; |
| 6237 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6238 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6239 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6240 | request.extra_headers.SetHeader("Foo", "1"); |
| 6241 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6242 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | // Cause the above state to be reset. |
| 6246 | trans->ResetStateForRestart(); |
| 6247 | |
| 6248 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6249 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6250 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6251 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6252 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6253 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6254 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6255 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6256 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6257 | } |
| 6258 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6259 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6260 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6261 | HttpRequestInfo request; |
| 6262 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6263 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6264 | request.load_flags = 0; |
| 6265 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6266 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6267 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6268 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6269 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6270 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6271 | MockWrite( |
| 6272 | "GET / HTTP/1.1\r\n" |
| 6273 | "Host: www.example.org\r\n" |
| 6274 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6275 | }; |
| 6276 | |
| 6277 | MockRead data_reads[] = { |
| 6278 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6279 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6280 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6281 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6282 | }; |
| 6283 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6284 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6286 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6287 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6288 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6289 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6290 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6295 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6297 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6299 | |
| 6300 | rv = callback.WaitForResult(); |
| 6301 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6303 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6304 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6305 | |
| 6306 | rv = callback.WaitForResult(); |
| 6307 | EXPECT_EQ(OK, rv); |
| 6308 | |
| 6309 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6310 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6311 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6312 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6313 | } |
| 6314 | |
| 6315 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6316 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6317 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6318 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6319 | |
| 6320 | HttpRequestInfo request; |
| 6321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6322 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6323 | request.load_flags = 0; |
| 6324 | |
| 6325 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6326 | MockWrite( |
| 6327 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6328 | "Host: www.example.org\r\n" |
| 6329 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6330 | }; |
| 6331 | |
| 6332 | MockRead proxy_reads[] = { |
| 6333 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6334 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6335 | }; |
| 6336 | |
| 6337 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6338 | MockWrite( |
| 6339 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6340 | "Host: www.example.org\r\n" |
| 6341 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6342 | MockWrite( |
| 6343 | "GET / HTTP/1.1\r\n" |
| 6344 | "Host: www.example.org\r\n" |
| 6345 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6346 | }; |
| 6347 | |
| 6348 | MockRead data_reads[] = { |
| 6349 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6350 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6351 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6352 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6353 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6354 | }; |
| 6355 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6356 | StaticSocketDataProvider ssl_bad_certificate( |
| 6357 | proxy_reads, arraysize(proxy_reads), |
| 6358 | proxy_writes, arraysize(proxy_writes)); |
| 6359 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6360 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6361 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6362 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6363 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6364 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6365 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6369 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6370 | |
| 6371 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6372 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6373 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6374 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6375 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6376 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6378 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6380 | |
| 6381 | rv = callback.WaitForResult(); |
| 6382 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6383 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6384 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6385 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6386 | |
| 6387 | rv = callback.WaitForResult(); |
| 6388 | EXPECT_EQ(OK, rv); |
| 6389 | |
| 6390 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6391 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6392 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6393 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6394 | } |
| 6395 | } |
| 6396 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6397 | |
| 6398 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6399 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6400 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6401 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6402 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6403 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6404 | |
| 6405 | HttpRequestInfo request; |
| 6406 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6407 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6408 | request.load_flags = 0; |
| 6409 | |
| 6410 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6411 | MockWrite( |
| 6412 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6413 | "Host: www.example.org\r\n" |
| 6414 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6415 | MockWrite( |
| 6416 | "GET / HTTP/1.1\r\n" |
| 6417 | "Host: www.example.org\r\n" |
| 6418 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6419 | }; |
| 6420 | |
| 6421 | MockRead data_reads[] = { |
| 6422 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 6423 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6424 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6425 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6426 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6427 | }; |
| 6428 | |
| 6429 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6430 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6431 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 6432 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6433 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 6436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6438 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6439 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6440 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6441 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6442 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6444 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6446 | |
| 6447 | rv = callback.WaitForResult(); |
| 6448 | EXPECT_EQ(OK, rv); |
| 6449 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6450 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6451 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6452 | |
| 6453 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6454 | EXPECT_EQ(200, response->headers->response_code()); |
| 6455 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6456 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6457 | |
| 6458 | LoadTimingInfo load_timing_info; |
| 6459 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6460 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6461 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6462 | } |
| 6463 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6464 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6465 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6466 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6467 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6468 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6469 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6470 | |
| 6471 | HttpRequestInfo request; |
| 6472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6473 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6474 | request.load_flags = 0; |
| 6475 | |
| 6476 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6477 | MockWrite( |
| 6478 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6479 | "Host: www.example.org\r\n" |
| 6480 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6481 | }; |
| 6482 | |
| 6483 | MockRead data_reads[] = { |
| 6484 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 6485 | MockRead("Location: http://login.example.com/\r\n"), |
| 6486 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6487 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6488 | }; |
| 6489 | |
| 6490 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6491 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6492 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6493 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6497 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6498 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6499 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6500 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6501 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6503 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6504 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6505 | |
| 6506 | rv = callback.WaitForResult(); |
| 6507 | EXPECT_EQ(OK, rv); |
| 6508 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6509 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6510 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6511 | |
| 6512 | EXPECT_EQ(302, response->headers->response_code()); |
| 6513 | std::string url; |
| 6514 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6515 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6516 | |
| 6517 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 6518 | // timing for the proxy connection instead of the connection to the host, |
| 6519 | // and no send / receive times. |
| 6520 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 6521 | LoadTimingInfo load_timing_info; |
| 6522 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6523 | |
| 6524 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6525 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6526 | |
| 6527 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 6528 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 6529 | load_timing_info.proxy_resolve_end); |
| 6530 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 6531 | load_timing_info.connect_timing.connect_start); |
| 6532 | ExpectConnectTimingHasTimes( |
| 6533 | load_timing_info.connect_timing, |
| 6534 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6535 | |
| 6536 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 6537 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 6538 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6539 | } |
| 6540 | |
| 6541 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6542 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6543 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6544 | ProxyService::CreateFixed("https://proxy:70")); |
| 6545 | |
| 6546 | HttpRequestInfo request; |
| 6547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6548 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6549 | request.load_flags = 0; |
| 6550 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6551 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6552 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6553 | scoped_ptr<SpdyFrame> goaway( |
| 6554 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6555 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6556 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 6557 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6558 | }; |
| 6559 | |
| 6560 | static const char* const kExtraHeaders[] = { |
| 6561 | "location", |
| 6562 | "http://login.example.com/", |
| 6563 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6564 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6565 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6566 | arraysize(kExtraHeaders)/2, 1)); |
| 6567 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6568 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6569 | }; |
| 6570 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6571 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6572 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6573 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6574 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6575 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6576 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6579 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6580 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6581 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6582 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6585 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6587 | |
| 6588 | rv = callback.WaitForResult(); |
| 6589 | EXPECT_EQ(OK, rv); |
| 6590 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6591 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6592 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6593 | |
| 6594 | EXPECT_EQ(302, response->headers->response_code()); |
| 6595 | std::string url; |
| 6596 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 6597 | EXPECT_EQ("http://login.example.com/", url); |
| 6598 | } |
| 6599 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6600 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6601 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6602 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6603 | session_deps_.proxy_service.reset( |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6604 | ProxyService::CreateFixed("https://proxy:70")); |
| 6605 | |
| 6606 | HttpRequestInfo request; |
| 6607 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6608 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6609 | request.load_flags = 0; |
| 6610 | |
| 6611 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6612 | MockWrite( |
| 6613 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6614 | "Host: www.example.org\r\n" |
| 6615 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6616 | }; |
| 6617 | |
| 6618 | MockRead data_reads[] = { |
| 6619 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6620 | MockRead("Content-Length: 23\r\n\r\n"), |
| 6621 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6622 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6623 | }; |
| 6624 | |
| 6625 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6626 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6627 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6628 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6631 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6632 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6633 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6634 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6635 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6638 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6640 | |
| 6641 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6642 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6643 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6644 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6645 | } |
| 6646 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6647 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6648 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6649 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6650 | session_deps_.proxy_service.reset( |
| 6651 | ProxyService::CreateFixed("https://proxy:70")); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6652 | |
| 6653 | HttpRequestInfo request; |
| 6654 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6655 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6656 | request.load_flags = 0; |
| 6657 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6658 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6659 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6660 | scoped_ptr<SpdyFrame> rst( |
| 6661 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6662 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6663 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6664 | }; |
| 6665 | |
| 6666 | static const char* const kExtraHeaders[] = { |
| 6667 | "location", |
| 6668 | "http://login.example.com/", |
| 6669 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6670 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6671 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6672 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6673 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6674 | spdy_util_.ConstructSpdyBodyFrame( |
| 6675 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6676 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6677 | CreateMockRead(*resp.get(), 1), |
| 6678 | CreateMockRead(*body.get(), 2), |
| 6679 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6680 | }; |
| 6681 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6682 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 6683 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6684 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6685 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6686 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6687 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6688 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6690 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6691 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6692 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6693 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6694 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6696 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6697 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6698 | |
| 6699 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6700 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6701 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 6702 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 6703 | } |
| 6704 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6705 | // Test the request-challenge-retry sequence for basic auth, through |
| 6706 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6707 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6708 | HttpRequestInfo request; |
| 6709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6710 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6711 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6712 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6713 | |
| 6714 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6715 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6716 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6717 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6718 | session_deps_.net_log = log.bound().net_log(); |
| 6719 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6720 | |
| 6721 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6722 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6723 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6724 | scoped_ptr<SpdyFrame> rst( |
| 6725 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6726 | |
| 6727 | // After calling trans->RestartWithAuth(), this is the request we should |
| 6728 | // be issuing -- the final header line contains the credentials. |
| 6729 | const char* const kAuthCredentials[] = { |
| 6730 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 6731 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 6732 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 6733 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6734 | HostPortPair("www.example.org", 443))); |
| 6735 | // fetch https://www.example.org/ via HTTP |
| 6736 | const char get[] = |
| 6737 | "GET / HTTP/1.1\r\n" |
| 6738 | "Host: www.example.org\r\n" |
| 6739 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6740 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6741 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6742 | |
| 6743 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6744 | CreateMockWrite(*req, 0, ASYNC), |
| 6745 | CreateMockWrite(*rst, 2, ASYNC), |
| 6746 | CreateMockWrite(*connect2, 3), |
| 6747 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6748 | }; |
| 6749 | |
| 6750 | // The proxy responds to the connect with a 407, using a persistent |
| 6751 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6752 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6753 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6754 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6755 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 6756 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6757 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6758 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6759 | scoped_ptr<SpdyFrame> conn_resp( |
| 6760 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6761 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6762 | "Content-Length: 5\r\n\r\n"; |
| 6763 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6764 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6765 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 6766 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6767 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6768 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6769 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 6770 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 6771 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 6772 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 6773 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6774 | }; |
| 6775 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6776 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6777 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6778 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6779 | // Negotiate SPDY to the proxy |
| 6780 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6781 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6783 | // Vanilla SSL to the server |
| 6784 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6786 | |
| 6787 | TestCompletionCallback callback1; |
| 6788 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6789 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6790 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6791 | |
| 6792 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 6793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6794 | |
| 6795 | rv = callback1.WaitForResult(); |
| 6796 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 6797 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6798 | log.GetEntries(&entries); |
| 6799 | size_t pos = ExpectLogContainsSomewhere( |
| 6800 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 6801 | NetLog::PHASE_NONE); |
| 6802 | ExpectLogContainsSomewhere( |
| 6803 | entries, pos, |
| 6804 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 6805 | NetLog::PHASE_NONE); |
| 6806 | |
| 6807 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6808 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6809 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6810 | EXPECT_EQ(407, response->headers->response_code()); |
| 6811 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6812 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 6813 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6814 | |
| 6815 | TestCompletionCallback callback2; |
| 6816 | |
| 6817 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6818 | callback2.callback()); |
| 6819 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6820 | |
| 6821 | rv = callback2.WaitForResult(); |
| 6822 | EXPECT_EQ(OK, rv); |
| 6823 | |
| 6824 | response = trans->GetResponseInfo(); |
| 6825 | ASSERT_TRUE(response != NULL); |
| 6826 | |
| 6827 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6828 | EXPECT_EQ(200, response->headers->response_code()); |
| 6829 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 6830 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6831 | |
| 6832 | // The password prompt info should not be set. |
| 6833 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6834 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6835 | LoadTimingInfo load_timing_info; |
| 6836 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6837 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6838 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6839 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 6840 | trans.reset(); |
| 6841 | session->CloseAllConnections(); |
| 6842 | } |
| 6843 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6844 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 6845 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6846 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6847 | HttpRequestInfo request; |
| 6848 | HttpRequestInfo push_request; |
| 6849 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6851 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6852 | push_request.method = "GET"; |
| 6853 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 6854 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6855 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6856 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6857 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6858 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6859 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6860 | |
| 6861 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6862 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6863 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6864 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6865 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6866 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6867 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6868 | |
| 6869 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6870 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6871 | }; |
| 6872 | |
| 6873 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6874 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6875 | |
| 6876 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6877 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6878 | |
| 6879 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6880 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6881 | 0, |
| 6882 | 2, |
| 6883 | 1, |
| 6884 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 6885 | const char kPushedData[] = "pushed"; |
| 6886 | scoped_ptr<SpdyFrame> stream2_body( |
| 6887 | spdy_util_.ConstructSpdyBodyFrame( |
| 6888 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6889 | |
| 6890 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6891 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 6892 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 6893 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 6894 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 6895 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6896 | }; |
| 6897 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6898 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 6899 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6900 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6901 | // Negotiate SPDY to the proxy |
| 6902 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6903 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6905 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6906 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6907 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6908 | TestCompletionCallback callback; |
| 6909 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 6910 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6911 | |
| 6912 | rv = callback.WaitForResult(); |
| 6913 | EXPECT_EQ(OK, rv); |
| 6914 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6915 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6916 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6917 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6918 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6920 | |
| 6921 | rv = callback.WaitForResult(); |
| 6922 | EXPECT_EQ(OK, rv); |
| 6923 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 6924 | |
| 6925 | ASSERT_TRUE(response != NULL); |
| 6926 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6927 | |
| 6928 | EXPECT_EQ(200, response->headers->response_code()); |
| 6929 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6930 | |
| 6931 | std::string response_data; |
| 6932 | rv = ReadTransaction(trans.get(), &response_data); |
| 6933 | EXPECT_EQ(OK, rv); |
| 6934 | EXPECT_EQ("hello!", response_data); |
| 6935 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6936 | LoadTimingInfo load_timing_info; |
| 6937 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6938 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 6939 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6940 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6941 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6942 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6943 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 6944 | |
| 6945 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 6946 | EXPECT_EQ(OK, rv); |
| 6947 | EXPECT_EQ("pushed", response_data); |
| 6948 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6949 | LoadTimingInfo push_load_timing_info; |
| 6950 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 6951 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 6952 | // The transactions should share a socket ID, despite being for different |
| 6953 | // origins. |
| 6954 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 6955 | push_load_timing_info.socket_log_id); |
| 6956 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 6957 | trans.reset(); |
| 6958 | push_trans.reset(); |
| 6959 | session->CloseAllConnections(); |
| 6960 | } |
| 6961 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6962 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6963 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6964 | HttpRequestInfo request; |
| 6965 | |
| 6966 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6967 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6968 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6969 | // Configure against https proxy server "myproxy:70". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6970 | session_deps_.proxy_service.reset( |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6971 | ProxyService::CreateFixed("https://myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6972 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6973 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6974 | |
| 6975 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6976 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 6977 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6978 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6979 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6980 | scoped_ptr<SpdyFrame> stream1_syn( |
| 6981 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6982 | |
| 6983 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 6984 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6985 | |
| 6986 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6987 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6988 | }; |
| 6989 | |
| 6990 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6991 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6992 | |
| 6993 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6994 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6995 | |
| 6996 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6997 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 6998 | 0, |
| 6999 | 2, |
| 7000 | 1, |
| 7001 | "https://www.another-origin.com/foo.dat")); |
| 7002 | |
| 7003 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7004 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7005 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7006 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7007 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7008 | }; |
| 7009 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7010 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7011 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7012 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7013 | // Negotiate SPDY to the proxy |
| 7014 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7015 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7016 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7017 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7018 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7020 | TestCompletionCallback callback; |
| 7021 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7022 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7023 | |
| 7024 | rv = callback.WaitForResult(); |
| 7025 | EXPECT_EQ(OK, rv); |
| 7026 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7027 | |
| 7028 | ASSERT_TRUE(response != NULL); |
| 7029 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7030 | |
| 7031 | EXPECT_EQ(200, response->headers->response_code()); |
| 7032 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7033 | |
| 7034 | std::string response_data; |
| 7035 | rv = ReadTransaction(trans.get(), &response_data); |
| 7036 | EXPECT_EQ(OK, rv); |
| 7037 | EXPECT_EQ("hello!", response_data); |
| 7038 | |
| 7039 | trans.reset(); |
| 7040 | session->CloseAllConnections(); |
| 7041 | } |
| 7042 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7043 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7044 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7045 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7046 | session_deps_.proxy_service.reset(ProxyService::CreateFixed( |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 7047 | "https://proxy:70")); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7048 | |
| 7049 | HttpRequestInfo request; |
| 7050 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7051 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7052 | request.load_flags = 0; |
| 7053 | |
| 7054 | // Attempt to fetch the URL from a server with a bad cert |
| 7055 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7056 | MockWrite( |
| 7057 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7058 | "Host: www.example.org\r\n" |
| 7059 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7060 | }; |
| 7061 | |
| 7062 | MockRead bad_cert_reads[] = { |
| 7063 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7064 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7065 | }; |
| 7066 | |
| 7067 | // Attempt to fetch the URL with a good cert |
| 7068 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7069 | MockWrite( |
| 7070 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7071 | "Host: www.example.org\r\n" |
| 7072 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7073 | MockWrite( |
| 7074 | "GET / HTTP/1.1\r\n" |
| 7075 | "Host: www.example.org\r\n" |
| 7076 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7077 | }; |
| 7078 | |
| 7079 | MockRead good_cert_reads[] = { |
| 7080 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7081 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7082 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7083 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7084 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7085 | }; |
| 7086 | |
| 7087 | StaticSocketDataProvider ssl_bad_certificate( |
| 7088 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7089 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7090 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7091 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7092 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7093 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7094 | |
| 7095 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7097 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7098 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7099 | |
| 7100 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7103 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7105 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7106 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7107 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7108 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7109 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7111 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7112 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7113 | |
| 7114 | rv = callback.WaitForResult(); |
| 7115 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7117 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7118 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7119 | |
| 7120 | rv = callback.WaitForResult(); |
| 7121 | EXPECT_EQ(OK, rv); |
| 7122 | |
| 7123 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7124 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7125 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7126 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7127 | } |
| 7128 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7129 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7130 | HttpRequestInfo request; |
| 7131 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7132 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7133 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7134 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7135 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7136 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7137 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7138 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7139 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7140 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7141 | MockWrite( |
| 7142 | "GET / HTTP/1.1\r\n" |
| 7143 | "Host: www.example.org\r\n" |
| 7144 | "Connection: keep-alive\r\n" |
| 7145 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7146 | }; |
| 7147 | |
| 7148 | // Lastly, the server responds with the actual content. |
| 7149 | MockRead data_reads[] = { |
| 7150 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7151 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7152 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7153 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7154 | }; |
| 7155 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7156 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7157 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7160 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7162 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7163 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7164 | |
| 7165 | rv = callback.WaitForResult(); |
| 7166 | EXPECT_EQ(OK, rv); |
| 7167 | } |
| 7168 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7169 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7170 | HttpRequestInfo request; |
| 7171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7172 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7173 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7174 | "Chromium Ultra Awesome X Edition"); |
| 7175 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7176 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7177 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7178 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7179 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7180 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7181 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7182 | MockWrite( |
| 7183 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7184 | "Host: www.example.org\r\n" |
| 7185 | "Proxy-Connection: keep-alive\r\n" |
| 7186 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7187 | }; |
| 7188 | MockRead data_reads[] = { |
| 7189 | // Return an error, so the transaction stops here (this test isn't |
| 7190 | // interested in the rest). |
| 7191 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7192 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7193 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7194 | }; |
| 7195 | |
| 7196 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7197 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7198 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7200 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7202 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7203 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7204 | |
| 7205 | rv = callback.WaitForResult(); |
| 7206 | EXPECT_EQ(OK, rv); |
| 7207 | } |
| 7208 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7209 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7210 | HttpRequestInfo request; |
| 7211 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7212 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7213 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7214 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7215 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7216 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7217 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7218 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7219 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7220 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7221 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7222 | MockWrite( |
| 7223 | "GET / HTTP/1.1\r\n" |
| 7224 | "Host: www.example.org\r\n" |
| 7225 | "Connection: keep-alive\r\n" |
| 7226 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7227 | }; |
| 7228 | |
| 7229 | // Lastly, the server responds with the actual content. |
| 7230 | MockRead data_reads[] = { |
| 7231 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7232 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7233 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7234 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7235 | }; |
| 7236 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7237 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7238 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7241 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7243 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7244 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7245 | |
| 7246 | rv = callback.WaitForResult(); |
| 7247 | EXPECT_EQ(OK, rv); |
| 7248 | } |
| 7249 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7250 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7251 | HttpRequestInfo request; |
| 7252 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7253 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7254 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7255 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7256 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7257 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7258 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7259 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7260 | MockWrite( |
| 7261 | "POST / HTTP/1.1\r\n" |
| 7262 | "Host: www.example.org\r\n" |
| 7263 | "Connection: keep-alive\r\n" |
| 7264 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7265 | }; |
| 7266 | |
| 7267 | // Lastly, the server responds with the actual content. |
| 7268 | MockRead data_reads[] = { |
| 7269 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7270 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7271 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7272 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7273 | }; |
| 7274 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7275 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7276 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7277 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7279 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7281 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7282 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7283 | |
| 7284 | rv = callback.WaitForResult(); |
| 7285 | EXPECT_EQ(OK, rv); |
| 7286 | } |
| 7287 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7288 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7289 | HttpRequestInfo request; |
| 7290 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7291 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7292 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7293 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7294 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7295 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7296 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7297 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7298 | MockWrite( |
| 7299 | "PUT / HTTP/1.1\r\n" |
| 7300 | "Host: www.example.org\r\n" |
| 7301 | "Connection: keep-alive\r\n" |
| 7302 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7303 | }; |
| 7304 | |
| 7305 | // Lastly, the server responds with the actual content. |
| 7306 | MockRead data_reads[] = { |
| 7307 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7308 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7309 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7310 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7311 | }; |
| 7312 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7313 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7314 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7315 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7317 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7319 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7320 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7321 | |
| 7322 | rv = callback.WaitForResult(); |
| 7323 | EXPECT_EQ(OK, rv); |
| 7324 | } |
| 7325 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7326 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7327 | HttpRequestInfo request; |
| 7328 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7329 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7330 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7332 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7334 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7335 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame^] | 7336 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 7337 | "Host: www.example.org\r\n" |
| 7338 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | // Lastly, the server responds with the actual content. |
| 7342 | MockRead data_reads[] = { |
| 7343 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7344 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7345 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7346 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7347 | }; |
| 7348 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7349 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7350 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7353 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7355 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7357 | |
| 7358 | rv = callback.WaitForResult(); |
| 7359 | EXPECT_EQ(OK, rv); |
| 7360 | } |
| 7361 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7362 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7363 | HttpRequestInfo request; |
| 7364 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7365 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7366 | request.load_flags = LOAD_BYPASS_CACHE; |
| 7367 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7368 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7369 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7370 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7371 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7372 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7373 | MockWrite( |
| 7374 | "GET / HTTP/1.1\r\n" |
| 7375 | "Host: www.example.org\r\n" |
| 7376 | "Connection: keep-alive\r\n" |
| 7377 | "Pragma: no-cache\r\n" |
| 7378 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7379 | }; |
| 7380 | |
| 7381 | // Lastly, the server responds with the actual content. |
| 7382 | MockRead data_reads[] = { |
| 7383 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7384 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7385 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7386 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7387 | }; |
| 7388 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7389 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7390 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7391 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7393 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7395 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7396 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7397 | |
| 7398 | rv = callback.WaitForResult(); |
| 7399 | EXPECT_EQ(OK, rv); |
| 7400 | } |
| 7401 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7402 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7403 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7404 | HttpRequestInfo request; |
| 7405 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7406 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7407 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 7408 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7409 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7410 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7411 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7412 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7413 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7414 | MockWrite( |
| 7415 | "GET / HTTP/1.1\r\n" |
| 7416 | "Host: www.example.org\r\n" |
| 7417 | "Connection: keep-alive\r\n" |
| 7418 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7419 | }; |
| 7420 | |
| 7421 | // Lastly, the server responds with the actual content. |
| 7422 | MockRead data_reads[] = { |
| 7423 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7424 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7425 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7426 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7427 | }; |
| 7428 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7429 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7430 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7431 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7433 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7435 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7436 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7437 | |
| 7438 | rv = callback.WaitForResult(); |
| 7439 | EXPECT_EQ(OK, rv); |
| 7440 | } |
| 7441 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7442 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7443 | HttpRequestInfo request; |
| 7444 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7445 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7446 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7447 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7448 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7449 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7450 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7451 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7452 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7453 | MockWrite( |
| 7454 | "GET / HTTP/1.1\r\n" |
| 7455 | "Host: www.example.org\r\n" |
| 7456 | "Connection: keep-alive\r\n" |
| 7457 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7458 | }; |
| 7459 | |
| 7460 | // Lastly, the server responds with the actual content. |
| 7461 | MockRead data_reads[] = { |
| 7462 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7463 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7464 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7465 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7466 | }; |
| 7467 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7468 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7469 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7472 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7474 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7475 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7476 | |
| 7477 | rv = callback.WaitForResult(); |
| 7478 | EXPECT_EQ(OK, rv); |
| 7479 | } |
| 7480 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7481 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7482 | HttpRequestInfo request; |
| 7483 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7484 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7485 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 7486 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 7487 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7488 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7489 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7490 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7491 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7492 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7493 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7494 | MockWrite( |
| 7495 | "GET / HTTP/1.1\r\n" |
| 7496 | "Host: www.example.org\r\n" |
| 7497 | "Connection: keep-alive\r\n" |
| 7498 | "referer: www.foo.com\r\n" |
| 7499 | "hEllo: Kitty\r\n" |
| 7500 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7501 | }; |
| 7502 | |
| 7503 | // Lastly, the server responds with the actual content. |
| 7504 | MockRead data_reads[] = { |
| 7505 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7506 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7507 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7508 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7509 | }; |
| 7510 | |
| 7511 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7512 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7515 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7516 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7517 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 7518 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7519 | |
| 7520 | rv = callback.WaitForResult(); |
| 7521 | EXPECT_EQ(OK, rv); |
| 7522 | } |
| 7523 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7524 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7525 | HttpRequestInfo request; |
| 7526 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7527 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7528 | request.load_flags = 0; |
| 7529 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7530 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7531 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7532 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7533 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7534 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7535 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7536 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7537 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7538 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7539 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7540 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7541 | |
| 7542 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7543 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7544 | MockWrite( |
| 7545 | "GET / HTTP/1.1\r\n" |
| 7546 | "Host: www.example.org\r\n" |
| 7547 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7548 | |
| 7549 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7550 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7551 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7552 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7553 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7554 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7555 | }; |
| 7556 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7557 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7558 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7559 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7561 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7563 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7565 | |
| 7566 | rv = callback.WaitForResult(); |
| 7567 | EXPECT_EQ(OK, rv); |
| 7568 | |
| 7569 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7570 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7571 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7572 | LoadTimingInfo load_timing_info; |
| 7573 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7574 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7575 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7576 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7577 | std::string response_text; |
| 7578 | rv = ReadTransaction(trans.get(), &response_text); |
| 7579 | EXPECT_EQ(OK, rv); |
| 7580 | EXPECT_EQ("Payload", response_text); |
| 7581 | } |
| 7582 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7583 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7584 | HttpRequestInfo request; |
| 7585 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7586 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7587 | request.load_flags = 0; |
| 7588 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7589 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7590 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7591 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7592 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7593 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7594 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7595 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7597 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7598 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 7599 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7600 | |
| 7601 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7602 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 7603 | arraysize(write_buffer)), |
| 7604 | MockWrite( |
| 7605 | "GET / HTTP/1.1\r\n" |
| 7606 | "Host: www.example.org\r\n" |
| 7607 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7608 | |
| 7609 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7610 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 7611 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7612 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7613 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7614 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7615 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7616 | }; |
| 7617 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7618 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7619 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7620 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7621 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7622 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7625 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7626 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7627 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7628 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7629 | |
| 7630 | rv = callback.WaitForResult(); |
| 7631 | EXPECT_EQ(OK, rv); |
| 7632 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7633 | LoadTimingInfo load_timing_info; |
| 7634 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7635 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7636 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7637 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7638 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7639 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7640 | |
| 7641 | std::string response_text; |
| 7642 | rv = ReadTransaction(trans.get(), &response_text); |
| 7643 | EXPECT_EQ(OK, rv); |
| 7644 | EXPECT_EQ("Payload", response_text); |
| 7645 | } |
| 7646 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7647 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7648 | HttpRequestInfo request; |
| 7649 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7650 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7651 | request.load_flags = 0; |
| 7652 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7653 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7654 | ProxyService::CreateFixed("socks4://myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7655 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7656 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7657 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7658 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7659 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7660 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7661 | |
| 7662 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 7663 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 7664 | |
| 7665 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7666 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 7667 | MockWrite( |
| 7668 | "GET / HTTP/1.1\r\n" |
| 7669 | "Host: www.example.org\r\n" |
| 7670 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7671 | |
| 7672 | MockRead data_reads[] = { |
| 7673 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 7674 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7675 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7676 | MockRead("Payload"), |
| 7677 | MockRead(SYNCHRONOUS, OK) |
| 7678 | }; |
| 7679 | |
| 7680 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7681 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7683 | |
| 7684 | TestCompletionCallback callback; |
| 7685 | |
| 7686 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 7687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7688 | |
| 7689 | rv = callback.WaitForResult(); |
| 7690 | EXPECT_EQ(OK, rv); |
| 7691 | |
| 7692 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7693 | ASSERT_TRUE(response != NULL); |
| 7694 | |
| 7695 | LoadTimingInfo load_timing_info; |
| 7696 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7697 | TestLoadTimingNotReused(load_timing_info, |
| 7698 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7699 | |
| 7700 | std::string response_text; |
| 7701 | rv = ReadTransaction(trans.get(), &response_text); |
| 7702 | EXPECT_EQ(OK, rv); |
| 7703 | EXPECT_EQ("Payload", response_text); |
| 7704 | } |
| 7705 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7706 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7707 | HttpRequestInfo request; |
| 7708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7709 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7710 | request.load_flags = 0; |
| 7711 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7712 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7713 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7714 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7715 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7716 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7717 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7718 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7719 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7720 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7721 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7722 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7723 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7724 | 0x05, // Version |
| 7725 | 0x01, // Command (CONNECT) |
| 7726 | 0x00, // Reserved. |
| 7727 | 0x03, // Address type (DOMAINNAME). |
| 7728 | 0x0F, // Length of domain (15) |
| 7729 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7730 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7731 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7732 | const char kSOCKS5OkResponse[] = |
| 7733 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 7734 | |
| 7735 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7736 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7737 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 7738 | MockWrite( |
| 7739 | "GET / HTTP/1.1\r\n" |
| 7740 | "Host: www.example.org\r\n" |
| 7741 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7742 | |
| 7743 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7744 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7745 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7746 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7747 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7748 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7749 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7750 | }; |
| 7751 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7752 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7753 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7754 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7756 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7758 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7759 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7760 | |
| 7761 | rv = callback.WaitForResult(); |
| 7762 | EXPECT_EQ(OK, rv); |
| 7763 | |
| 7764 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7765 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7766 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7767 | LoadTimingInfo load_timing_info; |
| 7768 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7769 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7770 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7771 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7772 | std::string response_text; |
| 7773 | rv = ReadTransaction(trans.get(), &response_text); |
| 7774 | EXPECT_EQ(OK, rv); |
| 7775 | EXPECT_EQ("Payload", response_text); |
| 7776 | } |
| 7777 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7778 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7779 | HttpRequestInfo request; |
| 7780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7781 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7782 | request.load_flags = 0; |
| 7783 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7784 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7785 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7786 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7787 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7788 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7789 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7790 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7791 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7792 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7793 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 7794 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7795 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7796 | 0x05, // Version |
| 7797 | 0x01, // Command (CONNECT) |
| 7798 | 0x00, // Reserved. |
| 7799 | 0x03, // Address type (DOMAINNAME). |
| 7800 | 0x0F, // Length of domain (15) |
| 7801 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 7802 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 7803 | }; |
| 7804 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7805 | const char kSOCKS5OkResponse[] = |
| 7806 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 7807 | |
| 7808 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7809 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 7810 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 7811 | arraysize(kSOCKS5OkRequest)), |
| 7812 | MockWrite( |
| 7813 | "GET / HTTP/1.1\r\n" |
| 7814 | "Host: www.example.org\r\n" |
| 7815 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 7816 | |
| 7817 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 7818 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 7819 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7820 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7821 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 7822 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7823 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7824 | }; |
| 7825 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7826 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7827 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7829 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7830 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7833 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7835 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7836 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7837 | |
| 7838 | rv = callback.WaitForResult(); |
| 7839 | EXPECT_EQ(OK, rv); |
| 7840 | |
| 7841 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7842 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7843 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7844 | LoadTimingInfo load_timing_info; |
| 7845 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7846 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7847 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7848 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 7849 | std::string response_text; |
| 7850 | rv = ReadTransaction(trans.get(), &response_text); |
| 7851 | EXPECT_EQ(OK, rv); |
| 7852 | EXPECT_EQ("Payload", response_text); |
| 7853 | } |
| 7854 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7855 | namespace { |
| 7856 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7857 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7858 | |
| 7859 | struct GroupNameTest { |
| 7860 | std::string proxy_server; |
| 7861 | std::string url; |
| 7862 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7863 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7864 | }; |
| 7865 | |
| 7866 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7867 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7868 | SpdySessionDependencies* session_deps_) { |
| 7869 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7870 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 7871 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 7872 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7873 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 7874 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7875 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 7876 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 7877 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 7878 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7879 | |
| 7880 | return session; |
| 7881 | } |
| 7882 | |
| 7883 | int GroupNameTransactionHelper( |
| 7884 | const std::string& url, |
| 7885 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7886 | HttpRequestInfo request; |
| 7887 | request.method = "GET"; |
| 7888 | request.url = GURL(url); |
| 7889 | request.load_flags = 0; |
| 7890 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7891 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7894 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7895 | |
| 7896 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7897 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7898 | } |
| 7899 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7900 | } // namespace |
| 7901 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7902 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7903 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7904 | { |
| 7905 | "", // unused |
| 7906 | "http://www.example.org/direct", |
| 7907 | "www.example.org:80", |
| 7908 | false, |
| 7909 | }, |
| 7910 | { |
| 7911 | "", // unused |
| 7912 | "http://[2001:1418:13:1::25]/direct", |
| 7913 | "[2001:1418:13:1::25]:80", |
| 7914 | false, |
| 7915 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 7916 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7917 | // SSL Tests |
| 7918 | { |
| 7919 | "", // unused |
| 7920 | "https://www.example.org/direct_ssl", |
| 7921 | "ssl/www.example.org:443", |
| 7922 | true, |
| 7923 | }, |
| 7924 | { |
| 7925 | "", // unused |
| 7926 | "https://[2001:1418:13:1::25]/direct", |
| 7927 | "ssl/[2001:1418:13:1::25]:443", |
| 7928 | true, |
| 7929 | }, |
| 7930 | { |
| 7931 | "", // unused |
| 7932 | "http://host.with.alternate/direct", |
| 7933 | "ssl/host.with.alternate:443", |
| 7934 | true, |
| 7935 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7936 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 7937 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 7938 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7939 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 7940 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7941 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 7942 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7943 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7944 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7945 | |
| 7946 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7947 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 7948 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 7949 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 7950 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 7951 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 7952 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 7953 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 7954 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 7955 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7956 | |
| 7957 | EXPECT_EQ(ERR_IO_PENDING, |
| 7958 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 7959 | if (tests[i].ssl) |
| 7960 | EXPECT_EQ(tests[i].expected_group_name, |
| 7961 | ssl_conn_pool->last_group_name_received()); |
| 7962 | else |
| 7963 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 7964 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7965 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7966 | } |
| 7967 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7968 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7969 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7970 | { |
| 7971 | "http_proxy", |
| 7972 | "http://www.example.org/http_proxy_normal", |
| 7973 | "www.example.org:80", |
| 7974 | false, |
| 7975 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7976 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7977 | // SSL Tests |
| 7978 | { |
| 7979 | "http_proxy", |
| 7980 | "https://www.example.org/http_connect_ssl", |
| 7981 | "ssl/www.example.org:443", |
| 7982 | true, |
| 7983 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 7984 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7985 | { |
| 7986 | "http_proxy", |
| 7987 | "http://host.with.alternate/direct", |
| 7988 | "ssl/host.with.alternate:443", |
| 7989 | true, |
| 7990 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 7991 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7992 | { |
| 7993 | "http_proxy", |
| 7994 | "ftp://ftp.google.com/http_proxy_normal", |
| 7995 | "ftp/ftp.google.com:21", |
| 7996 | false, |
| 7997 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 7998 | }; |
| 7999 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8000 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8001 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8002 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8003 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8004 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8005 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8006 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8007 | |
| 8008 | HttpNetworkSessionPeer peer(session); |
| 8009 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8010 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8011 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8012 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8013 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8014 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8015 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8016 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8017 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8018 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8019 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8020 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8021 | |
| 8022 | EXPECT_EQ(ERR_IO_PENDING, |
| 8023 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8024 | if (tests[i].ssl) |
| 8025 | EXPECT_EQ(tests[i].expected_group_name, |
| 8026 | ssl_conn_pool->last_group_name_received()); |
| 8027 | else |
| 8028 | EXPECT_EQ(tests[i].expected_group_name, |
| 8029 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8030 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8031 | } |
| 8032 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8033 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8034 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8035 | { |
| 8036 | "socks4://socks_proxy:1080", |
| 8037 | "http://www.example.org/socks4_direct", |
| 8038 | "socks4/www.example.org:80", |
| 8039 | false, |
| 8040 | }, |
| 8041 | { |
| 8042 | "socks5://socks_proxy:1080", |
| 8043 | "http://www.example.org/socks5_direct", |
| 8044 | "socks5/www.example.org:80", |
| 8045 | false, |
| 8046 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8047 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8048 | // SSL Tests |
| 8049 | { |
| 8050 | "socks4://socks_proxy:1080", |
| 8051 | "https://www.example.org/socks4_ssl", |
| 8052 | "socks4/ssl/www.example.org:443", |
| 8053 | true, |
| 8054 | }, |
| 8055 | { |
| 8056 | "socks5://socks_proxy:1080", |
| 8057 | "https://www.example.org/socks5_ssl", |
| 8058 | "socks5/ssl/www.example.org:443", |
| 8059 | true, |
| 8060 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8061 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8062 | { |
| 8063 | "socks4://socks_proxy:1080", |
| 8064 | "http://host.with.alternate/direct", |
| 8065 | "socks4/ssl/host.with.alternate:443", |
| 8066 | true, |
| 8067 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8068 | }; |
| 8069 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8070 | session_deps_.use_alternate_protocols = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8071 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8072 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8073 | session_deps_.proxy_service.reset( |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8074 | ProxyService::CreateFixed(tests[i].proxy_server)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8075 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8076 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8077 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8078 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8079 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8080 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8081 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8082 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8083 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8084 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8085 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8086 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8087 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8088 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8089 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8090 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8091 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8092 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8093 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8094 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8095 | EXPECT_EQ(ERR_IO_PENDING, |
| 8096 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8097 | if (tests[i].ssl) |
| 8098 | EXPECT_EQ(tests[i].expected_group_name, |
| 8099 | ssl_conn_pool->last_group_name_received()); |
| 8100 | else |
| 8101 | EXPECT_EQ(tests[i].expected_group_name, |
| 8102 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8103 | } |
| 8104 | } |
| 8105 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8106 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8107 | HttpRequestInfo request; |
| 8108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8109 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8110 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8111 | session_deps_.proxy_service.reset( |
[email protected] | 81cdfcd | 2010-10-16 00:49:00 | [diff] [blame] | 8112 | ProxyService::CreateFixed("myproxy:70;foobar:80")); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8113 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8114 | // This simulates failure resolving all hostnames; that means we will fail |
| 8115 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8116 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8117 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8118 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8119 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8122 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8123 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8124 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8125 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8126 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8127 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8128 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8129 | } |
| 8130 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8131 | // Base test to make sure that when the load flags for a request specify to |
| 8132 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8133 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8134 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8135 | // Issue a request, asking to bypass the cache(s). |
| 8136 | HttpRequestInfo request; |
| 8137 | request.method = "GET"; |
| 8138 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8139 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8140 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8141 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8142 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8143 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8144 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8145 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8146 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8147 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8148 | // Warm up the host cache so it has an entry for "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8149 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8150 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8151 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8152 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8153 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8155 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8156 | EXPECT_EQ(OK, rv); |
| 8157 | |
| 8158 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8159 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8160 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8161 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8162 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8163 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8164 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8165 | // Inject a failure the next time that "www.example.org" is resolved. This way |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8166 | // we can tell if the next lookup hit the cache, or the "network". |
| 8167 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8168 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8169 | |
| 8170 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8171 | // 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] | 8172 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8175 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8176 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8177 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8178 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8179 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8180 | |
| 8181 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8182 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8183 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8184 | } |
| 8185 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8186 | // There are multiple load flags that should trigger the host cache bypass. |
| 8187 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8188 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8189 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8190 | } |
| 8191 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8192 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8193 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8194 | } |
| 8195 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8196 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8197 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8198 | } |
| 8199 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8200 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8201 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8202 | HttpRequestInfo request; |
| 8203 | request.method = "GET"; |
| 8204 | request.url = GURL("http://www.foo.com/"); |
| 8205 | request.load_flags = 0; |
| 8206 | |
| 8207 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8208 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8209 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8210 | StaticSocketDataProvider data(NULL, 0, |
| 8211 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8212 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8213 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8215 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8216 | |
| 8217 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8218 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8220 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8221 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8222 | |
| 8223 | rv = callback.WaitForResult(); |
| 8224 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 8225 | } |
| 8226 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8227 | // Check that a connection closed after the start of the headers finishes ok. |
| 8228 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8229 | HttpRequestInfo request; |
| 8230 | request.method = "GET"; |
| 8231 | request.url = GURL("http://www.foo.com/"); |
| 8232 | request.load_flags = 0; |
| 8233 | |
| 8234 | MockRead data_reads[] = { |
| 8235 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8236 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8237 | }; |
| 8238 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8239 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8240 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8241 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8243 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8244 | |
| 8245 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8246 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8248 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8250 | |
| 8251 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8252 | EXPECT_EQ(OK, rv); |
| 8253 | |
| 8254 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8255 | ASSERT_TRUE(response != NULL); |
| 8256 | |
| 8257 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8258 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8259 | |
| 8260 | std::string response_data; |
| 8261 | rv = ReadTransaction(trans.get(), &response_data); |
| 8262 | EXPECT_EQ(OK, rv); |
| 8263 | EXPECT_EQ("", response_data); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8264 | } |
| 8265 | |
| 8266 | // Make sure that a dropped connection while draining the body for auth |
| 8267 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8268 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8269 | HttpRequestInfo request; |
| 8270 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8271 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8272 | request.load_flags = 0; |
| 8273 | |
| 8274 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8275 | MockWrite( |
| 8276 | "GET / HTTP/1.1\r\n" |
| 8277 | "Host: www.example.org\r\n" |
| 8278 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8279 | }; |
| 8280 | |
| 8281 | MockRead data_reads1[] = { |
| 8282 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8283 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8284 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8285 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8286 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8287 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8288 | }; |
| 8289 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8290 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8291 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8292 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8293 | |
| 8294 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8295 | // be issuing -- the final header line contains the credentials. |
| 8296 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8297 | MockWrite( |
| 8298 | "GET / HTTP/1.1\r\n" |
| 8299 | "Host: www.example.org\r\n" |
| 8300 | "Connection: keep-alive\r\n" |
| 8301 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8302 | }; |
| 8303 | |
| 8304 | // Lastly, the server responds with the actual content. |
| 8305 | MockRead data_reads2[] = { |
| 8306 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8307 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8308 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8309 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8310 | }; |
| 8311 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8312 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8313 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8314 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8315 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8317 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8318 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8319 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8320 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8322 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8323 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8324 | |
| 8325 | rv = callback1.WaitForResult(); |
| 8326 | EXPECT_EQ(OK, rv); |
| 8327 | |
| 8328 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8329 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8330 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8332 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8333 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8334 | rv = trans->RestartWithAuth( |
| 8335 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8337 | |
| 8338 | rv = callback2.WaitForResult(); |
| 8339 | EXPECT_EQ(OK, rv); |
| 8340 | |
| 8341 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8342 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8343 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8344 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8345 | } |
| 8346 | |
| 8347 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8348 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8349 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8350 | |
| 8351 | HttpRequestInfo request; |
| 8352 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8353 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8354 | request.load_flags = 0; |
| 8355 | |
| 8356 | MockRead proxy_reads[] = { |
| 8357 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8358 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8359 | }; |
| 8360 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8361 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8362 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8363 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8367 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8368 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8369 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8370 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8371 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8372 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8373 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8375 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8376 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8377 | |
| 8378 | rv = callback.WaitForResult(); |
| 8379 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 8380 | } |
| 8381 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8382 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8383 | HttpRequestInfo request; |
| 8384 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8385 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8386 | request.load_flags = 0; |
| 8387 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8388 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8389 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8390 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8391 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8392 | MockRead data_reads[] = { |
| 8393 | 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] | 8394 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8395 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8396 | |
| 8397 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8400 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8403 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8404 | |
| 8405 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8406 | |
| 8407 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8408 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8409 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8410 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 8411 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8412 | |
| 8413 | std::string response_data; |
| 8414 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 8415 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 8416 | } |
| 8417 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8418 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8419 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8420 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8421 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 8422 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 8423 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8424 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8425 | ScopedVector<UploadElementReader> element_readers; |
| 8426 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8427 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8428 | temp_file_path, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8429 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8430 | |
| 8431 | HttpRequestInfo request; |
| 8432 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8433 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8434 | request.upload_data_stream = &upload_data_stream; |
| 8435 | request.load_flags = 0; |
| 8436 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8437 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8438 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8439 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8440 | |
| 8441 | MockRead data_reads[] = { |
| 8442 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 8443 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8445 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8446 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8447 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8449 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8451 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8452 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8453 | |
| 8454 | rv = callback.WaitForResult(); |
| 8455 | EXPECT_EQ(OK, rv); |
| 8456 | |
| 8457 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8458 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8459 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8460 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8461 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8462 | |
| 8463 | std::string response_data; |
| 8464 | rv = ReadTransaction(trans.get(), &response_data); |
| 8465 | EXPECT_EQ(OK, rv); |
| 8466 | EXPECT_EQ("hello world", response_data); |
| 8467 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8468 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 8469 | } |
| 8470 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8471 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 8472 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 8473 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8474 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 8475 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8476 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 8477 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8478 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 8479 | ScopedVector<UploadElementReader> element_readers; |
| 8480 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 8481 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 8482 | temp_file, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8483 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8484 | |
| 8485 | HttpRequestInfo request; |
| 8486 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8487 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8488 | request.upload_data_stream = &upload_data_stream; |
| 8489 | request.load_flags = 0; |
| 8490 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8491 | // If we try to upload an unreadable file, the transaction should fail. |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8492 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8493 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8494 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8495 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8496 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8499 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8501 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8502 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8503 | |
| 8504 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 8505 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8506 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 8507 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 8508 | } |
| 8509 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8510 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 8511 | class FakeUploadElementReader : public UploadElementReader { |
| 8512 | public: |
| 8513 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8514 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8515 | |
| 8516 | const CompletionCallback& callback() const { return callback_; } |
| 8517 | |
| 8518 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8519 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8520 | callback_ = callback; |
| 8521 | return ERR_IO_PENDING; |
| 8522 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 8523 | uint64 GetContentLength() const override { return 0; } |
| 8524 | uint64 BytesRemaining() const override { return 0; } |
| 8525 | int Read(IOBuffer* buf, |
| 8526 | int buf_length, |
| 8527 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8528 | return ERR_FAILED; |
| 8529 | } |
| 8530 | |
| 8531 | private: |
| 8532 | CompletionCallback callback_; |
| 8533 | }; |
| 8534 | |
| 8535 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 8536 | ScopedVector<UploadElementReader> element_readers; |
| 8537 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 8538 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8539 | |
| 8540 | HttpRequestInfo request; |
| 8541 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8542 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8543 | request.upload_data_stream = &upload_data_stream; |
| 8544 | request.load_flags = 0; |
| 8545 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8546 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8547 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8548 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 8549 | |
| 8550 | StaticSocketDataProvider data; |
| 8551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8552 | |
| 8553 | TestCompletionCallback callback; |
| 8554 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8555 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8556 | base::MessageLoop::current()->RunUntilIdle(); |
| 8557 | |
| 8558 | // Transaction is pending on request body initialization. |
| 8559 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 8560 | |
| 8561 | // Return Init()'s result after the transaction gets destroyed. |
| 8562 | trans.reset(); |
| 8563 | fake_reader->callback().Run(OK); // Should not crash. |
| 8564 | } |
| 8565 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8566 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8567 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8568 | HttpRequestInfo request; |
| 8569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8570 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8571 | request.load_flags = 0; |
| 8572 | |
| 8573 | // First transaction will request a resource and receive a Basic challenge |
| 8574 | // with realm="first_realm". |
| 8575 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8576 | MockWrite( |
| 8577 | "GET / HTTP/1.1\r\n" |
| 8578 | "Host: www.example.org\r\n" |
| 8579 | "Connection: keep-alive\r\n" |
| 8580 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8581 | }; |
| 8582 | MockRead data_reads1[] = { |
| 8583 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8584 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8585 | "\r\n"), |
| 8586 | }; |
| 8587 | |
| 8588 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 8589 | // for first_realm. The server will reject and provide a challenge with |
| 8590 | // second_realm. |
| 8591 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8592 | MockWrite( |
| 8593 | "GET / HTTP/1.1\r\n" |
| 8594 | "Host: www.example.org\r\n" |
| 8595 | "Connection: keep-alive\r\n" |
| 8596 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 8597 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8598 | }; |
| 8599 | MockRead data_reads2[] = { |
| 8600 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8601 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 8602 | "\r\n"), |
| 8603 | }; |
| 8604 | |
| 8605 | // This again fails, and goes back to first_realm. Make sure that the |
| 8606 | // entry is removed from cache. |
| 8607 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8608 | MockWrite( |
| 8609 | "GET / HTTP/1.1\r\n" |
| 8610 | "Host: www.example.org\r\n" |
| 8611 | "Connection: keep-alive\r\n" |
| 8612 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 8613 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8614 | }; |
| 8615 | MockRead data_reads3[] = { |
| 8616 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 8617 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 8618 | "\r\n"), |
| 8619 | }; |
| 8620 | |
| 8621 | // Try one last time (with the correct password) and get the resource. |
| 8622 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8623 | MockWrite( |
| 8624 | "GET / HTTP/1.1\r\n" |
| 8625 | "Host: www.example.org\r\n" |
| 8626 | "Connection: keep-alive\r\n" |
| 8627 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 8628 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8629 | }; |
| 8630 | MockRead data_reads4[] = { |
| 8631 | MockRead("HTTP/1.1 200 OK\r\n" |
| 8632 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8633 | "Content-Length: 5\r\n" |
| 8634 | "\r\n" |
| 8635 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8636 | }; |
| 8637 | |
| 8638 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8639 | data_writes1, arraysize(data_writes1)); |
| 8640 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8641 | data_writes2, arraysize(data_writes2)); |
| 8642 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8643 | data_writes3, arraysize(data_writes3)); |
| 8644 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 8645 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8647 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8648 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8649 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8651 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8652 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8653 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8654 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8655 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8656 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8657 | // Issue the first request with Authorize headers. There should be a |
| 8658 | // password prompt for first_realm waiting to be filled in after the |
| 8659 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8660 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8661 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8662 | rv = callback1.WaitForResult(); |
| 8663 | EXPECT_EQ(OK, rv); |
| 8664 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8665 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8666 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 8667 | ASSERT_FALSE(challenge == NULL); |
| 8668 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8669 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8670 | EXPECT_EQ("first_realm", challenge->realm); |
| 8671 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8672 | |
| 8673 | // Issue the second request with an incorrect password. There should be a |
| 8674 | // password prompt for second_realm waiting to be filled in after the |
| 8675 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8676 | TestCompletionCallback callback2; |
| 8677 | rv = trans->RestartWithAuth( |
| 8678 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8679 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8680 | rv = callback2.WaitForResult(); |
| 8681 | EXPECT_EQ(OK, rv); |
| 8682 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8683 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8684 | challenge = response->auth_challenge.get(); |
| 8685 | ASSERT_FALSE(challenge == NULL); |
| 8686 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8687 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8688 | EXPECT_EQ("second_realm", challenge->realm); |
| 8689 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8690 | |
| 8691 | // Issue the third request with another incorrect password. There should be |
| 8692 | // a password prompt for first_realm waiting to be filled in. If the password |
| 8693 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 8694 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8695 | TestCompletionCallback callback3; |
| 8696 | rv = trans->RestartWithAuth( |
| 8697 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8698 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8699 | rv = callback3.WaitForResult(); |
| 8700 | EXPECT_EQ(OK, rv); |
| 8701 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8702 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8703 | challenge = response->auth_challenge.get(); |
| 8704 | ASSERT_FALSE(challenge == NULL); |
| 8705 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8706 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8707 | EXPECT_EQ("first_realm", challenge->realm); |
| 8708 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8709 | |
| 8710 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8711 | TestCompletionCallback callback4; |
| 8712 | rv = trans->RestartWithAuth( |
| 8713 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8714 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8715 | rv = callback4.WaitForResult(); |
| 8716 | EXPECT_EQ(OK, rv); |
| 8717 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8718 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 8719 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 8720 | } |
| 8721 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8722 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 8723 | session_deps_.next_protos = SpdyNextProtos(); |
| 8724 | session_deps_.use_alternate_protocols = true; |
| 8725 | |
| 8726 | std::string alternative_service_http_header = |
| 8727 | GetAlternativeServiceHttpHeader(); |
| 8728 | |
| 8729 | MockRead data_reads[] = { |
| 8730 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8731 | MockRead(alternative_service_http_header.c_str()), |
| 8732 | MockRead("\r\n"), |
| 8733 | MockRead("hello world"), |
| 8734 | MockRead(SYNCHRONOUS, OK), |
| 8735 | }; |
| 8736 | |
| 8737 | HttpRequestInfo request; |
| 8738 | request.method = "GET"; |
| 8739 | request.url = GURL("http://www.example.org/"); |
| 8740 | request.load_flags = 0; |
| 8741 | |
| 8742 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8743 | |
| 8744 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8745 | |
| 8746 | TestCompletionCallback callback; |
| 8747 | |
| 8748 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8749 | scoped_ptr<HttpTransaction> trans( |
| 8750 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8751 | |
| 8752 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8754 | |
| 8755 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8756 | HttpServerProperties& http_server_properties = |
| 8757 | *session->http_server_properties(); |
| 8758 | AlternativeServiceVector alternative_service_vector = |
| 8759 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8760 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8761 | |
| 8762 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8763 | |
| 8764 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8765 | ASSERT_TRUE(response != NULL); |
| 8766 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8767 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8768 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8769 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8770 | |
| 8771 | std::string response_data; |
| 8772 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8773 | EXPECT_EQ("hello world", response_data); |
| 8774 | |
| 8775 | alternative_service_vector = |
| 8776 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8777 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8778 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8779 | alternative_service_vector[0].protocol); |
| 8780 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 8781 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 8782 | } |
| 8783 | |
| 8784 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 8785 | session_deps_.next_protos = SpdyNextProtos(); |
| 8786 | session_deps_.use_alternate_protocols = true; |
| 8787 | |
| 8788 | MockRead data_reads[] = { |
| 8789 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8790 | MockRead("Alt-Svc: "), |
| 8791 | MockRead(GetAlternateProtocolFromParam()), |
| 8792 | MockRead("=\"www.example.com:443\";p=1.0,"), |
| 8793 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 8794 | MockRead("hello world"), |
| 8795 | MockRead(SYNCHRONOUS, OK), |
| 8796 | }; |
| 8797 | |
| 8798 | HttpRequestInfo request; |
| 8799 | request.method = "GET"; |
| 8800 | request.url = GURL("http://www.example.org/"); |
| 8801 | request.load_flags = 0; |
| 8802 | |
| 8803 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8804 | |
| 8805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8806 | |
| 8807 | TestCompletionCallback callback; |
| 8808 | |
| 8809 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8810 | scoped_ptr<HttpTransaction> trans( |
| 8811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8812 | |
| 8813 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8815 | |
| 8816 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 8817 | HttpServerProperties& http_server_properties = |
| 8818 | *session->http_server_properties(); |
| 8819 | AlternativeServiceVector alternative_service_vector = |
| 8820 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8821 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 8822 | |
| 8823 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8824 | |
| 8825 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8826 | ASSERT_TRUE(response != NULL); |
| 8827 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8828 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8829 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8830 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8831 | |
| 8832 | std::string response_data; |
| 8833 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8834 | EXPECT_EQ("hello world", response_data); |
| 8835 | |
| 8836 | alternative_service_vector = |
| 8837 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8838 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 8839 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8840 | alternative_service_vector[0].protocol); |
| 8841 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 8842 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 8843 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 8844 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 8845 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 8846 | } |
| 8847 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8848 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 8849 | session_deps_.next_protos = SpdyNextProtos(); |
| 8850 | session_deps_.use_alternate_protocols = true; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 8851 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8852 | std::string alternate_protocol_http_header = |
| 8853 | GetAlternateProtocolHttpHeader(); |
| 8854 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8855 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8856 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8857 | MockRead(alternate_protocol_http_header.c_str()), |
| 8858 | MockRead("\r\n"), |
| 8859 | MockRead("hello world"), |
| 8860 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8861 | }; |
| 8862 | |
| 8863 | HttpRequestInfo request; |
| 8864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8865 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8866 | request.load_flags = 0; |
| 8867 | |
| 8868 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8869 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8870 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8872 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8873 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8874 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8875 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8876 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8878 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8879 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 8880 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8881 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 8882 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8883 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 8884 | AlternativeServiceVector alternative_service_vector = |
| 8885 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8886 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8887 | |
| 8888 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8889 | |
| 8890 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8891 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8892 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8893 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 8894 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8895 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8896 | |
| 8897 | std::string response_data; |
| 8898 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8899 | EXPECT_EQ("hello world", response_data); |
| 8900 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 8901 | alternative_service_vector = |
| 8902 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8903 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8904 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 8905 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 8906 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 8907 | } |
| 8908 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8909 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 8910 | session_deps_.next_protos = SpdyNextProtos(); |
| 8911 | session_deps_.use_alternate_protocols = true; |
| 8912 | |
| 8913 | MockRead data_reads[] = { |
| 8914 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8915 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 8916 | MockRead("hello world"), |
| 8917 | MockRead(SYNCHRONOUS, OK), |
| 8918 | }; |
| 8919 | |
| 8920 | HttpRequestInfo request; |
| 8921 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8922 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8923 | request.load_flags = 0; |
| 8924 | |
| 8925 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8926 | |
| 8927 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8928 | |
| 8929 | TestCompletionCallback callback; |
| 8930 | |
| 8931 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8932 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8933 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8934 | HttpServerProperties& http_server_properties = |
| 8935 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8936 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8937 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 8938 | http_server_properties.SetAlternativeService( |
| 8939 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8940 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 8941 | AlternativeServiceVector alternative_service_vector = |
| 8942 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8943 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 8944 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8945 | |
| 8946 | scoped_ptr<HttpTransaction> trans( |
| 8947 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8948 | |
| 8949 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8950 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8951 | |
| 8952 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 8953 | |
| 8954 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8955 | ASSERT_TRUE(response != NULL); |
| 8956 | ASSERT_TRUE(response->headers.get() != NULL); |
| 8957 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8958 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8959 | EXPECT_FALSE(response->was_npn_negotiated); |
| 8960 | |
| 8961 | std::string response_data; |
| 8962 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8963 | EXPECT_EQ("hello world", response_data); |
| 8964 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 8965 | alternative_service_vector = |
| 8966 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 8967 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 8968 | } |
| 8969 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 8970 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 8971 | session_deps_.next_protos = SpdyNextProtos(); |
| 8972 | session_deps_.use_alternate_protocols = true; |
| 8973 | |
| 8974 | std::string alternative_service_http_header = |
| 8975 | GetAlternativeServiceHttpHeader(); |
| 8976 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 8977 | |
| 8978 | MockRead data_reads[] = { |
| 8979 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8980 | MockRead(alternative_service_http_header.c_str()), |
| 8981 | MockRead(alternate_protocol_http_header.c_str()), |
| 8982 | MockRead("\r\n"), |
| 8983 | MockRead("hello world"), |
| 8984 | MockRead(SYNCHRONOUS, OK), |
| 8985 | }; |
| 8986 | |
| 8987 | HttpRequestInfo request; |
| 8988 | request.method = "GET"; |
| 8989 | request.url = GURL("http://www.example.org/"); |
| 8990 | request.load_flags = 0; |
| 8991 | |
| 8992 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8993 | |
| 8994 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8995 | |
| 8996 | TestCompletionCallback callback; |
| 8997 | |
| 8998 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8999 | scoped_ptr<HttpTransaction> trans( |
| 9000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9001 | |
| 9002 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9004 | |
| 9005 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9006 | HttpServerProperties& http_server_properties = |
| 9007 | *session->http_server_properties(); |
| 9008 | AlternativeServiceVector alternative_service_vector = |
| 9009 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9010 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9011 | |
| 9012 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9013 | |
| 9014 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9015 | ASSERT_TRUE(response != NULL); |
| 9016 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9017 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9018 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9019 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9020 | |
| 9021 | std::string response_data; |
| 9022 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9023 | EXPECT_EQ("hello world", response_data); |
| 9024 | |
| 9025 | alternative_service_vector = |
| 9026 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9027 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9028 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9029 | alternative_service_vector[0].protocol); |
| 9030 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9031 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9032 | } |
| 9033 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9034 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9035 | MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9036 | session_deps_.use_alternate_protocols = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9037 | |
| 9038 | HttpRequestInfo request; |
| 9039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9040 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9041 | request.load_flags = 0; |
| 9042 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9043 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9044 | StaticSocketDataProvider first_data; |
| 9045 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9046 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9047 | |
| 9048 | MockRead data_reads[] = { |
| 9049 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9050 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9051 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9052 | }; |
| 9053 | StaticSocketDataProvider second_data( |
| 9054 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9055 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9056 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9057 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9058 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9059 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9060 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9061 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9062 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9063 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9064 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9065 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9066 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9067 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9068 | http_server_properties->SetAlternativeService( |
| 9069 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9070 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9071 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9073 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9075 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9076 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9077 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9078 | |
| 9079 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9080 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9081 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9082 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9083 | |
| 9084 | std::string response_data; |
| 9085 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9086 | EXPECT_EQ("hello world", response_data); |
| 9087 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9088 | const AlternativeServiceVector alternative_service_vector = |
| 9089 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9090 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9091 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9092 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9093 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9094 | } |
| 9095 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9096 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9097 | AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9098 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9099 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9100 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9101 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9102 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9103 | |
| 9104 | HttpRequestInfo restricted_port_request; |
| 9105 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9106 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9107 | restricted_port_request.load_flags = 0; |
| 9108 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9109 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9110 | StaticSocketDataProvider first_data; |
| 9111 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9112 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9113 | |
| 9114 | MockRead data_reads[] = { |
| 9115 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9116 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9117 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9118 | }; |
| 9119 | StaticSocketDataProvider second_data( |
| 9120 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9121 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9122 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9123 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9124 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9125 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9126 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9127 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9128 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9129 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9130 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9131 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9132 | http_server_properties->SetAlternativeService( |
| 9133 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9134 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9135 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9136 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9137 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9138 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9140 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9141 | &restricted_port_request, |
| 9142 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9144 | // Invalid change to unrestricted port should fail. |
| 9145 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9146 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9147 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9148 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9149 | AlternateProtocolPortRestrictedPermitted) { |
| 9150 | // Ensure that we're allowed to redirect traffic via an alternate |
| 9151 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9152 | // on a restricted port (port < 1024) if we set |
| 9153 | // enable_user_alternate_protocol_ports. |
| 9154 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9155 | session_deps_.use_alternate_protocols = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9156 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9157 | |
| 9158 | HttpRequestInfo restricted_port_request; |
| 9159 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9160 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9161 | restricted_port_request.load_flags = 0; |
| 9162 | |
| 9163 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9164 | StaticSocketDataProvider first_data; |
| 9165 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9166 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9167 | |
| 9168 | MockRead data_reads[] = { |
| 9169 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9170 | MockRead("hello world"), |
| 9171 | MockRead(ASYNC, OK), |
| 9172 | }; |
| 9173 | StaticSocketDataProvider second_data( |
| 9174 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9175 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9176 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9177 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9178 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9179 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9180 | session->http_server_properties(); |
| 9181 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9182 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9183 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9184 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9185 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9186 | http_server_properties->SetAlternativeService( |
| 9187 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9188 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9189 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9190 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9191 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9192 | TestCompletionCallback callback; |
| 9193 | |
| 9194 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9195 | &restricted_port_request, |
| 9196 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9197 | // Change to unrestricted port should succeed. |
| 9198 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9199 | } |
| 9200 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9201 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9202 | AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9203 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9204 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9205 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9206 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9207 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9208 | |
| 9209 | HttpRequestInfo restricted_port_request; |
| 9210 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9211 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9212 | restricted_port_request.load_flags = 0; |
| 9213 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9214 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9215 | StaticSocketDataProvider first_data; |
| 9216 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9217 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9218 | |
| 9219 | MockRead data_reads[] = { |
| 9220 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9221 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9222 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9223 | }; |
| 9224 | StaticSocketDataProvider second_data( |
| 9225 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9226 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9227 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9229 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9230 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9231 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9232 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9233 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9234 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9235 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9236 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9237 | http_server_properties->SetAlternativeService( |
| 9238 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9239 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9240 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9241 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9242 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9243 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9245 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9246 | &restricted_port_request, |
| 9247 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9249 | // Valid change to restricted port should pass. |
| 9250 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9251 | } |
| 9252 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9253 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9254 | AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9255 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9256 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9257 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9258 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9259 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9260 | |
| 9261 | HttpRequestInfo unrestricted_port_request; |
| 9262 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9263 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9264 | unrestricted_port_request.load_flags = 0; |
| 9265 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9266 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9267 | StaticSocketDataProvider first_data; |
| 9268 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9269 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9270 | |
| 9271 | MockRead data_reads[] = { |
| 9272 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9273 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9274 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9275 | }; |
| 9276 | StaticSocketDataProvider second_data( |
| 9277 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9278 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9279 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9280 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9281 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9282 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9283 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9284 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9285 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9286 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9287 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9288 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9289 | http_server_properties->SetAlternativeService( |
| 9290 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9291 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9292 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9293 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9294 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9295 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9297 | int rv = trans->Start( |
| 9298 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9299 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9300 | // Valid change to restricted port should pass. |
| 9301 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9302 | } |
| 9303 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9304 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9305 | AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9306 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9307 | // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 9308 | // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 9309 | // other cases. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9310 | session_deps_.use_alternate_protocols = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9311 | |
| 9312 | HttpRequestInfo unrestricted_port_request; |
| 9313 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9314 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9315 | unrestricted_port_request.load_flags = 0; |
| 9316 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9317 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9318 | StaticSocketDataProvider first_data; |
| 9319 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9320 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9321 | |
| 9322 | MockRead data_reads[] = { |
| 9323 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9324 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9325 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9326 | }; |
| 9327 | StaticSocketDataProvider second_data( |
| 9328 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9329 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9330 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9332 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9333 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9334 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 9335 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9336 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9337 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9338 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9339 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9340 | http_server_properties->SetAlternativeService( |
| 9341 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9342 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9343 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9344 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9346 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9348 | int rv = trans->Start( |
| 9349 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9351 | // Valid change to an unrestricted port should pass. |
| 9352 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9353 | } |
| 9354 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9355 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9356 | // Ensure that we're not allowed to redirect traffic via an alternate |
| 9357 | // protocol to an unsafe port, and that we resume the second |
| 9358 | // HttpStreamFactoryImpl::Job once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9359 | session_deps_.use_alternate_protocols = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9360 | |
| 9361 | HttpRequestInfo request; |
| 9362 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9363 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9364 | request.load_flags = 0; |
| 9365 | |
| 9366 | // The alternate protocol request will error out before we attempt to connect, |
| 9367 | // so only the standard HTTP request will try to connect. |
| 9368 | MockRead data_reads[] = { |
| 9369 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9370 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9371 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9372 | }; |
| 9373 | StaticSocketDataProvider data( |
| 9374 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9375 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9376 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9377 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9378 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9379 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9380 | session->http_server_properties(); |
| 9381 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9382 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9383 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9384 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9385 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9386 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9387 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9388 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9389 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9390 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9391 | TestCompletionCallback callback; |
| 9392 | |
| 9393 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9394 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9395 | // The HTTP request should succeed. |
| 9396 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9397 | |
| 9398 | // Disable alternate protocol before the asserts. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9399 | // HttpStreamFactory::set_use_alternate_protocols(false); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9400 | |
| 9401 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9402 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9403 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 9404 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9405 | |
| 9406 | std::string response_data; |
| 9407 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9408 | EXPECT_EQ("hello world", response_data); |
| 9409 | } |
| 9410 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9411 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9412 | session_deps_.use_alternate_protocols = true; |
| 9413 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9414 | |
| 9415 | HttpRequestInfo request; |
| 9416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9417 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9418 | request.load_flags = 0; |
| 9419 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9420 | std::string alternate_protocol_http_header = |
| 9421 | GetAlternateProtocolHttpHeader(); |
| 9422 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9423 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9424 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9425 | MockRead(alternate_protocol_http_header.c_str()), |
| 9426 | MockRead("\r\n"), |
| 9427 | MockRead("hello world"), |
| 9428 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9429 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9430 | |
| 9431 | StaticSocketDataProvider first_transaction( |
| 9432 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9433 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9434 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9435 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9436 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9437 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9438 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9440 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9441 | scoped_ptr<SpdyFrame> req( |
| 9442 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9443 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9444 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9445 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9446 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9447 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9448 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9449 | }; |
| 9450 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9451 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9452 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9453 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9454 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9455 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9456 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9457 | NULL, 0, NULL, 0); |
| 9458 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9459 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9460 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9461 | &hanging_non_alternate_protocol_socket); |
| 9462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9463 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9464 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9465 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9466 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9467 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9469 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9470 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9471 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9472 | |
| 9473 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9474 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9475 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9476 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9477 | |
| 9478 | std::string response_data; |
| 9479 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9480 | EXPECT_EQ("hello world", response_data); |
| 9481 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9482 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9484 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9485 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9486 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9487 | |
| 9488 | response = trans->GetResponseInfo(); |
| 9489 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9490 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9491 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9492 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9493 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9494 | |
| 9495 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9496 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9497 | } |
| 9498 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9499 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9500 | session_deps_.use_alternate_protocols = true; |
| 9501 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9502 | |
| 9503 | HttpRequestInfo request; |
| 9504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9505 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9506 | request.load_flags = 0; |
| 9507 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9508 | std::string alternate_protocol_http_header = |
| 9509 | GetAlternateProtocolHttpHeader(); |
| 9510 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9511 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9512 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9513 | MockRead(alternate_protocol_http_header.c_str()), |
| 9514 | MockRead("\r\n"), |
| 9515 | MockRead("hello world"), |
| 9516 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9517 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9518 | }; |
| 9519 | |
| 9520 | StaticSocketDataProvider first_transaction( |
| 9521 | data_reads, arraysize(data_reads), NULL, 0); |
| 9522 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9523 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9524 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9525 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9526 | StaticSocketDataProvider hanging_socket( |
| 9527 | NULL, 0, NULL, 0); |
| 9528 | hanging_socket.set_connect_data(never_finishing_connect); |
| 9529 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 9530 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9531 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 9532 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9533 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9534 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9535 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9536 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9537 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9539 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9540 | scoped_ptr<SpdyFrame> req1( |
| 9541 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 9542 | scoped_ptr<SpdyFrame> req2( |
| 9543 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9544 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9545 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9546 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9547 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9548 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 9549 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 9550 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9551 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9552 | CreateMockRead(*resp1, 2), |
| 9553 | CreateMockRead(*data1, 3), |
| 9554 | CreateMockRead(*resp2, 4), |
| 9555 | CreateMockRead(*data2, 5), |
| 9556 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9557 | }; |
| 9558 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9559 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9560 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9561 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9562 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9563 | |
| 9564 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9565 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9566 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9567 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9568 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9569 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9571 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9572 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9573 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 9574 | |
| 9575 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 9576 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9577 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9578 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9579 | |
| 9580 | std::string response_data; |
| 9581 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 9582 | EXPECT_EQ("hello world", response_data); |
| 9583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9584 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9585 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9586 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9587 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9589 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9590 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9591 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9592 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9593 | |
| 9594 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 9595 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 9596 | |
| 9597 | response = trans2.GetResponseInfo(); |
| 9598 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9599 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9600 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9601 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9602 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9603 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 9604 | EXPECT_EQ("hello!", response_data); |
| 9605 | |
| 9606 | response = trans3.GetResponseInfo(); |
| 9607 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9608 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9609 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9610 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9611 | EXPECT_TRUE(response->was_npn_negotiated); |
| 9612 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 9613 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9614 | } |
| 9615 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9616 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9617 | session_deps_.use_alternate_protocols = true; |
| 9618 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9619 | |
| 9620 | HttpRequestInfo request; |
| 9621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9622 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9623 | request.load_flags = 0; |
| 9624 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9625 | std::string alternate_protocol_http_header = |
| 9626 | GetAlternateProtocolHttpHeader(); |
| 9627 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9628 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9629 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9630 | MockRead(alternate_protocol_http_header.c_str()), |
| 9631 | MockRead("\r\n"), |
| 9632 | MockRead("hello world"), |
| 9633 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9634 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9635 | }; |
| 9636 | |
| 9637 | StaticSocketDataProvider first_transaction( |
| 9638 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9639 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9640 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9641 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9642 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9643 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9644 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9645 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9646 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 9647 | NULL, 0, NULL, 0); |
| 9648 | hanging_alternate_protocol_socket.set_connect_data( |
| 9649 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9650 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9651 | &hanging_alternate_protocol_socket); |
| 9652 | |
| 9653 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9654 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9656 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9657 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9658 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9659 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9660 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9661 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9662 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9664 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9665 | |
| 9666 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9667 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9668 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9669 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9670 | |
| 9671 | std::string response_data; |
| 9672 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9673 | EXPECT_EQ("hello world", response_data); |
| 9674 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9675 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9677 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9678 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9679 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9680 | |
| 9681 | response = trans->GetResponseInfo(); |
| 9682 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9683 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9684 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9685 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9686 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9687 | |
| 9688 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9689 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9690 | } |
| 9691 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9692 | class CapturingProxyResolver : public ProxyResolver { |
| 9693 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 9694 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9695 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9696 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9697 | int GetProxyForURL(const GURL& url, |
| 9698 | ProxyInfo* results, |
| 9699 | const CompletionCallback& callback, |
| 9700 | RequestHandle* request, |
| 9701 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 9702 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 9703 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9704 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9705 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9706 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9707 | } |
| 9708 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9709 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9710 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9711 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 9712 | NOTREACHED(); |
| 9713 | return LOAD_STATE_IDLE; |
| 9714 | } |
| 9715 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 9716 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 9717 | |
| 9718 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9719 | std::vector<GURL> resolved_; |
| 9720 | |
| 9721 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 9722 | }; |
| 9723 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9724 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 9725 | public: |
| 9726 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 9727 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 9728 | |
| 9729 | int CreateProxyResolver( |
| 9730 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 9731 | scoped_ptr<ProxyResolver>* resolver, |
| 9732 | const net::CompletionCallback& callback, |
| 9733 | scoped_ptr<Request>* request) override { |
| 9734 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 9735 | return OK; |
| 9736 | } |
| 9737 | |
| 9738 | private: |
| 9739 | ProxyResolver* resolver_; |
| 9740 | }; |
| 9741 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9742 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9743 | UseAlternateProtocolForTunneledNpnSpdy) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9744 | session_deps_.use_alternate_protocols = true; |
| 9745 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9746 | |
| 9747 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9748 | proxy_config.set_auto_detect(true); |
| 9749 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 9750 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9751 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9752 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9753 | new ProxyConfigServiceFixed(proxy_config), |
| 9754 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 9755 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9756 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9757 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9758 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9759 | |
| 9760 | HttpRequestInfo request; |
| 9761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9762 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9763 | request.load_flags = 0; |
| 9764 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9765 | std::string alternate_protocol_http_header = |
| 9766 | GetAlternateProtocolHttpHeader(); |
| 9767 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9768 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9769 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9770 | MockRead(alternate_protocol_http_header.c_str()), |
| 9771 | MockRead("\r\n"), |
| 9772 | MockRead("hello world"), |
| 9773 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 9774 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9775 | }; |
| 9776 | |
| 9777 | StaticSocketDataProvider first_transaction( |
| 9778 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9779 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9780 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9781 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9782 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9783 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9784 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9786 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9787 | scoped_ptr<SpdyFrame> req( |
| 9788 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9789 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9790 | MockWrite(ASYNC, 0, |
| 9791 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9792 | "Host: www.example.org\r\n" |
| 9793 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9794 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9795 | }; |
| 9796 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 9797 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 9798 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9799 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9800 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9801 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9802 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 9803 | CreateMockRead(*resp.get(), 3), |
| 9804 | CreateMockRead(*data.get(), 4), |
| 9805 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9806 | }; |
| 9807 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9808 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9809 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9810 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9811 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9812 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9813 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 9814 | NULL, 0, NULL, 0); |
| 9815 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 9816 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9817 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 9818 | &hanging_non_alternate_protocol_socket); |
| 9819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9820 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9821 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9822 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9823 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9826 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9827 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9828 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9829 | |
| 9830 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9831 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9832 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9833 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9834 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9835 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9836 | |
| 9837 | std::string response_data; |
| 9838 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9839 | EXPECT_EQ("hello world", response_data); |
| 9840 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9841 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9843 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9844 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9845 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9846 | |
| 9847 | response = trans->GetResponseInfo(); |
| 9848 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9849 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9850 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9851 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9852 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9853 | |
| 9854 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9855 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9856 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9857 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9858 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9859 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 9860 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9861 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9862 | LoadTimingInfo load_timing_info; |
| 9863 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9864 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9865 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9866 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 9867 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9868 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9869 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9870 | session_deps_.use_alternate_protocols = true; |
| 9871 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9872 | |
| 9873 | HttpRequestInfo request; |
| 9874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9875 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9876 | request.load_flags = 0; |
| 9877 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9878 | std::string alternate_protocol_http_header = |
| 9879 | GetAlternateProtocolHttpHeader(); |
| 9880 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9881 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9882 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9883 | MockRead(alternate_protocol_http_header.c_str()), |
| 9884 | MockRead("\r\n"), |
| 9885 | MockRead("hello world"), |
| 9886 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9887 | }; |
| 9888 | |
| 9889 | StaticSocketDataProvider first_transaction( |
| 9890 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9891 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9892 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9893 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9894 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9895 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 9896 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9898 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 9899 | scoped_ptr<SpdyFrame> req( |
| 9900 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9901 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9902 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9903 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 9904 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9905 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9906 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9907 | }; |
| 9908 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9909 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9910 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9911 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9912 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 9913 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9914 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9915 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9916 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9917 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9918 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9919 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9920 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9921 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9922 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9923 | |
| 9924 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9925 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9926 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9927 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9928 | |
| 9929 | std::string response_data; |
| 9930 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9931 | EXPECT_EQ("hello world", response_data); |
| 9932 | |
| 9933 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9934 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 9935 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 9936 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 9937 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 9938 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 9939 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9940 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9942 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9943 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9944 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9945 | |
| 9946 | response = trans->GetResponseInfo(); |
| 9947 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9948 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9949 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9950 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 9951 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9952 | |
| 9953 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9954 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9955 | } |
| 9956 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9957 | // GenerateAuthToken is a mighty big test. |
| 9958 | // It tests all permutation of GenerateAuthToken behavior: |
| 9959 | // - Synchronous and Asynchronous completion. |
| 9960 | // - OK or error on completion. |
| 9961 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 9962 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 9963 | // - Non-authenticating and authenticating backend. |
| 9964 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 9965 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9966 | // problems generating an auth token for an authenticating proxy, we don't |
| 9967 | // need to test all permutations of the backend server). |
| 9968 | // |
| 9969 | // The test proceeds by going over each of the configuration cases, and |
| 9970 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 9971 | // specifies both the configuration for the test as well as the expectations |
| 9972 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9973 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9974 | static const char kServer[] = "http://www.example.com"; |
| 9975 | static const char kSecureServer[] = "https://www.example.com"; |
| 9976 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 9977 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 9978 | |
| 9979 | enum AuthTiming { |
| 9980 | AUTH_NONE, |
| 9981 | AUTH_SYNC, |
| 9982 | AUTH_ASYNC, |
| 9983 | }; |
| 9984 | |
| 9985 | const MockWrite kGet( |
| 9986 | "GET / HTTP/1.1\r\n" |
| 9987 | "Host: www.example.com\r\n" |
| 9988 | "Connection: keep-alive\r\n\r\n"); |
| 9989 | const MockWrite kGetProxy( |
| 9990 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 9991 | "Host: www.example.com\r\n" |
| 9992 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 9993 | const MockWrite kGetAuth( |
| 9994 | "GET / HTTP/1.1\r\n" |
| 9995 | "Host: www.example.com\r\n" |
| 9996 | "Connection: keep-alive\r\n" |
| 9997 | "Authorization: auth_token\r\n\r\n"); |
| 9998 | const MockWrite kGetProxyAuth( |
| 9999 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10000 | "Host: www.example.com\r\n" |
| 10001 | "Proxy-Connection: keep-alive\r\n" |
| 10002 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10003 | const MockWrite kGetAuthThroughProxy( |
| 10004 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10005 | "Host: www.example.com\r\n" |
| 10006 | "Proxy-Connection: keep-alive\r\n" |
| 10007 | "Authorization: auth_token\r\n\r\n"); |
| 10008 | const MockWrite kGetAuthWithProxyAuth( |
| 10009 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10010 | "Host: www.example.com\r\n" |
| 10011 | "Proxy-Connection: keep-alive\r\n" |
| 10012 | "Proxy-Authorization: auth_token\r\n" |
| 10013 | "Authorization: auth_token\r\n\r\n"); |
| 10014 | const MockWrite kConnect( |
| 10015 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10016 | "Host: www.example.com\r\n" |
| 10017 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10018 | const MockWrite kConnectProxyAuth( |
| 10019 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10020 | "Host: www.example.com\r\n" |
| 10021 | "Proxy-Connection: keep-alive\r\n" |
| 10022 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10023 | |
| 10024 | const MockRead kSuccess( |
| 10025 | "HTTP/1.1 200 OK\r\n" |
| 10026 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10027 | "Content-Length: 3\r\n\r\n" |
| 10028 | "Yes"); |
| 10029 | const MockRead kFailure( |
| 10030 | "Should not be called."); |
| 10031 | const MockRead kServerChallenge( |
| 10032 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10033 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10034 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10035 | "Content-Length: 14\r\n\r\n" |
| 10036 | "Unauthorized\r\n"); |
| 10037 | const MockRead kProxyChallenge( |
| 10038 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10039 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10040 | "Proxy-Connection: close\r\n" |
| 10041 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10042 | "Content-Length: 14\r\n\r\n" |
| 10043 | "Unauthorized\r\n"); |
| 10044 | const MockRead kProxyConnected( |
| 10045 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10046 | |
| 10047 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10048 | // no constructors, but the C++ compiler on Windows warns about |
| 10049 | // unspecified data in compound literals. So, moved to using constructors, |
| 10050 | // and TestRound's created with the default constructor should not be used. |
| 10051 | struct TestRound { |
| 10052 | TestRound() |
| 10053 | : expected_rv(ERR_UNEXPECTED), |
| 10054 | extra_write(NULL), |
| 10055 | extra_read(NULL) { |
| 10056 | } |
| 10057 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10058 | int expected_rv_arg) |
| 10059 | : write(write_arg), |
| 10060 | read(read_arg), |
| 10061 | expected_rv(expected_rv_arg), |
| 10062 | extra_write(NULL), |
| 10063 | extra_read(NULL) { |
| 10064 | } |
| 10065 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10066 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10067 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10068 | : write(write_arg), |
| 10069 | read(read_arg), |
| 10070 | expected_rv(expected_rv_arg), |
| 10071 | extra_write(extra_write_arg), |
| 10072 | extra_read(extra_read_arg) { |
| 10073 | } |
| 10074 | MockWrite write; |
| 10075 | MockRead read; |
| 10076 | int expected_rv; |
| 10077 | const MockWrite* extra_write; |
| 10078 | const MockRead* extra_read; |
| 10079 | }; |
| 10080 | |
| 10081 | static const int kNoSSL = 500; |
| 10082 | |
| 10083 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10084 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10085 | AuthTiming proxy_auth_timing; |
| 10086 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10087 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10088 | AuthTiming server_auth_timing; |
| 10089 | int server_auth_rv; |
| 10090 | int num_auth_rounds; |
| 10091 | int first_ssl_round; |
| 10092 | TestRound rounds[3]; |
| 10093 | } test_configs[] = { |
| 10094 | // Non-authenticating HTTP server with a direct connection. |
| 10095 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10096 | { TestRound(kGet, kSuccess, OK)}}, |
| 10097 | // Authenticating HTTP server with a direct connection. |
| 10098 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10099 | { TestRound(kGet, kServerChallenge, OK), |
| 10100 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10101 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10102 | { TestRound(kGet, kServerChallenge, OK), |
| 10103 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10104 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10105 | { TestRound(kGet, kServerChallenge, OK), |
| 10106 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10107 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10108 | { TestRound(kGet, kServerChallenge, OK), |
| 10109 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10110 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10111 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10112 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10113 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10114 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10115 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10116 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10117 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10118 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10119 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10120 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10121 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10122 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10123 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10124 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10125 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10126 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10127 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10128 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10129 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10130 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10131 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10132 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10133 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10134 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10135 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10136 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10137 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10138 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10139 | // Authenticating HTTP server through an authenticating proxy. |
| 10140 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10141 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10142 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10143 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10144 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10145 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10146 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10147 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10148 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10149 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10150 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10151 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10152 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10153 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10154 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10155 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10156 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10157 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10158 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10159 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10160 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10161 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10162 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10163 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10164 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10165 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10166 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10167 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10168 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10169 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10170 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10171 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10172 | // Non-authenticating HTTPS server with a direct connection. |
| 10173 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10174 | { TestRound(kGet, kSuccess, OK)}}, |
| 10175 | // Authenticating HTTPS server with a direct connection. |
| 10176 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10177 | { TestRound(kGet, kServerChallenge, OK), |
| 10178 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10179 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10180 | { TestRound(kGet, kServerChallenge, OK), |
| 10181 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10182 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10183 | { TestRound(kGet, kServerChallenge, OK), |
| 10184 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10185 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10186 | { TestRound(kGet, kServerChallenge, OK), |
| 10187 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10188 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10189 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10190 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10191 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10192 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10193 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10194 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10195 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10196 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10197 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10198 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10199 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10200 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10201 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10202 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10203 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10204 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10205 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10206 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10207 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10208 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10209 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10210 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10211 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10212 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10213 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10214 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10215 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10216 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10217 | // Authenticating HTTPS server through an authenticating proxy. |
| 10218 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10219 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10220 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10221 | &kGet, &kServerChallenge), |
| 10222 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10223 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10224 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10225 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10226 | &kGet, &kServerChallenge), |
| 10227 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10228 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 10229 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10230 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10231 | &kGet, &kServerChallenge), |
| 10232 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10233 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 10234 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10235 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10236 | &kGet, &kServerChallenge), |
| 10237 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10238 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10239 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10240 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10241 | &kGet, &kServerChallenge), |
| 10242 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10243 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10244 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10245 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10246 | &kGet, &kServerChallenge), |
| 10247 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10248 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 10249 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10250 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10251 | &kGet, &kServerChallenge), |
| 10252 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10253 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 10254 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10255 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 10256 | &kGet, &kServerChallenge), |
| 10257 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10258 | }; |
| 10259 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10260 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10261 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10262 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10263 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10264 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10265 | |
| 10266 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10267 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10268 | for (int n = 0; n < 2; n++) { |
| 10269 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10270 | std::string auth_challenge = "Mock realm=proxy"; |
| 10271 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10272 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10273 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10274 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 10275 | origin, BoundNetLog()); |
| 10276 | auth_handler->SetGenerateExpectation( |
| 10277 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 10278 | test_config.proxy_auth_rv); |
| 10279 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10280 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10281 | } |
| 10282 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 10283 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10284 | std::string auth_challenge = "Mock realm=server"; |
| 10285 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10286 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10287 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10288 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10289 | origin, BoundNetLog()); |
| 10290 | auth_handler->SetGenerateExpectation( |
| 10291 | test_config.server_auth_timing == AUTH_ASYNC, |
| 10292 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10293 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10294 | } |
| 10295 | if (test_config.proxy_url) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10296 | session_deps_.proxy_service.reset( |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 10297 | ProxyService::CreateFixed(test_config.proxy_url)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10298 | } else { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10299 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10300 | } |
| 10301 | |
| 10302 | HttpRequestInfo request; |
| 10303 | request.method = "GET"; |
| 10304 | request.url = GURL(test_config.server_url); |
| 10305 | request.load_flags = 0; |
| 10306 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10307 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10308 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10309 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10310 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 10311 | |
| 10312 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 10313 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10314 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10315 | const TestRound& read_write_round = test_config.rounds[round]; |
| 10316 | |
| 10317 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10318 | mock_reads.back().push_back(read_write_round.read); |
| 10319 | mock_writes.back().push_back(read_write_round.write); |
| 10320 | |
| 10321 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 10322 | // socket is closed and a new one will be created for the next request. |
| 10323 | if (read_write_round.read.data == kProxyChallenge.data && |
| 10324 | read_write_round.write.data != kConnect.data) { |
| 10325 | mock_reads.push_back(std::vector<MockRead>()); |
| 10326 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10327 | } |
| 10328 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10329 | if (read_write_round.extra_read) { |
| 10330 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10331 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10332 | if (read_write_round.extra_write) { |
| 10333 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 10334 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10335 | |
| 10336 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10337 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10338 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10339 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10340 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10341 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 10342 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 10343 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 10344 | data_providers.push_back(new StaticSocketDataProvider( |
| 10345 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 10346 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 10347 | session_deps_.socket_factory->AddSocketDataProvider( |
| 10348 | data_providers.back()); |
| 10349 | } |
| 10350 | |
| 10351 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 10352 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10353 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10354 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10355 | int rv; |
| 10356 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10357 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10358 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10359 | rv = trans.RestartWithAuth( |
| 10360 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10361 | } |
| 10362 | if (rv == ERR_IO_PENDING) |
| 10363 | rv = callback.WaitForResult(); |
| 10364 | |
| 10365 | // Compare results with expected data. |
| 10366 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10367 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 10368 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10369 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 10370 | continue; |
| 10371 | } |
| 10372 | if (round + 1 < test_config.num_auth_rounds) { |
| 10373 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 10374 | } else { |
| 10375 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 10376 | } |
| 10377 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 10378 | } |
| 10379 | } |
| 10380 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10381 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10382 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10383 | HttpAuthHandlerMock::Factory* auth_factory( |
| 10384 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10385 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10386 | session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
| 10387 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 10388 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10389 | |
| 10390 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 10391 | auth_handler->set_connection_based(true); |
| 10392 | std::string auth_challenge = "Mock realm=server"; |
| 10393 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 10394 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 10395 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10396 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 10397 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 10398 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10399 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10400 | int rv = OK; |
| 10401 | const HttpResponseInfo* response = NULL; |
| 10402 | HttpRequestInfo request; |
| 10403 | request.method = "GET"; |
| 10404 | request.url = origin; |
| 10405 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10406 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10407 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10408 | |
| 10409 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 10410 | // to validate that the TCP socket is not released to the pool between |
| 10411 | // each round of multi-round authentication. |
| 10412 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10413 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10414 | 50, // Max sockets for pool |
| 10415 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10416 | session_deps_.host_resolver.get(), |
| 10417 | session_deps_.socket_factory.get(), |
| 10418 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 10419 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 10420 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10421 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 10422 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10423 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10424 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10425 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10426 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10427 | |
| 10428 | const MockWrite kGet( |
| 10429 | "GET / HTTP/1.1\r\n" |
| 10430 | "Host: www.example.com\r\n" |
| 10431 | "Connection: keep-alive\r\n\r\n"); |
| 10432 | const MockWrite kGetAuth( |
| 10433 | "GET / HTTP/1.1\r\n" |
| 10434 | "Host: www.example.com\r\n" |
| 10435 | "Connection: keep-alive\r\n" |
| 10436 | "Authorization: auth_token\r\n\r\n"); |
| 10437 | |
| 10438 | const MockRead kServerChallenge( |
| 10439 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10440 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10441 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10442 | "Content-Length: 14\r\n\r\n" |
| 10443 | "Unauthorized\r\n"); |
| 10444 | const MockRead kSuccess( |
| 10445 | "HTTP/1.1 200 OK\r\n" |
| 10446 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10447 | "Content-Length: 3\r\n\r\n" |
| 10448 | "Yes"); |
| 10449 | |
| 10450 | MockWrite writes[] = { |
| 10451 | // First round |
| 10452 | kGet, |
| 10453 | // Second round |
| 10454 | kGetAuth, |
| 10455 | // Third round |
| 10456 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10457 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10458 | kGetAuth, |
| 10459 | // Competing request |
| 10460 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10461 | }; |
| 10462 | MockRead reads[] = { |
| 10463 | // First round |
| 10464 | kServerChallenge, |
| 10465 | // Second round |
| 10466 | kServerChallenge, |
| 10467 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10468 | kServerChallenge, |
| 10469 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10470 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10471 | // Competing response |
| 10472 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10473 | }; |
| 10474 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 10475 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10476 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10477 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10478 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10479 | |
| 10480 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10481 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10482 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10483 | if (rv == ERR_IO_PENDING) |
| 10484 | rv = callback.WaitForResult(); |
| 10485 | EXPECT_EQ(OK, rv); |
| 10486 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10487 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10488 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10489 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10490 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10491 | // In between rounds, another request comes in for the same domain. |
| 10492 | // It should not be able to grab the TCP socket that trans has already |
| 10493 | // claimed. |
| 10494 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10495 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10496 | TestCompletionCallback callback_compete; |
| 10497 | rv = trans_compete->Start( |
| 10498 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10499 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10500 | // callback_compete.WaitForResult at this point would stall forever, |
| 10501 | // since the HttpNetworkTransaction does not release the request back to |
| 10502 | // the pool until after authentication completes. |
| 10503 | |
| 10504 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10505 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10506 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10507 | if (rv == ERR_IO_PENDING) |
| 10508 | rv = callback.WaitForResult(); |
| 10509 | EXPECT_EQ(OK, rv); |
| 10510 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10511 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10512 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10513 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10514 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10515 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10516 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10517 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10518 | if (rv == ERR_IO_PENDING) |
| 10519 | rv = callback.WaitForResult(); |
| 10520 | EXPECT_EQ(OK, rv); |
| 10521 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10522 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10523 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10524 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10525 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10526 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10527 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10528 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10529 | if (rv == ERR_IO_PENDING) |
| 10530 | rv = callback.WaitForResult(); |
| 10531 | EXPECT_EQ(OK, rv); |
| 10532 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10533 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 10534 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10535 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10536 | |
| 10537 | // Read the body since the fourth round was successful. This will also |
| 10538 | // release the socket back to the pool. |
| 10539 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10540 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10541 | if (rv == ERR_IO_PENDING) |
| 10542 | rv = callback.WaitForResult(); |
| 10543 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10544 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10545 | EXPECT_EQ(0, rv); |
| 10546 | // There are still 0 idle sockets, since the trans_compete transaction |
| 10547 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10548 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10549 | |
| 10550 | // The competing request can now finish. Wait for the headers and then |
| 10551 | // read the body. |
| 10552 | rv = callback_compete.WaitForResult(); |
| 10553 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10554 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10555 | if (rv == ERR_IO_PENDING) |
| 10556 | rv = callback.WaitForResult(); |
| 10557 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10558 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 10559 | EXPECT_EQ(0, rv); |
| 10560 | |
| 10561 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10562 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 10563 | } |
| 10564 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10565 | // This tests the case that a request is issued via http instead of spdy after |
| 10566 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10567 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10568 | session_deps_.use_alternate_protocols = true; |
| 10569 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 10570 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10571 | session_deps_.next_protos = next_protos; |
| 10572 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10573 | HttpRequestInfo request; |
| 10574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10575 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10576 | request.load_flags = 0; |
| 10577 | |
| 10578 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10579 | MockWrite( |
| 10580 | "GET / HTTP/1.1\r\n" |
| 10581 | "Host: www.example.org\r\n" |
| 10582 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10583 | }; |
| 10584 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10585 | std::string alternate_protocol_http_header = |
| 10586 | GetAlternateProtocolHttpHeader(); |
| 10587 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10588 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10589 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10590 | MockRead(alternate_protocol_http_header.c_str()), |
| 10591 | MockRead("\r\n"), |
| 10592 | MockRead("hello world"), |
| 10593 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10594 | }; |
| 10595 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10596 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 10597 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10598 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10599 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10600 | |
| 10601 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10602 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10603 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10605 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10606 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10607 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10608 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10611 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10612 | |
| 10613 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10614 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10615 | |
| 10616 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10617 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10618 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10619 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10620 | |
| 10621 | std::string response_data; |
| 10622 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10623 | EXPECT_EQ("hello world", response_data); |
| 10624 | |
| 10625 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10626 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10627 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10628 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10629 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10630 | // Simulate the SSL handshake completing with an NPN negotiation |
| 10631 | // followed by an immediate server closing of the socket. |
| 10632 | // Fix crash: http://crbug.com/46369 |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10633 | session_deps_.use_alternate_protocols = true; |
| 10634 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10635 | |
| 10636 | HttpRequestInfo request; |
| 10637 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10638 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10639 | request.load_flags = 0; |
| 10640 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10641 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10642 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10643 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10644 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10645 | scoped_ptr<SpdyFrame> req( |
| 10646 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10647 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10648 | |
| 10649 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10650 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10651 | }; |
| 10652 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10653 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10654 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10655 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10656 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10657 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10658 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10659 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10660 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10661 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10663 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10664 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10665 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 10666 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 10667 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10668 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 10669 | // it gets it. This is needed since the auth handler may get destroyed |
| 10670 | // before we get a chance to query it. |
| 10671 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 10672 | public: |
| 10673 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 10674 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10675 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10676 | |
| 10677 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10678 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 10679 | const HttpRequestInfo* request, |
| 10680 | const CompletionCallback& callback, |
| 10681 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10682 | *url_ = request->url; |
| 10683 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 10684 | credentials, request, callback, auth_token); |
| 10685 | } |
| 10686 | |
| 10687 | private: |
| 10688 | GURL* url_; |
| 10689 | }; |
| 10690 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10691 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10692 | // This test ensures that the URL passed into the proxy is upgraded |
| 10693 | // to https when doing an Alternate Protocol upgrade. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10694 | session_deps_.use_alternate_protocols = true; |
| 10695 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10696 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10697 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10698 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10699 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10700 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10701 | GURL request_url; |
| 10702 | { |
| 10703 | HttpAuthHandlerMock::Factory* auth_factory = |
| 10704 | new HttpAuthHandlerMock::Factory(); |
| 10705 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 10706 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 10707 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 10708 | auth_factory->set_do_init_from_challenge(true); |
| 10709 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 10710 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10711 | |
| 10712 | HttpRequestInfo request; |
| 10713 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10714 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10715 | request.load_flags = 0; |
| 10716 | |
| 10717 | // First round goes unauthenticated through the proxy. |
| 10718 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10719 | MockWrite( |
| 10720 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10721 | "Host: www.example.org\r\n" |
| 10722 | "Proxy-Connection: keep-alive\r\n" |
| 10723 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10724 | }; |
| 10725 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10726 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 10727 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10728 | MockRead("Alternate-Protocol: 443:"), |
| 10729 | MockRead(GetAlternateProtocolFromParam()), |
| 10730 | MockRead("\r\n"), |
| 10731 | MockRead("Proxy-Connection: close\r\n"), |
| 10732 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10733 | }; |
| 10734 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 10735 | data_writes_1, arraysize(data_writes_1)); |
| 10736 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10737 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10738 | // Alternate-Protocol announcement in the first round. It fails due |
| 10739 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10740 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10741 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 10742 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10743 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 10744 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 10745 | // does a Disconnect and Connect on the same socket, rather than trying |
| 10746 | // to obtain a new one. |
| 10747 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10748 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 10749 | // simply returned another 407 so the unit test could skip the SSL connection |
| 10750 | // establishment and SPDY framing issues. Alas, the |
| 10751 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10752 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10753 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10754 | scoped_ptr<SpdyFrame> req( |
| 10755 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10756 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10757 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10758 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10759 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10760 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10761 | MockWrite(ASYNC, 0, |
| 10762 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10763 | "Host: www.example.org\r\n" |
| 10764 | "Proxy-Connection: keep-alive\r\n" |
| 10765 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10766 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10767 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10768 | MockWrite(ASYNC, 2, |
| 10769 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10770 | "Host: www.example.org\r\n" |
| 10771 | "Proxy-Connection: keep-alive\r\n" |
| 10772 | "Proxy-Authorization: auth_token\r\n" |
| 10773 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10774 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10775 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10776 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10777 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10778 | const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n" |
| 10779 | "Proxy-Authenticate: Mock\r\n" |
| 10780 | "Proxy-Connection: close\r\n" |
| 10781 | "\r\n"); |
| 10782 | const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10783 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10784 | // First connection attempt fails |
| 10785 | MockRead(ASYNC, kRejectConnectResponse, |
| 10786 | arraysize(kRejectConnectResponse) - 1, 1), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10787 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10788 | // Second connection attempt passes |
| 10789 | MockRead(ASYNC, kAcceptConnectResponse, |
| 10790 | arraysize(kAcceptConnectResponse) - 1, 3), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10791 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10792 | // SPDY response |
| 10793 | CreateMockRead(*resp.get(), 5), |
| 10794 | CreateMockRead(*data.get(), 6), |
| 10795 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 10796 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10797 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 10798 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10799 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10800 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10801 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10802 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10803 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10804 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10805 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10806 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10807 | NULL, 0, NULL, 0); |
| 10808 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10809 | never_finishing_connect); |
| 10810 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10811 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 10812 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 10813 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10814 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10815 | &hanging_non_alternate_protocol_socket); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10816 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10817 | |
| 10818 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10819 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10820 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10821 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10822 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10824 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 10825 | |
| 10826 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10827 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10828 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10829 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10830 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10832 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 10833 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10834 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10835 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 10836 | |
| 10837 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10838 | TestCompletionCallback callback_3; |
| 10839 | rv = trans_2->RestartWithAuth( |
| 10840 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10841 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10842 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 10843 | |
| 10844 | // After all that work, these two lines (or actually, just the scheme) are |
| 10845 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10846 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10847 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10848 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10849 | LoadTimingInfo load_timing_info; |
| 10850 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 10851 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10852 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10853 | } |
| 10854 | |
| 10855 | // Test that if we cancel the transaction as the connection is completing, that |
| 10856 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10857 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10858 | // Setup everything about the connection to complete synchronously, so that |
| 10859 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 10860 | // for is the callback from the HttpStreamRequest. |
| 10861 | // Then cancel the transaction. |
| 10862 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10863 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10864 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10865 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 10866 | MockRead(SYNCHRONOUS, "hello world"), |
| 10867 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10868 | }; |
| 10869 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10870 | HttpRequestInfo request; |
| 10871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10872 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10873 | request.load_flags = 0; |
| 10874 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10875 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 10876 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10877 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10878 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10879 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10880 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10881 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10884 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10885 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10886 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10887 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 10888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10889 | trans.reset(); // Cancel the transaction here. |
| 10890 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 10891 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 10892 | } |
| 10893 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10894 | // Test that if a transaction is cancelled after receiving the headers, the |
| 10895 | // stream is drained properly and added back to the socket pool. The main |
| 10896 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 10897 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 10898 | // deleted. |
| 10899 | // See http://crbug.com/368418 |
| 10900 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 10901 | MockRead data_reads[] = { |
| 10902 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 10903 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 10904 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 10905 | MockRead(ASYNC, "1"), |
| 10906 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 10907 | // HttpNetworkTransaction has been deleted. |
| 10908 | MockRead(ASYNC, "2"), |
| 10909 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 10910 | }; |
| 10911 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10912 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10913 | |
| 10914 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10915 | |
| 10916 | { |
| 10917 | HttpRequestInfo request; |
| 10918 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10919 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10920 | request.load_flags = 0; |
| 10921 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10922 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10923 | TestCompletionCallback callback; |
| 10924 | |
| 10925 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10926 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10927 | callback.WaitForResult(); |
| 10928 | |
| 10929 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10930 | ASSERT_TRUE(response != NULL); |
| 10931 | EXPECT_TRUE(response->headers.get() != NULL); |
| 10932 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10933 | |
| 10934 | // The transaction and HttpRequestInfo are deleted. |
| 10935 | } |
| 10936 | |
| 10937 | // Let the HttpResponseBodyDrainer drain the socket. |
| 10938 | base::MessageLoop::current()->RunUntilIdle(); |
| 10939 | |
| 10940 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 10941 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 10942 | } |
| 10943 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10944 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10945 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10946 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10947 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10948 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10949 | session_deps_.net_log = log.bound().net_log(); |
| 10950 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10951 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10952 | HttpRequestInfo request; |
| 10953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10954 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10955 | |
| 10956 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10957 | MockWrite( |
| 10958 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 10959 | "Host: www.example.org\r\n" |
| 10960 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10961 | }; |
| 10962 | |
| 10963 | MockRead data_reads1[] = { |
| 10964 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10965 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10966 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10967 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10968 | }; |
| 10969 | |
| 10970 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10971 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10972 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10974 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10975 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10976 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10978 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 10979 | trans->SetBeforeProxyHeadersSentCallback( |
| 10980 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 10981 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10983 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10984 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10985 | |
| 10986 | rv = callback1.WaitForResult(); |
| 10987 | EXPECT_EQ(OK, rv); |
| 10988 | |
| 10989 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 10990 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 10991 | |
| 10992 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10993 | EXPECT_EQ(200, response->headers->response_code()); |
| 10994 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10995 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 10996 | EXPECT_TRUE( |
| 10997 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 10998 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 10999 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11000 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11001 | |
| 11002 | LoadTimingInfo load_timing_info; |
| 11003 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11004 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11005 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11006 | } |
| 11007 | |
| 11008 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11009 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11010 | session_deps_.proxy_service.reset( |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11011 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11012 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11013 | session_deps_.net_log = log.bound().net_log(); |
| 11014 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11015 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11016 | HttpRequestInfo request; |
| 11017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11018 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11019 | |
| 11020 | // Since we have proxy, should try to establish tunnel. |
| 11021 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11022 | MockWrite( |
| 11023 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11024 | "Host: www.example.org\r\n" |
| 11025 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11026 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11027 | MockWrite( |
| 11028 | "GET / HTTP/1.1\r\n" |
| 11029 | "Host: www.example.org\r\n" |
| 11030 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11031 | }; |
| 11032 | |
| 11033 | MockRead data_reads1[] = { |
| 11034 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11035 | |
| 11036 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11037 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11038 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11039 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11040 | }; |
| 11041 | |
| 11042 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11043 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11044 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11045 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11046 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11048 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11049 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11050 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11051 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11053 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11055 | |
| 11056 | rv = callback1.WaitForResult(); |
| 11057 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11058 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11059 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11060 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11061 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11062 | NetLog::PHASE_NONE); |
| 11063 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11064 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11065 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11066 | NetLog::PHASE_NONE); |
| 11067 | |
| 11068 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11069 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11070 | |
| 11071 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11072 | EXPECT_EQ(200, response->headers->response_code()); |
| 11073 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11074 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11075 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11076 | EXPECT_TRUE( |
| 11077 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11078 | |
| 11079 | LoadTimingInfo load_timing_info; |
| 11080 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11081 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11082 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11083 | } |
| 11084 | |
| 11085 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11086 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11087 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11088 | session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11089 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11090 | session_deps_.net_log = log.bound().net_log(); |
| 11091 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11092 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11093 | HttpRequestInfo request; |
| 11094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11095 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11096 | |
| 11097 | // Since we have proxy, should try to establish tunnel. |
| 11098 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11099 | MockWrite( |
| 11100 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11101 | "Host: www.example.org\r\n" |
| 11102 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11103 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11104 | MockWrite( |
| 11105 | "GET / HTTP/1.1\r\n" |
| 11106 | "Host: www.example.org\r\n" |
| 11107 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11108 | }; |
| 11109 | |
| 11110 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11111 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11112 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11113 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11114 | }; |
| 11115 | |
| 11116 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11117 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11118 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11119 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11122 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11123 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11124 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11127 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11129 | |
| 11130 | rv = callback1.WaitForResult(); |
| 11131 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11132 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11133 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11134 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11135 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11136 | NetLog::PHASE_NONE); |
| 11137 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11138 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11139 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11140 | NetLog::PHASE_NONE); |
| 11141 | } |
| 11142 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11143 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11144 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11145 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11146 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11147 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11148 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11149 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11150 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11151 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11152 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11153 | }; |
| 11154 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11155 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11156 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11157 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11158 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11159 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11160 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11161 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11162 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11163 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11164 | |
| 11165 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11166 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11167 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11168 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11169 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11170 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11171 | |
| 11172 | HttpRequestInfo request; |
| 11173 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11174 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11175 | request.load_flags = 0; |
| 11176 | |
| 11177 | // This is the important line that marks this as a preconnect. |
| 11178 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 11179 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11180 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11182 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11183 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11184 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11185 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11186 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11187 | } |
| 11188 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11189 | // Given a net error, cause that error to be returned from the first Write() |
| 11190 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11191 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11192 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11193 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11194 | request_info.url = GURL("https://www.example.com/"); |
| 11195 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11196 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11197 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11198 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11199 | MockWrite data_writes[] = { |
| 11200 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11201 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11202 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11203 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11205 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11206 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11207 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11208 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11210 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11211 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11212 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11213 | rv = callback.WaitForResult(); |
| 11214 | ASSERT_EQ(error, rv); |
| 11215 | } |
| 11216 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11217 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11218 | // Just check a grab bag of cert errors. |
| 11219 | static const int kErrors[] = { |
| 11220 | ERR_CERT_COMMON_NAME_INVALID, |
| 11221 | ERR_CERT_AUTHORITY_INVALID, |
| 11222 | ERR_CERT_DATE_INVALID, |
| 11223 | }; |
| 11224 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11225 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 11226 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11227 | } |
| 11228 | } |
| 11229 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11230 | // Ensure that a client certificate is removed from the SSL client auth |
| 11231 | // cache when: |
| 11232 | // 1) No proxy is involved. |
| 11233 | // 2) TLS False Start is disabled. |
| 11234 | // 3) The initial TLS handshake requests a client certificate. |
| 11235 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11236 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11237 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11238 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11239 | request_info.url = GURL("https://www.example.com/"); |
| 11240 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11241 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11242 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11243 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11244 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11245 | |
| 11246 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 11247 | // CertificateRequest is received for the first time, the handshake will |
| 11248 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11249 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11250 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11252 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11253 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11254 | |
| 11255 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 11256 | // False Start is not being used, the result of the SSL handshake will be |
| 11257 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 11258 | // matches the result of a server sending a handshake_failure alert, |
| 11259 | // rather than a Finished message, because it requires a client |
| 11260 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11261 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11262 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11264 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11265 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11266 | |
| 11267 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 11268 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11269 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 11270 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11271 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11272 | // requiring a client certificate, this fallback handshake should also |
| 11273 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11274 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11275 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11277 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11278 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11279 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11280 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 11281 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 11282 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 11283 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11284 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 11285 | // requiring a client certificate, this fallback handshake should also |
| 11286 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11287 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11288 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11290 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11291 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11292 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11293 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11294 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11295 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11296 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11297 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11298 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11299 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11300 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11301 | |
| 11302 | // Complete the SSL handshake, which should abort due to requiring a |
| 11303 | // client certificate. |
| 11304 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11305 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11306 | |
| 11307 | // Indicate that no certificate should be supplied. From the perspective |
| 11308 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11309 | // certificate, so this is the same as supply a |
| 11310 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11311 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11312 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11313 | |
| 11314 | // Ensure the certificate was added to the client auth cache before |
| 11315 | // allowing the connection to continue restarting. |
| 11316 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11317 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11318 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11319 | ASSERT_EQ(NULL, client_cert.get()); |
| 11320 | |
| 11321 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11322 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11323 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11324 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11325 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11326 | |
| 11327 | // Ensure that the client certificate is removed from the cache on a |
| 11328 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11329 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11330 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11331 | } |
| 11332 | |
| 11333 | // Ensure that a client certificate is removed from the SSL client auth |
| 11334 | // cache when: |
| 11335 | // 1) No proxy is involved. |
| 11336 | // 2) TLS False Start is enabled. |
| 11337 | // 3) The initial TLS handshake requests a client certificate. |
| 11338 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11339 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11340 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11341 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11342 | request_info.url = GURL("https://www.example.com/"); |
| 11343 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11344 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11345 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11346 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11347 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11348 | |
| 11349 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 11350 | // return successfully after reading up to the peer's Certificate message. |
| 11351 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 11352 | // enqueue application data to be sent in the same packet as the |
| 11353 | // ChangeCipherSpec and Finished messages. |
| 11354 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 11355 | // called, which expects to process the peer's ChangeCipherSpec and |
| 11356 | // Finished messages. If there was an error negotiating with the peer, |
| 11357 | // such as due to the peer requiring a client certificate when none was |
| 11358 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 11359 | // called. |
| 11360 | |
| 11361 | // Like the non-False Start case, when a client certificate is requested by |
| 11362 | // the peer, the handshake is aborted during the Connect() call. |
| 11363 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11364 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11365 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11367 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11368 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11369 | |
| 11370 | // When a client certificate is supplied, Connect() will not be aborted |
| 11371 | // when the peer requests the certificate. Instead, the handshake will |
| 11372 | // artificially succeed, allowing the caller to write the HTTP request to |
| 11373 | // the socket. The handshake messages are not processed until Read() is |
| 11374 | // called, which then detects that the handshake was aborted, due to the |
| 11375 | // peer sending a handshake_failure because it requires a client |
| 11376 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11377 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11378 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11380 | MockRead data2_reads[] = { |
| 11381 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11382 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11383 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11384 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11385 | |
| 11386 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11387 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 11388 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11389 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11390 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11392 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11393 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11394 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11395 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 11396 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11397 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11398 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11400 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11401 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11402 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11403 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11404 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11405 | ssl_data5.cert_request_info = cert_request.get(); |
| 11406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11407 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 11408 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 11409 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11410 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11411 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11412 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11413 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11414 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11415 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11416 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11417 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11418 | |
| 11419 | // Complete the SSL handshake, which should abort due to requiring a |
| 11420 | // client certificate. |
| 11421 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11422 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11423 | |
| 11424 | // Indicate that no certificate should be supplied. From the perspective |
| 11425 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11426 | // certificate, so this is the same as supply a |
| 11427 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11428 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11429 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11430 | |
| 11431 | // Ensure the certificate was added to the client auth cache before |
| 11432 | // allowing the connection to continue restarting. |
| 11433 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11434 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11435 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11436 | ASSERT_EQ(NULL, client_cert.get()); |
| 11437 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11438 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11439 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 11440 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11441 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11442 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11443 | |
| 11444 | // Ensure that the client certificate is removed from the cache on a |
| 11445 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11446 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11447 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 11448 | } |
| 11449 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11450 | // Ensure that a client certificate is removed from the SSL client auth |
| 11451 | // cache when: |
| 11452 | // 1) An HTTPS proxy is involved. |
| 11453 | // 3) The HTTPS proxy requests a client certificate. |
| 11454 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 11455 | // proxy. |
| 11456 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 11457 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11458 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11459 | session_deps_.proxy_service.reset( |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11460 | ProxyService::CreateFixed("https://proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11461 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11462 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11463 | |
| 11464 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11465 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11466 | |
| 11467 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 11468 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 11469 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 11470 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11471 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11472 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11474 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11475 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11476 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11477 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11478 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11479 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11480 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11481 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11482 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11483 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 11484 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11485 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11486 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11488 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11489 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 11490 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11491 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11492 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11493 | requests[0].url = GURL("https://www.example.com/"); |
| 11494 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11495 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11496 | |
| 11497 | requests[1].url = GURL("http://www.example.com/"); |
| 11498 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11499 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11500 | |
| 11501 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11502 | session_deps_.socket_factory->ResetNextMockIndexes(); |
| 11503 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11504 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11505 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11506 | |
| 11507 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11508 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11509 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 11510 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11511 | |
| 11512 | // Complete the SSL handshake, which should abort due to requiring a |
| 11513 | // client certificate. |
| 11514 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11515 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11516 | |
| 11517 | // Indicate that no certificate should be supplied. From the perspective |
| 11518 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 11519 | // certificate, so this is the same as supply a |
| 11520 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11521 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11522 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11523 | |
| 11524 | // Ensure the certificate was added to the client auth cache before |
| 11525 | // allowing the connection to continue restarting. |
| 11526 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11527 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 11528 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11529 | ASSERT_EQ(NULL, client_cert.get()); |
| 11530 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 11531 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11532 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11533 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11534 | |
| 11535 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 11536 | // then consume ssl_data3, which should also fail. The result code is |
| 11537 | // checked against what ssl_data3 should return. |
| 11538 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11539 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11540 | |
| 11541 | // Now that the new handshake has failed, ensure that the client |
| 11542 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 11543 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11544 | HostPortPair("proxy", 70), &client_cert)); |
| 11545 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 11546 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 11547 | } |
| 11548 | } |
| 11549 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11550 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11551 | session_deps_.use_alternate_protocols = true; |
| 11552 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11553 | |
| 11554 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11555 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11556 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11557 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11558 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11559 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11560 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11561 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11563 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11564 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11565 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11566 | scoped_ptr<SpdyFrame> host2_req( |
| 11567 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11568 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11569 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11570 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11571 | scoped_ptr<SpdyFrame> host1_resp( |
| 11572 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11573 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11574 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11575 | scoped_ptr<SpdyFrame> host2_resp( |
| 11576 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11577 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11578 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11579 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11580 | CreateMockRead(*host1_resp, 1), |
| 11581 | CreateMockRead(*host1_resp_body, 2), |
| 11582 | CreateMockRead(*host2_resp, 4), |
| 11583 | CreateMockRead(*host2_resp_body, 5), |
| 11584 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11585 | }; |
| 11586 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11587 | IPAddressNumber ip; |
| 11588 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11589 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11590 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11591 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11592 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11593 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11594 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11595 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11596 | HttpRequestInfo request1; |
| 11597 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11598 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11599 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11600 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11601 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11602 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11603 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11604 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11605 | |
| 11606 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11607 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11608 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11609 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11610 | |
| 11611 | std::string response_data; |
| 11612 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11613 | EXPECT_EQ("hello!", response_data); |
| 11614 | |
| 11615 | // Preload www.gmail.com into HostCache. |
| 11616 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11617 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11618 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11619 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 11620 | DEFAULT_PRIORITY, |
| 11621 | &ignored, |
| 11622 | callback.callback(), |
| 11623 | NULL, |
| 11624 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11625 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11626 | rv = callback.WaitForResult(); |
| 11627 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11628 | |
| 11629 | HttpRequestInfo request2; |
| 11630 | request2.method = "GET"; |
| 11631 | request2.url = GURL("https://www.gmail.com/"); |
| 11632 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11633 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11635 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11636 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11637 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11638 | |
| 11639 | response = trans2.GetResponseInfo(); |
| 11640 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11641 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11642 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11643 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11644 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11645 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11646 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11647 | } |
| 11648 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11649 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11650 | session_deps_.use_alternate_protocols = true; |
| 11651 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11652 | |
| 11653 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11654 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
| 11655 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11656 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11657 | pool_peer.DisableDomainAuthenticationVerification(); |
| 11658 | |
| 11659 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11660 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11662 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11663 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11664 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11665 | scoped_ptr<SpdyFrame> host2_req( |
| 11666 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11667 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11668 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11669 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11670 | scoped_ptr<SpdyFrame> host1_resp( |
| 11671 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11672 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11673 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11674 | scoped_ptr<SpdyFrame> host2_resp( |
| 11675 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11676 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11677 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11678 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11679 | CreateMockRead(*host1_resp, 1), |
| 11680 | CreateMockRead(*host1_resp_body, 2), |
| 11681 | CreateMockRead(*host2_resp, 4), |
| 11682 | CreateMockRead(*host2_resp_body, 5), |
| 11683 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11684 | }; |
| 11685 | |
| 11686 | IPAddressNumber ip; |
| 11687 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11688 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11689 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11690 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11691 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11692 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11693 | |
| 11694 | TestCompletionCallback callback; |
| 11695 | HttpRequestInfo request1; |
| 11696 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11697 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11698 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11699 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11700 | |
| 11701 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 11702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11703 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11704 | |
| 11705 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11706 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11707 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11708 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11709 | |
| 11710 | std::string response_data; |
| 11711 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11712 | EXPECT_EQ("hello!", response_data); |
| 11713 | |
| 11714 | HttpRequestInfo request2; |
| 11715 | request2.method = "GET"; |
| 11716 | request2.url = GURL("https://www.gmail.com/"); |
| 11717 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11718 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11719 | |
| 11720 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 11721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11722 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11723 | |
| 11724 | response = trans2.GetResponseInfo(); |
| 11725 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11726 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11727 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11728 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11729 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11730 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11731 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11732 | } |
| 11733 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11734 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11735 | public: |
| 11736 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 11737 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11738 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11739 | |
| 11740 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 11741 | |
| 11742 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11743 | int Resolve(const RequestInfo& info, |
| 11744 | RequestPriority priority, |
| 11745 | AddressList* addresses, |
| 11746 | const CompletionCallback& callback, |
| 11747 | RequestHandle* out_req, |
| 11748 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11749 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11750 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11751 | } |
| 11752 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11753 | int ResolveFromCache(const RequestInfo& info, |
| 11754 | AddressList* addresses, |
| 11755 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 11756 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 11757 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 11758 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11759 | return rv; |
| 11760 | } |
| 11761 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11762 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11763 | host_resolver_.CancelRequest(req); |
| 11764 | } |
| 11765 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 11766 | MockCachingHostResolver* GetMockHostResolver() { |
| 11767 | return &host_resolver_; |
| 11768 | } |
| 11769 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11770 | private: |
| 11771 | MockCachingHostResolver host_resolver_; |
| 11772 | const HostPortPair host_port_; |
| 11773 | }; |
| 11774 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 11775 | TEST_P(HttpNetworkTransactionTest, |
| 11776 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11777 | session_deps_.use_alternate_protocols = true; |
| 11778 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11779 | |
| 11780 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11781 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 11782 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11783 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11784 | params.host_resolver = &host_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11785 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 11786 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 11787 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11788 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11789 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11790 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11792 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11793 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11794 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11795 | scoped_ptr<SpdyFrame> host2_req( |
| 11796 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11797 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11798 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11799 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11800 | scoped_ptr<SpdyFrame> host1_resp( |
| 11801 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11802 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 11803 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11804 | scoped_ptr<SpdyFrame> host2_resp( |
| 11805 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 11806 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 11807 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11808 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11809 | CreateMockRead(*host1_resp, 1), |
| 11810 | CreateMockRead(*host1_resp_body, 2), |
| 11811 | CreateMockRead(*host2_resp, 4), |
| 11812 | CreateMockRead(*host2_resp_body, 5), |
| 11813 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11814 | }; |
| 11815 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 11816 | IPAddressNumber ip; |
| 11817 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 11818 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 11819 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11820 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 11821 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11822 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11823 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11824 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11825 | HttpRequestInfo request1; |
| 11826 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11827 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11828 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11829 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11831 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11832 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11833 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11834 | |
| 11835 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 11836 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11837 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11838 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11839 | |
| 11840 | std::string response_data; |
| 11841 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 11842 | EXPECT_EQ("hello!", response_data); |
| 11843 | |
| 11844 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11845 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11846 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 11847 | rv = host_resolver.Resolve(resolve_info, |
| 11848 | DEFAULT_PRIORITY, |
| 11849 | &ignored, |
| 11850 | callback.callback(), |
| 11851 | NULL, |
| 11852 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11854 | rv = callback.WaitForResult(); |
| 11855 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11856 | |
| 11857 | HttpRequestInfo request2; |
| 11858 | request2.method = "GET"; |
| 11859 | request2.url = GURL("https://www.gmail.com/"); |
| 11860 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11861 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11863 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11864 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11865 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11866 | |
| 11867 | response = trans2.GetResponseInfo(); |
| 11868 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11869 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11870 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11871 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11872 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11873 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 11874 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 11875 | } |
| 11876 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11877 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11878 | const std::string https_url = "https://www.example.org:8080/"; |
| 11879 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11880 | |
| 11881 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11882 | scoped_ptr<SpdyFrame> req1( |
| 11883 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11884 | |
| 11885 | MockWrite writes1[] = { |
| 11886 | CreateMockWrite(*req1, 0), |
| 11887 | }; |
| 11888 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11889 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11890 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11891 | MockRead reads1[] = { |
| 11892 | CreateMockRead(*resp1, 1), |
| 11893 | CreateMockRead(*body1, 2), |
| 11894 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 11895 | }; |
| 11896 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11897 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 11898 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11899 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 11900 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11901 | |
| 11902 | // HTTP GET for the HTTP URL |
| 11903 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11904 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11905 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11906 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 11907 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11908 | }; |
| 11909 | |
| 11910 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11911 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 11912 | MockRead(ASYNC, 2, "hello"), |
| 11913 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11914 | }; |
| 11915 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11916 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 11917 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11918 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11919 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11920 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11921 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11922 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11923 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11924 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11925 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11926 | |
| 11927 | // Start the first transaction to set up the SpdySession |
| 11928 | HttpRequestInfo request1; |
| 11929 | request1.method = "GET"; |
| 11930 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11931 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11932 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11933 | TestCompletionCallback callback1; |
| 11934 | EXPECT_EQ(ERR_IO_PENDING, |
| 11935 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11936 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11937 | |
| 11938 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 11939 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 11940 | |
| 11941 | // Now, start the HTTP request |
| 11942 | HttpRequestInfo request2; |
| 11943 | request2.method = "GET"; |
| 11944 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11945 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11946 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11947 | TestCompletionCallback callback2; |
| 11948 | EXPECT_EQ(ERR_IO_PENDING, |
| 11949 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11950 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 11951 | |
| 11952 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11953 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11954 | } |
| 11955 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 11956 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 11957 | public: |
| 11958 | void Run(bool pooling, bool valid) { |
| 11959 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 11960 | 443); |
| 11961 | HostPortPair alternative("www.example.org", 443); |
| 11962 | |
| 11963 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 11964 | scoped_refptr<X509Certificate> cert( |
| 11965 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 11966 | ASSERT_TRUE(cert.get()); |
| 11967 | bool common_name_fallback_used; |
| 11968 | EXPECT_EQ(valid, |
| 11969 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 11970 | EXPECT_TRUE( |
| 11971 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 11972 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11973 | ssl.SetNextProto(GetParam()); |
| 11974 | ssl.cert = cert; |
| 11975 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11976 | |
| 11977 | // If pooling, then start a request to alternative first to create a |
| 11978 | // SpdySession. |
| 11979 | std::string url0 = "https://www.example.org:443"; |
| 11980 | // Second request to origin, which has an alternative service, and could |
| 11981 | // open a connection to the alternative host or pool to the existing one. |
| 11982 | std::string url1("https://"); |
| 11983 | url1.append(origin.host()); |
| 11984 | url1.append(":443"); |
| 11985 | |
| 11986 | scoped_ptr<SpdyFrame> req0; |
| 11987 | scoped_ptr<SpdyFrame> req1; |
| 11988 | scoped_ptr<SpdyFrame> resp0; |
| 11989 | scoped_ptr<SpdyFrame> body0; |
| 11990 | scoped_ptr<SpdyFrame> resp1; |
| 11991 | scoped_ptr<SpdyFrame> body1; |
| 11992 | std::vector<MockWrite> writes; |
| 11993 | std::vector<MockRead> reads; |
| 11994 | |
| 11995 | if (pooling) { |
| 11996 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 11997 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 11998 | |
| 11999 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12000 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12001 | |
| 12002 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12003 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12004 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12005 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12006 | |
| 12007 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12008 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12009 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12010 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12011 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12012 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12013 | } else { |
| 12014 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12015 | |
| 12016 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12017 | |
| 12018 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12019 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12020 | |
| 12021 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12022 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12023 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12024 | } |
| 12025 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12026 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12027 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12029 | |
| 12030 | // Connection to the origin fails. |
| 12031 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12032 | StaticSocketDataProvider data_refused; |
| 12033 | data_refused.set_connect_data(mock_connect); |
| 12034 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12035 | |
| 12036 | session_deps_.use_alternate_protocols = true; |
| 12037 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12038 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12039 | session->http_server_properties(); |
| 12040 | AlternativeService alternative_service( |
| 12041 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12042 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12043 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12044 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12045 | |
| 12046 | // First request to alternative. |
| 12047 | if (pooling) { |
| 12048 | scoped_ptr<HttpTransaction> trans0( |
| 12049 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12050 | HttpRequestInfo request0; |
| 12051 | request0.method = "GET"; |
| 12052 | request0.url = GURL(url0); |
| 12053 | request0.load_flags = 0; |
| 12054 | TestCompletionCallback callback0; |
| 12055 | |
| 12056 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12058 | rv = callback0.WaitForResult(); |
| 12059 | EXPECT_EQ(OK, rv); |
| 12060 | } |
| 12061 | |
| 12062 | // Second request to origin. |
| 12063 | scoped_ptr<HttpTransaction> trans1( |
| 12064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12065 | HttpRequestInfo request1; |
| 12066 | request1.method = "GET"; |
| 12067 | request1.url = GURL(url1); |
| 12068 | request1.load_flags = 0; |
| 12069 | TestCompletionCallback callback1; |
| 12070 | |
| 12071 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12072 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12073 | base::MessageLoop::current()->RunUntilIdle(); |
| 12074 | if (data.IsReadPaused()) { |
| 12075 | data.CompleteRead(); |
| 12076 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12077 | rv = callback1.WaitForResult(); |
| 12078 | if (valid) { |
| 12079 | EXPECT_EQ(OK, rv); |
| 12080 | } else { |
| 12081 | if (pooling) { |
| 12082 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12083 | } else { |
| 12084 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12085 | } |
| 12086 | } |
| 12087 | } |
| 12088 | }; |
| 12089 | |
| 12090 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12091 | AltSvcCertificateVerificationTest, |
| 12092 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12093 | kProtoHTTP2_14, |
| 12094 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12095 | |
| 12096 | // The alternative service host must exhibit a certificate that is valid for the |
| 12097 | // origin host. Test that this is enforced when pooling to an existing |
| 12098 | // connection. |
| 12099 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12100 | Run(true, true); |
| 12101 | } |
| 12102 | |
| 12103 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12104 | Run(true, false); |
| 12105 | } |
| 12106 | |
| 12107 | // The alternative service host must exhibit a certificate that is valid for the |
| 12108 | // origin host. Test that this is enforced when opening a new connection. |
| 12109 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12110 | Run(false, true); |
| 12111 | } |
| 12112 | |
| 12113 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12114 | Run(false, false); |
| 12115 | } |
| 12116 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12117 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12118 | // with the alternative server. That connection should not be used. |
| 12119 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12120 | HostPortPair origin("origin.example.org", 443); |
| 12121 | HostPortPair alternative("alternative.example.org", 443); |
| 12122 | |
| 12123 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12124 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12125 | ssl.SetNextProto(kProtoHTTP11); |
| 12126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12127 | |
| 12128 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12129 | // negotiated. |
| 12130 | StaticSocketDataProvider data; |
| 12131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12132 | |
| 12133 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12134 | // negotiated. In order to test this, a failed connection to the origin is |
| 12135 | // mocked. This way the request relies on the alternate Job. |
| 12136 | StaticSocketDataProvider data_refused; |
| 12137 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12138 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12139 | |
| 12140 | // Set up alternative service for origin. |
| 12141 | session_deps_.use_alternate_protocols = true; |
| 12142 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12143 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12144 | session->http_server_properties(); |
| 12145 | AlternativeService alternative_service( |
| 12146 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12147 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12148 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12149 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12150 | |
| 12151 | scoped_ptr<HttpTransaction> trans( |
| 12152 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12153 | HttpRequestInfo request; |
| 12154 | request.method = "GET"; |
| 12155 | request.url = GURL("https://origin.example.org:443"); |
| 12156 | request.load_flags = 0; |
| 12157 | TestCompletionCallback callback; |
| 12158 | |
| 12159 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12160 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12161 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12162 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12163 | } |
| 12164 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12165 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12166 | // origin, and an alternate one to the alternative server. If the former |
| 12167 | // succeeds, the request should succeed, even if the latter fails because |
| 12168 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 12169 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 12170 | HostPortPair origin("origin.example.org", 443); |
| 12171 | HostPortPair alternative("alternative.example.org", 443); |
| 12172 | |
| 12173 | // Negotiate HTTP/1.1 with alternative. |
| 12174 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 12175 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 12176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 12177 | |
| 12178 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12179 | // negotiated. |
| 12180 | StaticSocketDataProvider data; |
| 12181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12182 | |
| 12183 | // Negotiate HTTP/1.1 with origin. |
| 12184 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12185 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12187 | |
| 12188 | MockWrite http_writes[] = { |
| 12189 | MockWrite( |
| 12190 | "GET / HTTP/1.1\r\n" |
| 12191 | "Host: origin.example.org\r\n" |
| 12192 | "Connection: keep-alive\r\n\r\n"), |
| 12193 | MockWrite( |
| 12194 | "GET /second HTTP/1.1\r\n" |
| 12195 | "Host: origin.example.org\r\n" |
| 12196 | "Connection: keep-alive\r\n\r\n"), |
| 12197 | }; |
| 12198 | |
| 12199 | MockRead http_reads[] = { |
| 12200 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12201 | MockRead("Content-Type: text/html\r\n"), |
| 12202 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12203 | MockRead("foobar"), |
| 12204 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12205 | MockRead("Content-Type: text/html\r\n"), |
| 12206 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12207 | MockRead("another"), |
| 12208 | }; |
| 12209 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12210 | http_writes, arraysize(http_writes)); |
| 12211 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12212 | |
| 12213 | // Set up alternative service for origin. |
| 12214 | session_deps_.use_alternate_protocols = true; |
| 12215 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12216 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12217 | session->http_server_properties(); |
| 12218 | AlternativeService alternative_service( |
| 12219 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12220 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12221 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12222 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12223 | |
| 12224 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 12225 | HttpRequestInfo request1; |
| 12226 | request1.method = "GET"; |
| 12227 | request1.url = GURL("https://origin.example.org:443"); |
| 12228 | request1.load_flags = 0; |
| 12229 | TestCompletionCallback callback1; |
| 12230 | |
| 12231 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 12232 | rv = callback1.GetResult(rv); |
| 12233 | EXPECT_EQ(OK, rv); |
| 12234 | |
| 12235 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 12236 | ASSERT_TRUE(response1 != nullptr); |
| 12237 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 12238 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12239 | |
| 12240 | std::string response_data1; |
| 12241 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 12242 | EXPECT_EQ("foobar", response_data1); |
| 12243 | |
| 12244 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 12245 | // for alternative service. |
| 12246 | EXPECT_TRUE( |
| 12247 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 12248 | |
| 12249 | // Since |alternative_service| is broken, a second transaction to origin |
| 12250 | // should not start an alternate Job. It should pool to existing connection |
| 12251 | // to origin. |
| 12252 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 12253 | HttpRequestInfo request2; |
| 12254 | request2.method = "GET"; |
| 12255 | request2.url = GURL("https://origin.example.org:443/second"); |
| 12256 | request2.load_flags = 0; |
| 12257 | TestCompletionCallback callback2; |
| 12258 | |
| 12259 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 12260 | rv = callback2.GetResult(rv); |
| 12261 | EXPECT_EQ(OK, rv); |
| 12262 | |
| 12263 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 12264 | ASSERT_TRUE(response2 != nullptr); |
| 12265 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 12266 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 12267 | |
| 12268 | std::string response_data2; |
| 12269 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 12270 | EXPECT_EQ("another", response_data2); |
| 12271 | } |
| 12272 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12273 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 12274 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 12275 | // used. |
| 12276 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 12277 | HostPortPair origin("origin.example.org", 443); |
| 12278 | HostPortPair alternative("alternative.example.org", 443); |
| 12279 | std::string origin_url = "https://origin.example.org:443"; |
| 12280 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12281 | |
| 12282 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12283 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12284 | ssl.SetNextProto(kProtoHTTP11); |
| 12285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12286 | |
| 12287 | // HTTP/1.1 data for |request1| and |request2|. |
| 12288 | MockWrite http_writes[] = { |
| 12289 | MockWrite( |
| 12290 | "GET / HTTP/1.1\r\n" |
| 12291 | "Host: alternative.example.org\r\n" |
| 12292 | "Connection: keep-alive\r\n\r\n"), |
| 12293 | MockWrite( |
| 12294 | "GET / HTTP/1.1\r\n" |
| 12295 | "Host: alternative.example.org\r\n" |
| 12296 | "Connection: keep-alive\r\n\r\n"), |
| 12297 | }; |
| 12298 | |
| 12299 | MockRead http_reads[] = { |
| 12300 | MockRead( |
| 12301 | "HTTP/1.1 200 OK\r\n" |
| 12302 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12303 | "Content-Length: 40\r\n\r\n" |
| 12304 | "first HTTP/1.1 response from alternative"), |
| 12305 | MockRead( |
| 12306 | "HTTP/1.1 200 OK\r\n" |
| 12307 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12308 | "Content-Length: 41\r\n\r\n" |
| 12309 | "second HTTP/1.1 response from alternative"), |
| 12310 | }; |
| 12311 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12312 | http_writes, arraysize(http_writes)); |
| 12313 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12314 | |
| 12315 | // This test documents that an alternate Job should not pool to an already |
| 12316 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 12317 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 12318 | StaticSocketDataProvider data_refused; |
| 12319 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12320 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12321 | |
| 12322 | // Set up alternative service for origin. |
| 12323 | session_deps_.use_alternate_protocols = true; |
| 12324 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12325 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12326 | session->http_server_properties(); |
| 12327 | AlternativeService alternative_service( |
| 12328 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12329 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12330 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12331 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12332 | |
| 12333 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 12334 | scoped_ptr<HttpTransaction> trans1( |
| 12335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12336 | HttpRequestInfo request1; |
| 12337 | request1.method = "GET"; |
| 12338 | request1.url = GURL(alternative_url); |
| 12339 | request1.load_flags = 0; |
| 12340 | TestCompletionCallback callback1; |
| 12341 | |
| 12342 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12343 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 12344 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 12345 | ASSERT_TRUE(response1); |
| 12346 | ASSERT_TRUE(response1->headers.get()); |
| 12347 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 12348 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 12349 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 12350 | std::string response_data1; |
| 12351 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 12352 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 12353 | |
| 12354 | // Request for origin.example.org, which has an alternative service. This |
| 12355 | // will start two Jobs: the alternative looks for connections to pool to, |
| 12356 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 12357 | // open other connections to alternative server. The Job to origin fails, so |
| 12358 | // this request fails. |
| 12359 | scoped_ptr<HttpTransaction> trans2( |
| 12360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12361 | HttpRequestInfo request2; |
| 12362 | request2.method = "GET"; |
| 12363 | request2.url = GURL(origin_url); |
| 12364 | request2.load_flags = 0; |
| 12365 | TestCompletionCallback callback2; |
| 12366 | |
| 12367 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 12368 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 12369 | |
| 12370 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 12371 | // socket is still open and in the pool. |
| 12372 | scoped_ptr<HttpTransaction> trans3( |
| 12373 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12374 | HttpRequestInfo request3; |
| 12375 | request3.method = "GET"; |
| 12376 | request3.url = GURL(alternative_url); |
| 12377 | request3.load_flags = 0; |
| 12378 | TestCompletionCallback callback3; |
| 12379 | |
| 12380 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 12381 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 12382 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 12383 | ASSERT_TRUE(response3); |
| 12384 | ASSERT_TRUE(response3->headers.get()); |
| 12385 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 12386 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 12387 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 12388 | std::string response_data3; |
| 12389 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 12390 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 12391 | } |
| 12392 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12393 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12394 | const std::string https_url = "https://www.example.org:8080/"; |
| 12395 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12396 | |
| 12397 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12398 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12399 | scoped_ptr<SpdyFrame> connect( |
| 12400 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12401 | scoped_ptr<SpdyFrame> req1( |
| 12402 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12403 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 12404 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12405 | |
| 12406 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12407 | SpdyHeaderBlock req2_block; |
| 12408 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 12409 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12410 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12411 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 12412 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 12413 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12414 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12415 | |
| 12416 | MockWrite writes1[] = { |
| 12417 | CreateMockWrite(*connect, 0), |
| 12418 | CreateMockWrite(*wrapped_req1, 2), |
| 12419 | CreateMockWrite(*req2, 5), |
| 12420 | }; |
| 12421 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12422 | scoped_ptr<SpdyFrame> conn_resp( |
| 12423 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12424 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12425 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12426 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 12427 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 12428 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 12429 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 12430 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12431 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12432 | MockRead reads1[] = { |
| 12433 | CreateMockRead(*conn_resp, 1), |
| 12434 | CreateMockRead(*wrapped_resp1, 3), |
| 12435 | CreateMockRead(*wrapped_body1, 4), |
| 12436 | CreateMockRead(*resp2, 6), |
| 12437 | CreateMockRead(*body2, 7), |
| 12438 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 12439 | }; |
| 12440 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12441 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 12442 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12443 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12444 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12445 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12446 | session_deps_.proxy_service.reset( |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12447 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70")); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12448 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12449 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12450 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12451 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12452 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12453 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12454 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12455 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12456 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12457 | |
| 12458 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12459 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12460 | |
| 12461 | // Start the first transaction to set up the SpdySession |
| 12462 | HttpRequestInfo request1; |
| 12463 | request1.method = "GET"; |
| 12464 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12465 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12466 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12467 | TestCompletionCallback callback1; |
| 12468 | EXPECT_EQ(ERR_IO_PENDING, |
| 12469 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12470 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12471 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12472 | |
| 12473 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12474 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12475 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12476 | LoadTimingInfo load_timing_info1; |
| 12477 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 12478 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 12479 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12480 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12481 | // Now, start the HTTP request |
| 12482 | HttpRequestInfo request2; |
| 12483 | request2.method = "GET"; |
| 12484 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12485 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12486 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12487 | TestCompletionCallback callback2; |
| 12488 | EXPECT_EQ(ERR_IO_PENDING, |
| 12489 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12490 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12491 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12492 | |
| 12493 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12494 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 12495 | |
| 12496 | LoadTimingInfo load_timing_info2; |
| 12497 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 12498 | // The established SPDY sessions is considered reused by the HTTP request. |
| 12499 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 12500 | // HTTP requests over a SPDY session should have a different connection |
| 12501 | // socket_log_id than requests over a tunnel. |
| 12502 | 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] | 12503 | } |
| 12504 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12505 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 12506 | // that we do not pool other origins that resolve to the same IP when |
| 12507 | // the certificate does not match the new origin. |
| 12508 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12509 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12510 | const std::string url1 = "http://www.example.org/"; |
| 12511 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12512 | const std::string ip_addr = "1.2.3.4"; |
| 12513 | |
| 12514 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12515 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12516 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 12517 | scoped_ptr<SpdyFrame> req1( |
| 12518 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12519 | |
| 12520 | MockWrite writes1[] = { |
| 12521 | CreateMockWrite(*req1, 0), |
| 12522 | }; |
| 12523 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12524 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12525 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12526 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12527 | CreateMockRead(*resp1, 1), |
| 12528 | CreateMockRead(*body1, 2), |
| 12529 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12530 | }; |
| 12531 | |
| 12532 | scoped_ptr<DeterministicSocketData> data1( |
| 12533 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 12534 | writes1, arraysize(writes1))); |
| 12535 | IPAddressNumber ip; |
| 12536 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 12537 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12538 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 12539 | data1->set_connect_data(connect_data1); |
| 12540 | |
| 12541 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12542 | scoped_ptr<SpdyFrame> req2( |
| 12543 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12544 | |
| 12545 | MockWrite writes2[] = { |
| 12546 | CreateMockWrite(*req2, 0), |
| 12547 | }; |
| 12548 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12549 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12550 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12551 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 12552 | CreateMockRead(*resp2, 1), |
| 12553 | CreateMockRead(*body2, 2), |
| 12554 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12555 | }; |
| 12556 | |
| 12557 | scoped_ptr<DeterministicSocketData> data2( |
| 12558 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 12559 | writes2, arraysize(writes2))); |
| 12560 | MockConnect connect_data2(ASYNC, OK); |
| 12561 | data2->set_connect_data(connect_data2); |
| 12562 | |
| 12563 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 12564 | // all others direct. |
| 12565 | ProxyConfig proxy_config; |
| 12566 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12567 | session_deps_.proxy_service.reset(new ProxyService( |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12568 | new ProxyConfigServiceFixed(proxy_config), nullptr, NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12569 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12570 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 12571 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12572 | // Load a valid cert. Note, that this does not need to |
| 12573 | // be valid for proxy because the MockSSLClientSocket does |
| 12574 | // not actually verify it. But SpdySession will use this |
| 12575 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12576 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 12577 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12578 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12579 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12580 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12581 | |
| 12582 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12583 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12584 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12585 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 12586 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12587 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12588 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12589 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12590 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12591 | |
| 12592 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12593 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12594 | |
| 12595 | // Start the first transaction to set up the SpdySession |
| 12596 | HttpRequestInfo request1; |
| 12597 | request1.method = "GET"; |
| 12598 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12599 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12600 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12601 | TestCompletionCallback callback1; |
| 12602 | ASSERT_EQ(ERR_IO_PENDING, |
| 12603 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 12604 | data1->RunFor(3); |
| 12605 | |
| 12606 | ASSERT_TRUE(callback1.have_result()); |
| 12607 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12608 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12609 | |
| 12610 | // Now, start the HTTP request |
| 12611 | HttpRequestInfo request2; |
| 12612 | request2.method = "GET"; |
| 12613 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12614 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12615 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12616 | TestCompletionCallback callback2; |
| 12617 | EXPECT_EQ(ERR_IO_PENDING, |
| 12618 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12619 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 12620 | data2->RunFor(3); |
| 12621 | |
| 12622 | ASSERT_TRUE(callback2.have_result()); |
| 12623 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12624 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12625 | } |
| 12626 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12627 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 12628 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 12629 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 12630 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12631 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12632 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12633 | |
| 12634 | MockRead reads1[] = { |
| 12635 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 12636 | }; |
| 12637 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12638 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12639 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12640 | scoped_ptr<SpdyFrame> req2( |
| 12641 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12642 | MockWrite writes2[] = { |
| 12643 | CreateMockWrite(*req2, 0), |
| 12644 | }; |
| 12645 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12646 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12647 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12648 | MockRead reads2[] = { |
| 12649 | CreateMockRead(*resp2, 1), |
| 12650 | CreateMockRead(*body2, 2), |
| 12651 | MockRead(ASYNC, OK, 3) // EOF |
| 12652 | }; |
| 12653 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12654 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12655 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12656 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12657 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12658 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12660 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12661 | |
| 12662 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12663 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12665 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12666 | |
| 12667 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12668 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12669 | |
| 12670 | // Start the first transaction to set up the SpdySession and verify that |
| 12671 | // connection was closed. |
| 12672 | HttpRequestInfo request1; |
| 12673 | request1.method = "GET"; |
| 12674 | request1.url = GURL(https_url); |
| 12675 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12676 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12677 | TestCompletionCallback callback1; |
| 12678 | EXPECT_EQ(ERR_IO_PENDING, |
| 12679 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12680 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 12681 | |
| 12682 | // Now, start the second request and make sure it succeeds. |
| 12683 | HttpRequestInfo request2; |
| 12684 | request2.method = "GET"; |
| 12685 | request2.url = GURL(https_url); |
| 12686 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12687 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12688 | TestCompletionCallback callback2; |
| 12689 | EXPECT_EQ(ERR_IO_PENDING, |
| 12690 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12691 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 12692 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 12693 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12694 | } |
| 12695 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12696 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12697 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12698 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 12699 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12700 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 12701 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 12702 | |
| 12703 | // Use two different hosts with different IPs so they don't get pooled. |
| 12704 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 12705 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
| 12706 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12707 | |
| 12708 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12709 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12710 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12711 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 12713 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 12714 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12715 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12716 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 12717 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12718 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12719 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12720 | scoped_ptr<SpdyFrame> host1_resp( |
| 12721 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12722 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12723 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12724 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12725 | CreateMockRead(*host1_resp, 1), |
| 12726 | CreateMockRead(*host1_resp_body, 2), |
| 12727 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12728 | }; |
| 12729 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12730 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 12731 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 12732 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12733 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 12734 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12735 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12736 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 12737 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12738 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12739 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12740 | scoped_ptr<SpdyFrame> host2_resp( |
| 12741 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12742 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12743 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12744 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12745 | CreateMockRead(*host2_resp, 1), |
| 12746 | CreateMockRead(*host2_resp_body, 2), |
| 12747 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12748 | }; |
| 12749 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12750 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 12751 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 12752 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12753 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 12754 | |
| 12755 | MockWrite http_write[] = { |
| 12756 | MockWrite("GET / HTTP/1.1\r\n" |
| 12757 | "Host: www.a.com\r\n" |
| 12758 | "Connection: keep-alive\r\n\r\n"), |
| 12759 | }; |
| 12760 | |
| 12761 | MockRead http_read[] = { |
| 12762 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12763 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12764 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12765 | MockRead("hello!"), |
| 12766 | }; |
| 12767 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 12768 | http_write, arraysize(http_write)); |
| 12769 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12770 | |
| 12771 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12772 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12773 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12774 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12775 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12776 | |
| 12777 | TestCompletionCallback callback; |
| 12778 | HttpRequestInfo request1; |
| 12779 | request1.method = "GET"; |
| 12780 | request1.url = GURL("https://www.a.com/"); |
| 12781 | request1.load_flags = 0; |
| 12782 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12783 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12784 | |
| 12785 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 12786 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12787 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12788 | |
| 12789 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12790 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12791 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12792 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12793 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12794 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12795 | |
| 12796 | std::string response_data; |
| 12797 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12798 | EXPECT_EQ("hello!", response_data); |
| 12799 | trans.reset(); |
| 12800 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12801 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12802 | |
| 12803 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12804 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12805 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12806 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12807 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12808 | HttpRequestInfo request2; |
| 12809 | request2.method = "GET"; |
| 12810 | request2.url = GURL("https://www.b.com/"); |
| 12811 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12812 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12813 | |
| 12814 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 12815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12816 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12817 | |
| 12818 | response = trans->GetResponseInfo(); |
| 12819 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12820 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12821 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12822 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12823 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12824 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12825 | EXPECT_EQ("hello!", response_data); |
| 12826 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12827 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12828 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12829 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12830 | |
| 12831 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12832 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12833 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12834 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12835 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12836 | HttpRequestInfo request3; |
| 12837 | request3.method = "GET"; |
| 12838 | request3.url = GURL("http://www.a.com/"); |
| 12839 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12840 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12841 | |
| 12842 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 12843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12844 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12845 | |
| 12846 | response = trans->GetResponseInfo(); |
| 12847 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12848 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12849 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12850 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12851 | EXPECT_FALSE(response->was_npn_negotiated); |
| 12852 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 12853 | EXPECT_EQ("hello!", response_data); |
| 12854 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12855 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12856 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12857 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 12858 | } |
| 12859 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12860 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 12861 | HttpRequestInfo request; |
| 12862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12863 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12864 | request.load_flags = 0; |
| 12865 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12866 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12867 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12868 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12869 | |
| 12870 | MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED); |
| 12871 | StaticSocketDataProvider data; |
| 12872 | data.set_connect_data(mock_connect); |
| 12873 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12874 | |
| 12875 | TestCompletionCallback callback; |
| 12876 | |
| 12877 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12879 | |
| 12880 | rv = callback.WaitForResult(); |
| 12881 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12882 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12883 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12884 | HttpRequestHeaders request_headers; |
| 12885 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 12886 | |
| 12887 | ConnectionAttempts attempts; |
| 12888 | trans->GetConnectionAttempts(&attempts); |
| 12889 | ASSERT_EQ(1u, attempts.size()); |
| 12890 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12891 | } |
| 12892 | |
| 12893 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 12894 | HttpRequestInfo request; |
| 12895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12896 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12897 | request.load_flags = 0; |
| 12898 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12899 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12900 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12901 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12902 | |
| 12903 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12904 | StaticSocketDataProvider data; |
| 12905 | data.set_connect_data(mock_connect); |
| 12906 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12907 | |
| 12908 | TestCompletionCallback callback; |
| 12909 | |
| 12910 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12911 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12912 | |
| 12913 | rv = callback.WaitForResult(); |
| 12914 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12915 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12916 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 12917 | HttpRequestHeaders request_headers; |
| 12918 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 12919 | |
| 12920 | ConnectionAttempts attempts; |
| 12921 | trans->GetConnectionAttempts(&attempts); |
| 12922 | ASSERT_EQ(1u, attempts.size()); |
| 12923 | EXPECT_EQ(ERR_CONNECTION_REFUSED, attempts[0].result); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12924 | } |
| 12925 | |
| 12926 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 12927 | HttpRequestInfo request; |
| 12928 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12929 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12930 | request.load_flags = 0; |
| 12931 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12932 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12933 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12934 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12935 | |
| 12936 | MockWrite data_writes[] = { |
| 12937 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 12938 | }; |
| 12939 | MockRead data_reads[] = { |
| 12940 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12941 | }; |
| 12942 | |
| 12943 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12944 | data_writes, arraysize(data_writes)); |
| 12945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12946 | |
| 12947 | TestCompletionCallback callback; |
| 12948 | |
| 12949 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12950 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12951 | |
| 12952 | rv = callback.WaitForResult(); |
| 12953 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12954 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12955 | HttpRequestHeaders request_headers; |
| 12956 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12957 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12958 | } |
| 12959 | |
| 12960 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 12961 | HttpRequestInfo request; |
| 12962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12963 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12964 | request.load_flags = 0; |
| 12965 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 12966 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12967 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12968 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12969 | |
| 12970 | MockWrite data_writes[] = { |
| 12971 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 12972 | }; |
| 12973 | MockRead data_reads[] = { |
| 12974 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 12975 | }; |
| 12976 | |
| 12977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12978 | data_writes, arraysize(data_writes)); |
| 12979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12980 | |
| 12981 | TestCompletionCallback callback; |
| 12982 | |
| 12983 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12984 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12985 | |
| 12986 | rv = callback.WaitForResult(); |
| 12987 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 12988 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12989 | HttpRequestHeaders request_headers; |
| 12990 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 12991 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 12992 | } |
| 12993 | |
| 12994 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 12995 | HttpRequestInfo request; |
| 12996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12997 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 12998 | request.load_flags = 0; |
| 12999 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13000 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13001 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13002 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13003 | |
| 13004 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13005 | MockWrite( |
| 13006 | "GET / HTTP/1.1\r\n" |
| 13007 | "Host: www.example.org\r\n" |
| 13008 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13009 | }; |
| 13010 | MockRead data_reads[] = { |
| 13011 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13012 | }; |
| 13013 | |
| 13014 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13015 | data_writes, arraysize(data_writes)); |
| 13016 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13017 | |
| 13018 | TestCompletionCallback callback; |
| 13019 | |
| 13020 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13021 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13022 | |
| 13023 | rv = callback.WaitForResult(); |
| 13024 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13025 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13026 | HttpRequestHeaders request_headers; |
| 13027 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13028 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13029 | } |
| 13030 | |
| 13031 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13032 | HttpRequestInfo request; |
| 13033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13034 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13035 | request.load_flags = 0; |
| 13036 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13037 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13038 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13039 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13040 | |
| 13041 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13042 | MockWrite( |
| 13043 | "GET / HTTP/1.1\r\n" |
| 13044 | "Host: www.example.org\r\n" |
| 13045 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13046 | }; |
| 13047 | MockRead data_reads[] = { |
| 13048 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13049 | }; |
| 13050 | |
| 13051 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13052 | data_writes, arraysize(data_writes)); |
| 13053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13054 | |
| 13055 | TestCompletionCallback callback; |
| 13056 | |
| 13057 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13058 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13059 | |
| 13060 | rv = callback.WaitForResult(); |
| 13061 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13062 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13063 | HttpRequestHeaders request_headers; |
| 13064 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13065 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13066 | } |
| 13067 | |
| 13068 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13069 | HttpRequestInfo request; |
| 13070 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13071 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13072 | request.load_flags = 0; |
| 13073 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13074 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 13075 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13076 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13077 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13078 | |
| 13079 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13080 | MockWrite( |
| 13081 | "GET / HTTP/1.1\r\n" |
| 13082 | "Host: www.example.org\r\n" |
| 13083 | "Connection: keep-alive\r\n" |
| 13084 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13085 | }; |
| 13086 | MockRead data_reads[] = { |
| 13087 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13088 | "Content-Length: 5\r\n\r\n" |
| 13089 | "hello"), |
| 13090 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13091 | }; |
| 13092 | |
| 13093 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13094 | data_writes, arraysize(data_writes)); |
| 13095 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13096 | |
| 13097 | TestCompletionCallback callback; |
| 13098 | |
| 13099 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13100 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13101 | |
| 13102 | rv = callback.WaitForResult(); |
| 13103 | EXPECT_EQ(OK, rv); |
| 13104 | |
| 13105 | HttpRequestHeaders request_headers; |
| 13106 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13107 | std::string foo; |
| 13108 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13109 | EXPECT_EQ("bar", foo); |
| 13110 | } |
| 13111 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13112 | namespace { |
| 13113 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13114 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13115 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13116 | public base::SupportsWeakPtr<FakeStream> { |
| 13117 | public: |
| 13118 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13119 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13120 | |
| 13121 | RequestPriority priority() const { return priority_; } |
| 13122 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13123 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13124 | RequestPriority priority, |
| 13125 | const BoundNetLog& net_log, |
| 13126 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13127 | return ERR_IO_PENDING; |
| 13128 | } |
| 13129 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13130 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13131 | HttpResponseInfo* response, |
| 13132 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13133 | ADD_FAILURE(); |
| 13134 | return ERR_UNEXPECTED; |
| 13135 | } |
| 13136 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13137 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13138 | ADD_FAILURE(); |
| 13139 | return ERR_UNEXPECTED; |
| 13140 | } |
| 13141 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13142 | int ReadResponseBody(IOBuffer* buf, |
| 13143 | int buf_len, |
| 13144 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13145 | ADD_FAILURE(); |
| 13146 | return ERR_UNEXPECTED; |
| 13147 | } |
| 13148 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13149 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13150 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13151 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13152 | ADD_FAILURE(); |
| 13153 | return false; |
| 13154 | } |
| 13155 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13156 | bool CanFindEndOfResponse() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13157 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13158 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13159 | ADD_FAILURE(); |
| 13160 | return false; |
| 13161 | } |
| 13162 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13163 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13164 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13165 | bool IsConnectionReusable() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13166 | ADD_FAILURE(); |
| 13167 | return false; |
| 13168 | } |
| 13169 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13170 | int64 GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 13171 | ADD_FAILURE(); |
| 13172 | return 0; |
| 13173 | } |
| 13174 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13175 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13176 | ADD_FAILURE(); |
| 13177 | return false; |
| 13178 | } |
| 13179 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13180 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13181 | |
| 13182 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13183 | ADD_FAILURE(); |
| 13184 | } |
| 13185 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13186 | bool IsSpdyHttpStream() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13187 | ADD_FAILURE(); |
| 13188 | return false; |
| 13189 | } |
| 13190 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13191 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13192 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13193 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13194 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13195 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13196 | |
| 13197 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13198 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13199 | private: |
| 13200 | RequestPriority priority_; |
| 13201 | |
| 13202 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13203 | }; |
| 13204 | |
| 13205 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13206 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13207 | class FakeStreamRequest : public HttpStreamRequest, |
| 13208 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13209 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13210 | FakeStreamRequest(RequestPriority priority, |
| 13211 | HttpStreamRequest::Delegate* delegate) |
| 13212 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13213 | delegate_(delegate), |
| 13214 | websocket_stream_create_helper_(NULL) {} |
| 13215 | |
| 13216 | FakeStreamRequest(RequestPriority priority, |
| 13217 | HttpStreamRequest::Delegate* delegate, |
| 13218 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 13219 | : priority_(priority), |
| 13220 | delegate_(delegate), |
| 13221 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13222 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13223 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13224 | |
| 13225 | RequestPriority priority() const { return priority_; } |
| 13226 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13227 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 13228 | websocket_stream_create_helper() const { |
| 13229 | return websocket_stream_create_helper_; |
| 13230 | } |
| 13231 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13232 | // Create a new FakeStream and pass it to the request's |
| 13233 | // delegate. Returns a weak pointer to the FakeStream. |
| 13234 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 13235 | FakeStream* fake_stream = new FakeStream(priority_); |
| 13236 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 13237 | // immediately delete |fake_stream|. |
| 13238 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 13239 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 13240 | return weak_stream; |
| 13241 | } |
| 13242 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13243 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13244 | ADD_FAILURE(); |
| 13245 | return ERR_UNEXPECTED; |
| 13246 | } |
| 13247 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13248 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13249 | ADD_FAILURE(); |
| 13250 | return LoadState(); |
| 13251 | } |
| 13252 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13253 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13254 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13255 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13256 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13257 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13258 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13259 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13260 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13261 | const ConnectionAttempts& connection_attempts() const override { |
| 13262 | static ConnectionAttempts no_attempts; |
| 13263 | return no_attempts; |
| 13264 | } |
| 13265 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13266 | private: |
| 13267 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13268 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13269 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13270 | |
| 13271 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 13272 | }; |
| 13273 | |
| 13274 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 13275 | class FakeStreamFactory : public HttpStreamFactory { |
| 13276 | public: |
| 13277 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13278 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13279 | |
| 13280 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 13281 | // RequestStream() (which may be NULL if it was destroyed already). |
| 13282 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 13283 | return last_stream_request_; |
| 13284 | } |
| 13285 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13286 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 13287 | RequestPriority priority, |
| 13288 | const SSLConfig& server_ssl_config, |
| 13289 | const SSLConfig& proxy_ssl_config, |
| 13290 | HttpStreamRequest::Delegate* delegate, |
| 13291 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13292 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13293 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13294 | return fake_request; |
| 13295 | } |
| 13296 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13297 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13298 | const HttpRequestInfo& info, |
| 13299 | RequestPriority priority, |
| 13300 | const SSLConfig& server_ssl_config, |
| 13301 | const SSLConfig& proxy_ssl_config, |
| 13302 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 13303 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13304 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13305 | FakeStreamRequest* fake_request = |
| 13306 | new FakeStreamRequest(priority, delegate, create_helper); |
| 13307 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 13308 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13309 | } |
| 13310 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13311 | void PreconnectStreams(int num_streams, |
| 13312 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13313 | const SSLConfig& server_ssl_config, |
| 13314 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13315 | ADD_FAILURE(); |
| 13316 | } |
| 13317 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13318 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13319 | ADD_FAILURE(); |
| 13320 | return NULL; |
| 13321 | } |
| 13322 | |
| 13323 | private: |
| 13324 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 13325 | |
| 13326 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 13327 | }; |
| 13328 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13329 | // TODO(ricea): Maybe unify this with the one in |
| 13330 | // url_request_http_job_unittest.cc ? |
| 13331 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 13332 | public: |
| 13333 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 13334 | bool using_proxy) |
| 13335 | : state_(connection.release(), using_proxy) {} |
| 13336 | |
| 13337 | // Fake implementation of HttpStreamBase methods. |
| 13338 | // This ends up being quite "real" because this object has to really send data |
| 13339 | // on the mock socket. It might be easier to use the real implementation, but |
| 13340 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 13341 | // difficult. |
| 13342 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13343 | RequestPriority priority, |
| 13344 | const BoundNetLog& net_log, |
| 13345 | const CompletionCallback& callback) override { |
| 13346 | state_.Initialize(request_info, priority, net_log, callback); |
| 13347 | return OK; |
| 13348 | } |
| 13349 | |
| 13350 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13351 | HttpResponseInfo* response, |
| 13352 | const CompletionCallback& callback) override { |
| 13353 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 13354 | response, callback); |
| 13355 | } |
| 13356 | |
| 13357 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 13358 | return parser()->ReadResponseHeaders(callback); |
| 13359 | } |
| 13360 | |
| 13361 | int ReadResponseBody(IOBuffer* buf, |
| 13362 | int buf_len, |
| 13363 | const CompletionCallback& callback) override { |
| 13364 | NOTREACHED(); |
| 13365 | return ERR_IO_PENDING; |
| 13366 | } |
| 13367 | |
| 13368 | void Close(bool not_reusable) override { |
| 13369 | if (parser()) |
| 13370 | parser()->Close(true); |
| 13371 | } |
| 13372 | |
| 13373 | bool IsResponseBodyComplete() const override { |
| 13374 | NOTREACHED(); |
| 13375 | return false; |
| 13376 | } |
| 13377 | |
| 13378 | bool CanFindEndOfResponse() const override { |
| 13379 | return parser()->CanFindEndOfResponse(); |
| 13380 | } |
| 13381 | |
| 13382 | bool IsConnectionReused() const override { |
| 13383 | NOTREACHED(); |
| 13384 | return false; |
| 13385 | } |
| 13386 | void SetConnectionReused() override { NOTREACHED(); } |
| 13387 | |
| 13388 | bool IsConnectionReusable() const override { |
| 13389 | NOTREACHED(); |
| 13390 | return false; |
| 13391 | } |
| 13392 | |
| 13393 | int64 GetTotalReceivedBytes() const override { |
| 13394 | NOTREACHED(); |
| 13395 | return 0; |
| 13396 | } |
| 13397 | |
| 13398 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 13399 | NOTREACHED(); |
| 13400 | return false; |
| 13401 | } |
| 13402 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 13403 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13404 | |
| 13405 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 13406 | NOTREACHED(); |
| 13407 | } |
| 13408 | |
| 13409 | bool IsSpdyHttpStream() const override { |
| 13410 | NOTREACHED(); |
| 13411 | return false; |
| 13412 | } |
| 13413 | |
| 13414 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 13415 | |
| 13416 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 13417 | |
| 13418 | UploadProgress GetUploadProgress() const override { |
| 13419 | NOTREACHED(); |
| 13420 | return UploadProgress(); |
| 13421 | } |
| 13422 | |
| 13423 | HttpStream* RenewStreamForAuth() override { |
| 13424 | NOTREACHED(); |
| 13425 | return nullptr; |
| 13426 | } |
| 13427 | |
| 13428 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 13429 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 13430 | NOTREACHED(); |
| 13431 | return scoped_ptr<WebSocketStream>(); |
| 13432 | } |
| 13433 | |
| 13434 | private: |
| 13435 | HttpStreamParser* parser() const { return state_.parser(); } |
| 13436 | HttpBasicState state_; |
| 13437 | |
| 13438 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 13439 | }; |
| 13440 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13441 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 13442 | // worth doing. |
| 13443 | class FakeWebSocketStreamCreateHelper : |
| 13444 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 13445 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13446 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 13447 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13448 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 13449 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 13450 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13451 | } |
| 13452 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13453 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13454 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 13455 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13456 | NOTREACHED(); |
| 13457 | return NULL; |
| 13458 | }; |
| 13459 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13460 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13461 | |
| 13462 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 13463 | NOTREACHED(); |
| 13464 | return scoped_ptr<WebSocketStream>(); |
| 13465 | } |
| 13466 | }; |
| 13467 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13468 | } // namespace |
| 13469 | |
| 13470 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 13471 | // stream request on start. |
| 13472 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
| 13473 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13474 | HttpNetworkSessionPeer peer(session); |
| 13475 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13476 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13477 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13478 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13479 | |
| 13480 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 13481 | |
| 13482 | HttpRequestInfo request; |
| 13483 | TestCompletionCallback callback; |
| 13484 | EXPECT_EQ(ERR_IO_PENDING, |
| 13485 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13486 | |
| 13487 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13488 | fake_factory->last_stream_request(); |
| 13489 | ASSERT_TRUE(fake_request != NULL); |
| 13490 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13491 | } |
| 13492 | |
| 13493 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13494 | // updates to its stream request. |
| 13495 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
| 13496 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13497 | HttpNetworkSessionPeer peer(session); |
| 13498 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13499 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13500 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13501 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13502 | |
| 13503 | HttpRequestInfo request; |
| 13504 | TestCompletionCallback callback; |
| 13505 | EXPECT_EQ(ERR_IO_PENDING, |
| 13506 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13507 | |
| 13508 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13509 | fake_factory->last_stream_request(); |
| 13510 | ASSERT_TRUE(fake_request != NULL); |
| 13511 | EXPECT_EQ(LOW, fake_request->priority()); |
| 13512 | |
| 13513 | trans.SetPriority(LOWEST); |
| 13514 | ASSERT_TRUE(fake_request != NULL); |
| 13515 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 13516 | } |
| 13517 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13518 | // Make sure that HttpNetworkTransaction passes on its priority |
| 13519 | // updates to its stream. |
| 13520 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
| 13521 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13522 | HttpNetworkSessionPeer peer(session); |
| 13523 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13524 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13525 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13526 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13527 | |
| 13528 | HttpRequestInfo request; |
| 13529 | TestCompletionCallback callback; |
| 13530 | EXPECT_EQ(ERR_IO_PENDING, |
| 13531 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13532 | |
| 13533 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13534 | fake_factory->last_stream_request(); |
| 13535 | ASSERT_TRUE(fake_request != NULL); |
| 13536 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 13537 | ASSERT_TRUE(fake_stream != NULL); |
| 13538 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 13539 | |
| 13540 | trans.SetPriority(LOWEST); |
| 13541 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 13542 | } |
| 13543 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13544 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 13545 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 13546 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 13547 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13548 | std::string test_cases[] = {"ws://www.example.org/", |
| 13549 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13550 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 13551 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13552 | HttpNetworkSessionPeer peer(session); |
| 13553 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 13554 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 13555 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13556 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 13557 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13558 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13559 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 13560 | &websocket_stream_create_helper); |
| 13561 | |
| 13562 | HttpRequestInfo request; |
| 13563 | TestCompletionCallback callback; |
| 13564 | request.method = "GET"; |
| 13565 | request.url = GURL(test_cases[i]); |
| 13566 | |
| 13567 | EXPECT_EQ(ERR_IO_PENDING, |
| 13568 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 13569 | |
| 13570 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 13571 | fake_factory->last_stream_request(); |
| 13572 | ASSERT_TRUE(fake_request != NULL); |
| 13573 | EXPECT_EQ(&websocket_stream_create_helper, |
| 13574 | fake_request->websocket_stream_create_helper()); |
| 13575 | } |
| 13576 | } |
| 13577 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13578 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 13579 | // if the transport socket pool is stalled on the global socket limit. |
| 13580 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 13581 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13582 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13583 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13584 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13585 | |
| 13586 | // Set up SSL request. |
| 13587 | |
| 13588 | HttpRequestInfo ssl_request; |
| 13589 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13590 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13591 | |
| 13592 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13593 | MockWrite( |
| 13594 | "GET / HTTP/1.1\r\n" |
| 13595 | "Host: www.example.org\r\n" |
| 13596 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13597 | }; |
| 13598 | MockRead ssl_reads[] = { |
| 13599 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13600 | MockRead("Content-Length: 11\r\n\r\n"), |
| 13601 | MockRead("hello world"), |
| 13602 | MockRead(SYNCHRONOUS, OK), |
| 13603 | }; |
| 13604 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 13605 | ssl_writes, arraysize(ssl_writes)); |
| 13606 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13607 | |
| 13608 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13610 | |
| 13611 | // Set up HTTP request. |
| 13612 | |
| 13613 | HttpRequestInfo http_request; |
| 13614 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13615 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13616 | |
| 13617 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13618 | MockWrite( |
| 13619 | "GET / HTTP/1.1\r\n" |
| 13620 | "Host: www.example.org\r\n" |
| 13621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13622 | }; |
| 13623 | MockRead http_reads[] = { |
| 13624 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13625 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13626 | MockRead("falafel"), |
| 13627 | MockRead(SYNCHRONOUS, OK), |
| 13628 | }; |
| 13629 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13630 | http_writes, arraysize(http_writes)); |
| 13631 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13632 | |
| 13633 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13634 | |
| 13635 | // Start the SSL request. |
| 13636 | TestCompletionCallback ssl_callback; |
| 13637 | scoped_ptr<HttpTransaction> ssl_trans( |
| 13638 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13639 | ASSERT_EQ(ERR_IO_PENDING, |
| 13640 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 13641 | BoundNetLog())); |
| 13642 | |
| 13643 | // Start the HTTP request. Pool should stall. |
| 13644 | TestCompletionCallback http_callback; |
| 13645 | scoped_ptr<HttpTransaction> http_trans( |
| 13646 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13647 | ASSERT_EQ(ERR_IO_PENDING, |
| 13648 | http_trans->Start(&http_request, http_callback.callback(), |
| 13649 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13650 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13651 | |
| 13652 | // Wait for response from SSL request. |
| 13653 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 13654 | std::string response_data; |
| 13655 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 13656 | EXPECT_EQ("hello world", response_data); |
| 13657 | |
| 13658 | // The SSL socket should automatically be closed, so the HTTP request can |
| 13659 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13660 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 13661 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13662 | |
| 13663 | // The HTTP request can now complete. |
| 13664 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13665 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13666 | EXPECT_EQ("falafel", response_data); |
| 13667 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13668 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13669 | } |
| 13670 | |
| 13671 | // Tests that when a SSL connection is established but there's no corresponding |
| 13672 | // request that needs it, the new socket is closed if the transport socket pool |
| 13673 | // is stalled on the global socket limit. |
| 13674 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 13675 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13676 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13677 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13678 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13679 | |
| 13680 | // Set up an ssl request. |
| 13681 | |
| 13682 | HttpRequestInfo ssl_request; |
| 13683 | ssl_request.method = "GET"; |
| 13684 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 13685 | |
| 13686 | // No data will be sent on the SSL socket. |
| 13687 | StaticSocketDataProvider ssl_data; |
| 13688 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 13689 | |
| 13690 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13692 | |
| 13693 | // Set up HTTP request. |
| 13694 | |
| 13695 | HttpRequestInfo http_request; |
| 13696 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13697 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13698 | |
| 13699 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13700 | MockWrite( |
| 13701 | "GET / HTTP/1.1\r\n" |
| 13702 | "Host: www.example.org\r\n" |
| 13703 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13704 | }; |
| 13705 | MockRead http_reads[] = { |
| 13706 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13707 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13708 | MockRead("falafel"), |
| 13709 | MockRead(SYNCHRONOUS, OK), |
| 13710 | }; |
| 13711 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13712 | http_writes, arraysize(http_writes)); |
| 13713 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13714 | |
| 13715 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13716 | |
| 13717 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 13718 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13719 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 13720 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13721 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 13722 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 13723 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13724 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13725 | |
| 13726 | // Start the HTTP request. Pool should stall. |
| 13727 | TestCompletionCallback http_callback; |
| 13728 | scoped_ptr<HttpTransaction> http_trans( |
| 13729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13730 | ASSERT_EQ(ERR_IO_PENDING, |
| 13731 | http_trans->Start(&http_request, http_callback.callback(), |
| 13732 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13733 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13734 | |
| 13735 | // The SSL connection will automatically be closed once the connection is |
| 13736 | // established, to let the HTTP request start. |
| 13737 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 13738 | std::string response_data; |
| 13739 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 13740 | EXPECT_EQ("falafel", response_data); |
| 13741 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13742 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 13743 | } |
| 13744 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13745 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 13746 | ScopedVector<UploadElementReader> element_readers; |
| 13747 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13748 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13749 | |
| 13750 | HttpRequestInfo request; |
| 13751 | request.method = "POST"; |
| 13752 | request.url = GURL("http://www.foo.com/"); |
| 13753 | request.upload_data_stream = &upload_data_stream; |
| 13754 | request.load_flags = 0; |
| 13755 | |
| 13756 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13757 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13758 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13759 | // Send headers successfully, but get an error while sending the body. |
| 13760 | MockWrite data_writes[] = { |
| 13761 | MockWrite("POST / HTTP/1.1\r\n" |
| 13762 | "Host: www.foo.com\r\n" |
| 13763 | "Connection: keep-alive\r\n" |
| 13764 | "Content-Length: 3\r\n\r\n"), |
| 13765 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13766 | }; |
| 13767 | |
| 13768 | MockRead data_reads[] = { |
| 13769 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13770 | MockRead("hello world"), |
| 13771 | MockRead(SYNCHRONOUS, OK), |
| 13772 | }; |
| 13773 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13774 | arraysize(data_writes)); |
| 13775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13776 | |
| 13777 | TestCompletionCallback callback; |
| 13778 | |
| 13779 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13780 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13781 | |
| 13782 | rv = callback.WaitForResult(); |
| 13783 | EXPECT_EQ(OK, rv); |
| 13784 | |
| 13785 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13786 | ASSERT_TRUE(response != NULL); |
| 13787 | |
| 13788 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13789 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13790 | |
| 13791 | std::string response_data; |
| 13792 | rv = ReadTransaction(trans.get(), &response_data); |
| 13793 | EXPECT_EQ(OK, rv); |
| 13794 | EXPECT_EQ("hello world", response_data); |
| 13795 | } |
| 13796 | |
| 13797 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 13798 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 13799 | TEST_P(HttpNetworkTransactionTest, |
| 13800 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
| 13801 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13802 | MockWrite data_writes[] = { |
| 13803 | MockWrite("GET / HTTP/1.1\r\n" |
| 13804 | "Host: www.foo.com\r\n" |
| 13805 | "Connection: keep-alive\r\n\r\n"), |
| 13806 | MockWrite("POST / HTTP/1.1\r\n" |
| 13807 | "Host: www.foo.com\r\n" |
| 13808 | "Connection: keep-alive\r\n" |
| 13809 | "Content-Length: 3\r\n\r\n"), |
| 13810 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13811 | }; |
| 13812 | |
| 13813 | MockRead data_reads[] = { |
| 13814 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 13815 | "Content-Length: 14\r\n\r\n"), |
| 13816 | MockRead("first response"), |
| 13817 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 13818 | "Content-Length: 15\r\n\r\n"), |
| 13819 | MockRead("second response"), |
| 13820 | MockRead(SYNCHRONOUS, OK), |
| 13821 | }; |
| 13822 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13823 | arraysize(data_writes)); |
| 13824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13825 | |
| 13826 | TestCompletionCallback callback; |
| 13827 | HttpRequestInfo request1; |
| 13828 | request1.method = "GET"; |
| 13829 | request1.url = GURL("http://www.foo.com/"); |
| 13830 | request1.load_flags = 0; |
| 13831 | |
| 13832 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13833 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13834 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 13835 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13836 | |
| 13837 | rv = callback.WaitForResult(); |
| 13838 | EXPECT_EQ(OK, rv); |
| 13839 | |
| 13840 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13841 | ASSERT_TRUE(response1 != NULL); |
| 13842 | |
| 13843 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 13844 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 13845 | |
| 13846 | std::string response_data1; |
| 13847 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 13848 | EXPECT_EQ(OK, rv); |
| 13849 | EXPECT_EQ("first response", response_data1); |
| 13850 | // Delete the transaction to release the socket back into the socket pool. |
| 13851 | trans1.reset(); |
| 13852 | |
| 13853 | ScopedVector<UploadElementReader> element_readers; |
| 13854 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13855 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13856 | |
| 13857 | HttpRequestInfo request2; |
| 13858 | request2.method = "POST"; |
| 13859 | request2.url = GURL("http://www.foo.com/"); |
| 13860 | request2.upload_data_stream = &upload_data_stream; |
| 13861 | request2.load_flags = 0; |
| 13862 | |
| 13863 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13865 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 13866 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13867 | |
| 13868 | rv = callback.WaitForResult(); |
| 13869 | EXPECT_EQ(OK, rv); |
| 13870 | |
| 13871 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 13872 | ASSERT_TRUE(response2 != NULL); |
| 13873 | |
| 13874 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 13875 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 13876 | |
| 13877 | std::string response_data2; |
| 13878 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 13879 | EXPECT_EQ(OK, rv); |
| 13880 | EXPECT_EQ("second response", response_data2); |
| 13881 | } |
| 13882 | |
| 13883 | TEST_P(HttpNetworkTransactionTest, |
| 13884 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 13885 | ScopedVector<UploadElementReader> element_readers; |
| 13886 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13887 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13888 | |
| 13889 | HttpRequestInfo request; |
| 13890 | request.method = "POST"; |
| 13891 | request.url = GURL("http://www.foo.com/"); |
| 13892 | request.upload_data_stream = &upload_data_stream; |
| 13893 | request.load_flags = 0; |
| 13894 | |
| 13895 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13896 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13897 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13898 | // Send headers successfully, but get an error while sending the body. |
| 13899 | MockWrite data_writes[] = { |
| 13900 | MockWrite("POST / HTTP/1.1\r\n" |
| 13901 | "Host: www.foo.com\r\n" |
| 13902 | "Connection: keep-alive\r\n" |
| 13903 | "Content-Length: 3\r\n\r\n" |
| 13904 | "fo"), |
| 13905 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13906 | }; |
| 13907 | |
| 13908 | MockRead data_reads[] = { |
| 13909 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13910 | MockRead("hello world"), |
| 13911 | MockRead(SYNCHRONOUS, OK), |
| 13912 | }; |
| 13913 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13914 | arraysize(data_writes)); |
| 13915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13916 | |
| 13917 | TestCompletionCallback callback; |
| 13918 | |
| 13919 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13920 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13921 | |
| 13922 | rv = callback.WaitForResult(); |
| 13923 | EXPECT_EQ(OK, rv); |
| 13924 | |
| 13925 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13926 | ASSERT_TRUE(response != NULL); |
| 13927 | |
| 13928 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13929 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13930 | |
| 13931 | std::string response_data; |
| 13932 | rv = ReadTransaction(trans.get(), &response_data); |
| 13933 | EXPECT_EQ(OK, rv); |
| 13934 | EXPECT_EQ("hello world", response_data); |
| 13935 | } |
| 13936 | |
| 13937 | // This tests the more common case than the previous test, where headers and |
| 13938 | // body are not merged into a single request. |
| 13939 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 13940 | ScopedVector<UploadElementReader> element_readers; |
| 13941 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13942 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13943 | |
| 13944 | HttpRequestInfo request; |
| 13945 | request.method = "POST"; |
| 13946 | request.url = GURL("http://www.foo.com/"); |
| 13947 | request.upload_data_stream = &upload_data_stream; |
| 13948 | request.load_flags = 0; |
| 13949 | |
| 13950 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13951 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13952 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13953 | // Send headers successfully, but get an error while sending the body. |
| 13954 | MockWrite data_writes[] = { |
| 13955 | MockWrite("POST / HTTP/1.1\r\n" |
| 13956 | "Host: www.foo.com\r\n" |
| 13957 | "Connection: keep-alive\r\n" |
| 13958 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 13959 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13960 | }; |
| 13961 | |
| 13962 | MockRead data_reads[] = { |
| 13963 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 13964 | MockRead("hello world"), |
| 13965 | MockRead(SYNCHRONOUS, OK), |
| 13966 | }; |
| 13967 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 13968 | arraysize(data_writes)); |
| 13969 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13970 | |
| 13971 | TestCompletionCallback callback; |
| 13972 | |
| 13973 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13975 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 13976 | // they can't be merged with the body in a single send. Not currently |
| 13977 | // necessary since a chunked body is never merged with headers, but this makes |
| 13978 | // the test more future proof. |
| 13979 | base::RunLoop().RunUntilIdle(); |
| 13980 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 13981 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 13982 | |
| 13983 | rv = callback.WaitForResult(); |
| 13984 | EXPECT_EQ(OK, rv); |
| 13985 | |
| 13986 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13987 | ASSERT_TRUE(response != NULL); |
| 13988 | |
| 13989 | EXPECT_TRUE(response->headers.get() != NULL); |
| 13990 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 13991 | |
| 13992 | std::string response_data; |
| 13993 | rv = ReadTransaction(trans.get(), &response_data); |
| 13994 | EXPECT_EQ(OK, rv); |
| 13995 | EXPECT_EQ("hello world", response_data); |
| 13996 | } |
| 13997 | |
| 13998 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 13999 | ScopedVector<UploadElementReader> element_readers; |
| 14000 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14001 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14002 | |
| 14003 | HttpRequestInfo request; |
| 14004 | request.method = "POST"; |
| 14005 | request.url = GURL("http://www.foo.com/"); |
| 14006 | request.upload_data_stream = &upload_data_stream; |
| 14007 | request.load_flags = 0; |
| 14008 | |
| 14009 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14010 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14011 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14012 | |
| 14013 | MockWrite data_writes[] = { |
| 14014 | MockWrite("POST / HTTP/1.1\r\n" |
| 14015 | "Host: www.foo.com\r\n" |
| 14016 | "Connection: keep-alive\r\n" |
| 14017 | "Content-Length: 3\r\n\r\n"), |
| 14018 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14019 | }; |
| 14020 | |
| 14021 | MockRead data_reads[] = { |
| 14022 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14023 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14024 | MockRead("hello world"), |
| 14025 | MockRead(SYNCHRONOUS, OK), |
| 14026 | }; |
| 14027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14028 | arraysize(data_writes)); |
| 14029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14030 | |
| 14031 | TestCompletionCallback callback; |
| 14032 | |
| 14033 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14034 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14035 | |
| 14036 | rv = callback.WaitForResult(); |
| 14037 | EXPECT_EQ(OK, rv); |
| 14038 | |
| 14039 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14040 | ASSERT_TRUE(response != NULL); |
| 14041 | |
| 14042 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14043 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14044 | |
| 14045 | std::string response_data; |
| 14046 | rv = ReadTransaction(trans.get(), &response_data); |
| 14047 | EXPECT_EQ(OK, rv); |
| 14048 | EXPECT_EQ("hello world", response_data); |
| 14049 | } |
| 14050 | |
| 14051 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14052 | ScopedVector<UploadElementReader> element_readers; |
| 14053 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14054 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14055 | |
| 14056 | HttpRequestInfo request; |
| 14057 | request.method = "POST"; |
| 14058 | request.url = GURL("http://www.foo.com/"); |
| 14059 | request.upload_data_stream = &upload_data_stream; |
| 14060 | request.load_flags = 0; |
| 14061 | |
| 14062 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14063 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14065 | // Send headers successfully, but get an error while sending the body. |
| 14066 | MockWrite data_writes[] = { |
| 14067 | MockWrite("POST / HTTP/1.1\r\n" |
| 14068 | "Host: www.foo.com\r\n" |
| 14069 | "Connection: keep-alive\r\n" |
| 14070 | "Content-Length: 3\r\n\r\n"), |
| 14071 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14072 | }; |
| 14073 | |
| 14074 | MockRead data_reads[] = { |
| 14075 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14076 | MockRead("hello world"), |
| 14077 | MockRead(SYNCHRONOUS, OK), |
| 14078 | }; |
| 14079 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14080 | arraysize(data_writes)); |
| 14081 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14082 | |
| 14083 | TestCompletionCallback callback; |
| 14084 | |
| 14085 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14086 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14087 | |
| 14088 | rv = callback.WaitForResult(); |
| 14089 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14090 | } |
| 14091 | |
| 14092 | TEST_P(HttpNetworkTransactionTest, |
| 14093 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14094 | ScopedVector<UploadElementReader> element_readers; |
| 14095 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14096 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14097 | |
| 14098 | HttpRequestInfo request; |
| 14099 | request.method = "POST"; |
| 14100 | request.url = GURL("http://www.foo.com/"); |
| 14101 | request.upload_data_stream = &upload_data_stream; |
| 14102 | request.load_flags = 0; |
| 14103 | |
| 14104 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14105 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14106 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14107 | // Send headers successfully, but get an error while sending the body. |
| 14108 | MockWrite data_writes[] = { |
| 14109 | MockWrite("POST / HTTP/1.1\r\n" |
| 14110 | "Host: www.foo.com\r\n" |
| 14111 | "Connection: keep-alive\r\n" |
| 14112 | "Content-Length: 3\r\n\r\n"), |
| 14113 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14114 | }; |
| 14115 | |
| 14116 | MockRead data_reads[] = { |
| 14117 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14118 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14119 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14120 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14121 | MockRead(SYNCHRONOUS, OK), |
| 14122 | }; |
| 14123 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14124 | arraysize(data_writes)); |
| 14125 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14126 | |
| 14127 | TestCompletionCallback callback; |
| 14128 | |
| 14129 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14130 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14131 | |
| 14132 | rv = callback.WaitForResult(); |
| 14133 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14134 | } |
| 14135 | |
| 14136 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14137 | ScopedVector<UploadElementReader> element_readers; |
| 14138 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14139 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14140 | |
| 14141 | HttpRequestInfo request; |
| 14142 | request.method = "POST"; |
| 14143 | request.url = GURL("http://www.foo.com/"); |
| 14144 | request.upload_data_stream = &upload_data_stream; |
| 14145 | request.load_flags = 0; |
| 14146 | |
| 14147 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14148 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14149 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14150 | // Send headers successfully, but get an error while sending the body. |
| 14151 | MockWrite data_writes[] = { |
| 14152 | MockWrite("POST / HTTP/1.1\r\n" |
| 14153 | "Host: www.foo.com\r\n" |
| 14154 | "Connection: keep-alive\r\n" |
| 14155 | "Content-Length: 3\r\n\r\n"), |
| 14156 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14157 | }; |
| 14158 | |
| 14159 | MockRead data_reads[] = { |
| 14160 | MockRead("HTTP 0.9 rocks!"), |
| 14161 | MockRead(SYNCHRONOUS, OK), |
| 14162 | }; |
| 14163 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14164 | arraysize(data_writes)); |
| 14165 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14166 | |
| 14167 | TestCompletionCallback callback; |
| 14168 | |
| 14169 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14170 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14171 | |
| 14172 | rv = callback.WaitForResult(); |
| 14173 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14174 | } |
| 14175 | |
| 14176 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14177 | ScopedVector<UploadElementReader> element_readers; |
| 14178 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14179 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14180 | |
| 14181 | HttpRequestInfo request; |
| 14182 | request.method = "POST"; |
| 14183 | request.url = GURL("http://www.foo.com/"); |
| 14184 | request.upload_data_stream = &upload_data_stream; |
| 14185 | request.load_flags = 0; |
| 14186 | |
| 14187 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14188 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14189 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14190 | // Send headers successfully, but get an error while sending the body. |
| 14191 | MockWrite data_writes[] = { |
| 14192 | MockWrite("POST / HTTP/1.1\r\n" |
| 14193 | "Host: www.foo.com\r\n" |
| 14194 | "Connection: keep-alive\r\n" |
| 14195 | "Content-Length: 3\r\n\r\n"), |
| 14196 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14197 | }; |
| 14198 | |
| 14199 | MockRead data_reads[] = { |
| 14200 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14201 | MockRead(SYNCHRONOUS, OK), |
| 14202 | }; |
| 14203 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14204 | arraysize(data_writes)); |
| 14205 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14206 | |
| 14207 | TestCompletionCallback callback; |
| 14208 | |
| 14209 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14210 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14211 | |
| 14212 | rv = callback.WaitForResult(); |
| 14213 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14214 | } |
| 14215 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14216 | // Verify that proxy headers are not sent to the destination server when |
| 14217 | // establishing a tunnel for a secure WebSocket connection. |
| 14218 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14219 | HttpRequestInfo request; |
| 14220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14221 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14222 | AddWebSocketHeaders(&request.extra_headers); |
| 14223 | |
| 14224 | // Configure against proxy server "myproxy:70". |
| 14225 | session_deps_.proxy_service.reset( |
| 14226 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14227 | |
| 14228 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14229 | |
| 14230 | // Since a proxy is configured, try to establish a tunnel. |
| 14231 | MockWrite data_writes[] = { |
| 14232 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14233 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14234 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14235 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14236 | |
| 14237 | // After calling trans->RestartWithAuth(), this is the request we should |
| 14238 | // be issuing -- the final header line contains the credentials. |
| 14239 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14240 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14241 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14242 | "Proxy-Connection: keep-alive\r\n" |
| 14243 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14244 | |
| 14245 | MockWrite( |
| 14246 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14247 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14248 | "Connection: Upgrade\r\n" |
| 14249 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14250 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14251 | "Sec-WebSocket-Version: 13\r\n" |
| 14252 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14253 | }; |
| 14254 | |
| 14255 | // The proxy responds to the connect with a 407, using a persistent |
| 14256 | // connection. |
| 14257 | MockRead data_reads[] = { |
| 14258 | // No credentials. |
| 14259 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 14260 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 14261 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 14262 | |
| 14263 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14264 | |
| 14265 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14266 | MockRead("Upgrade: websocket\r\n"), |
| 14267 | MockRead("Connection: Upgrade\r\n"), |
| 14268 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14269 | }; |
| 14270 | |
| 14271 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14272 | arraysize(data_writes)); |
| 14273 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14274 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14276 | |
| 14277 | scoped_ptr<HttpTransaction> trans( |
| 14278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14279 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14280 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14281 | &websocket_stream_create_helper); |
| 14282 | |
| 14283 | { |
| 14284 | TestCompletionCallback callback; |
| 14285 | |
| 14286 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14287 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14288 | |
| 14289 | rv = callback.WaitForResult(); |
| 14290 | EXPECT_EQ(OK, rv); |
| 14291 | } |
| 14292 | |
| 14293 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14294 | ASSERT_TRUE(response); |
| 14295 | ASSERT_TRUE(response->headers.get()); |
| 14296 | EXPECT_EQ(407, response->headers->response_code()); |
| 14297 | |
| 14298 | { |
| 14299 | TestCompletionCallback callback; |
| 14300 | |
| 14301 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 14302 | callback.callback()); |
| 14303 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14304 | |
| 14305 | rv = callback.WaitForResult(); |
| 14306 | EXPECT_EQ(OK, rv); |
| 14307 | } |
| 14308 | |
| 14309 | response = trans->GetResponseInfo(); |
| 14310 | ASSERT_TRUE(response); |
| 14311 | ASSERT_TRUE(response->headers.get()); |
| 14312 | |
| 14313 | EXPECT_EQ(101, response->headers->response_code()); |
| 14314 | |
| 14315 | trans.reset(); |
| 14316 | session->CloseAllConnections(); |
| 14317 | } |
| 14318 | |
| 14319 | // Verify that proxy headers are not sent to the destination server when |
| 14320 | // establishing a tunnel for an insecure WebSocket connection. |
| 14321 | // This requires the authentication info to be injected into the auth cache |
| 14322 | // due to crbug.com/395064 |
| 14323 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 14324 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 14325 | HttpRequestInfo request; |
| 14326 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14327 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14328 | AddWebSocketHeaders(&request.extra_headers); |
| 14329 | |
| 14330 | // Configure against proxy server "myproxy:70". |
| 14331 | session_deps_.proxy_service.reset( |
| 14332 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 14333 | |
| 14334 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14335 | |
| 14336 | MockWrite data_writes[] = { |
| 14337 | // Try to establish a tunnel for the WebSocket connection, with |
| 14338 | // credentials. Because WebSockets have a separate set of socket pools, |
| 14339 | // they cannot and will not use the same TCP/IP connection as the |
| 14340 | // preflight HTTP request. |
| 14341 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14342 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 14343 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14344 | "Proxy-Connection: keep-alive\r\n" |
| 14345 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 14346 | |
| 14347 | MockWrite( |
| 14348 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14349 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14350 | "Connection: Upgrade\r\n" |
| 14351 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14352 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14353 | "Sec-WebSocket-Version: 13\r\n" |
| 14354 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 14355 | }; |
| 14356 | |
| 14357 | MockRead data_reads[] = { |
| 14358 | // HTTP CONNECT with credentials. |
| 14359 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14360 | |
| 14361 | // WebSocket connection established inside tunnel. |
| 14362 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 14363 | MockRead("Upgrade: websocket\r\n"), |
| 14364 | MockRead("Connection: Upgrade\r\n"), |
| 14365 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 14366 | }; |
| 14367 | |
| 14368 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14369 | arraysize(data_writes)); |
| 14370 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14371 | |
| 14372 | session->http_auth_cache()->Add( |
| 14373 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 14374 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 14375 | |
| 14376 | scoped_ptr<HttpTransaction> trans( |
| 14377 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14378 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 14379 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 14380 | &websocket_stream_create_helper); |
| 14381 | |
| 14382 | TestCompletionCallback callback; |
| 14383 | |
| 14384 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14385 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14386 | |
| 14387 | rv = callback.WaitForResult(); |
| 14388 | EXPECT_EQ(OK, rv); |
| 14389 | |
| 14390 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14391 | ASSERT_TRUE(response); |
| 14392 | ASSERT_TRUE(response->headers.get()); |
| 14393 | |
| 14394 | EXPECT_EQ(101, response->headers->response_code()); |
| 14395 | |
| 14396 | trans.reset(); |
| 14397 | session->CloseAllConnections(); |
| 14398 | } |
| 14399 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 14400 | } // namespace net |