[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> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 13 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 22 | #include "base/run_loop.h" |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 26 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 27 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 28 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 30 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 32 | #include "net/base/load_timing_info.h" |
| 33 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 34 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 35 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 37 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 38 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 39 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 40 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 41 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 42 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 43 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 46 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 50 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 54 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 56 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 58 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 59 | #include "net/log/test_net_log_entry.h" |
| 60 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 61 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 62 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 64 | #include "net/proxy/proxy_resolver.h" |
| 65 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 66 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 67 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 68 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 69 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 70 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 71 | #include "net/socket/socket_test_util.h" |
| 72 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 73 | #include "net/spdy/spdy_framer.h" |
| 74 | #include "net/spdy/spdy_session.h" |
| 75 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 76 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 79 | #include "net/ssl/ssl_config_service_defaults.h" |
| 80 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 81 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 82 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 83 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 84 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 85 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 86 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 87 | using base::ASCIIToUTF16; |
| 88 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 89 | //----------------------------------------------------------------------------- |
| 90 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 91 | namespace net { |
| 92 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 93 | namespace { |
| 94 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 95 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 96 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 97 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 98 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 99 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 100 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 101 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 102 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 103 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 104 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 105 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 106 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 107 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 108 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 109 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 110 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 111 | } |
| 112 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 113 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 114 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 115 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 116 | } |
| 117 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 118 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 119 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 120 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 123 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 124 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 125 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 126 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 127 | if (!params) |
| 128 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 129 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 130 | if (!params->GetList("headers", &header_list)) |
| 131 | return false; |
| 132 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 133 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 134 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 135 | return true; |
| 136 | } |
| 137 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 138 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 139 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 140 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 141 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 143 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 144 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 145 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 146 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 147 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 148 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 149 | |
| 150 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 151 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 152 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 153 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 154 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 155 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 158 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 159 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 161 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 163 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 164 | |
| 165 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 166 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 167 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 169 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 170 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 171 | load_timing_info.send_start); |
| 172 | |
| 173 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 175 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 177 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 178 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 182 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 185 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | |
| 189 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 190 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 191 | load_timing_info.proxy_resolve_end); |
| 192 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 193 | load_timing_info.send_start); |
| 194 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 198 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 203 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | int connect_timing_flags) { |
| 206 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | |
| 209 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 211 | load_timing_info.proxy_resolve_end); |
| 212 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 213 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 214 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 215 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 217 | load_timing_info.send_start); |
| 218 | |
| 219 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 221 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 223 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 224 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 225 | } |
| 226 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 227 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 228 | headers->SetHeader("Connection", "Upgrade"); |
| 229 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 230 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 231 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 232 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 233 | } |
| 234 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 235 | HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 236 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 237 | } |
| 238 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 239 | } // namespace |
| 240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 241 | class HttpNetworkTransactionTest |
| 242 | : public PlatformTest, |
| 243 | public ::testing::WithParamInterface<NextProto> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 244 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 245 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 246 | // Important to restore the per-pool limit first, since the pool limit must |
| 247 | // always be greater than group limit, and the tests reduce both limits. |
| 248 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 249 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 250 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 251 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 252 | } |
| 253 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 254 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 255 | HttpNetworkTransactionTest() |
| 256 | : spdy_util_(GetParam()), |
| 257 | session_deps_(GetParam()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 258 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 259 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 260 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 261 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
| 262 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 263 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 264 | struct SimpleGetHelperResult { |
| 265 | int rv; |
| 266 | std::string status_line; |
| 267 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 268 | int64_t total_received_bytes; |
| 269 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 270 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 271 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 272 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 273 | }; |
| 274 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 275 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 276 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 277 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 278 | } |
| 279 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 280 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 281 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 282 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 283 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 284 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 285 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 286 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 287 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 288 | } |
| 289 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 290 | const char* GetAlternateProtocolFromParam() { |
| 291 | return |
| 292 | AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 293 | } |
| 294 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 295 | std::string GetAlternativeServiceHttpHeader() { |
| 296 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 297 | "=\"www.example.com:443\"\r\n"; |
| 298 | } |
| 299 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 300 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 301 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 302 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 305 | // Either |write_failure| specifies a write failure or |read_failure| |
| 306 | // specifies a read failure when using a reused socket. In either case, the |
| 307 | // failure should cause the network transaction to resend the request, and the |
| 308 | // other argument should be NULL. |
| 309 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 310 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 311 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 312 | // Either |write_failure| specifies a write failure or |read_failure| |
| 313 | // specifies a read failure when using a reused socket. In either case, the |
| 314 | // failure should cause the network transaction to resend the request, and the |
| 315 | // other argument should be NULL. |
| 316 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 317 | const MockRead* read_failure, |
| 318 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 319 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 320 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 321 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 322 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 323 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 324 | HttpRequestInfo request; |
| 325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 326 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 327 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 328 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 329 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 330 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 331 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 332 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 334 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 335 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 336 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 337 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 339 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 340 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 341 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 342 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 344 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 345 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 346 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 347 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 348 | |
| 349 | // Even in the failure cases that use this function, connections are always |
| 350 | // successfully established before the error. |
| 351 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 352 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 353 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 354 | if (out.rv != OK) |
| 355 | return out; |
| 356 | |
| 357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 358 | // Can't use ASSERT_* inside helper functions like this, so |
| 359 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 360 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 361 | out.rv = ERR_UNEXPECTED; |
| 362 | return out; |
| 363 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 364 | out.status_line = response->headers->GetStatusLine(); |
| 365 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 366 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 367 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 368 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 369 | bool got_endpoint = |
| 370 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 371 | EXPECT_EQ(got_endpoint, |
| 372 | out.remote_endpoint_after_start.address().size() > 0); |
| 373 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 374 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 375 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 376 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 377 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 378 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 379 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 380 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 381 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 382 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 383 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 384 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 385 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 386 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 387 | std::string line; |
| 388 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 389 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 390 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 391 | HttpRequestHeaders request_headers; |
| 392 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 393 | std::string value; |
| 394 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 395 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 396 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 397 | EXPECT_EQ("keep-alive", value); |
| 398 | |
| 399 | std::string response_headers; |
| 400 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 401 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 402 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 403 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 404 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 405 | // The total number of sent bytes should not have changed. |
| 406 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 407 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 408 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 409 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 410 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 411 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 412 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 413 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 414 | MockWrite data_writes[] = { |
| 415 | MockWrite("GET / HTTP/1.1\r\n" |
| 416 | "Host: www.example.org\r\n" |
| 417 | "Connection: keep-alive\r\n\r\n"), |
| 418 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 419 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 420 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 421 | arraysize(data_writes)); |
| 422 | StaticSocketDataProvider* data[] = {&reads}; |
| 423 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 424 | |
| 425 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 426 | out.total_sent_bytes); |
| 427 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 430 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 431 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 432 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 433 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 434 | |
| 435 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 436 | |
| 437 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 438 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 439 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 440 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 441 | |
| 442 | // Original socket limits. Some tests set these. Safest to always restore |
| 443 | // them once each test has been run. |
| 444 | int old_max_group_sockets_; |
| 445 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 446 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 447 | |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 448 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 449 | HttpNetworkTransactionTest, |
| 450 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 451 | kProtoHTTP2)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 452 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 453 | namespace { |
| 454 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 455 | class BeforeNetworkStartHandler { |
| 456 | public: |
| 457 | explicit BeforeNetworkStartHandler(bool defer) |
| 458 | : defer_on_before_network_start_(defer), |
| 459 | observed_before_network_start_(false) {} |
| 460 | |
| 461 | void OnBeforeNetworkStart(bool* defer) { |
| 462 | *defer = defer_on_before_network_start_; |
| 463 | observed_before_network_start_ = true; |
| 464 | } |
| 465 | |
| 466 | bool observed_before_network_start() const { |
| 467 | return observed_before_network_start_; |
| 468 | } |
| 469 | |
| 470 | private: |
| 471 | const bool defer_on_before_network_start_; |
| 472 | bool observed_before_network_start_; |
| 473 | |
| 474 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 475 | }; |
| 476 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 477 | class BeforeProxyHeadersSentHandler { |
| 478 | public: |
| 479 | BeforeProxyHeadersSentHandler() |
| 480 | : observed_before_proxy_headers_sent_(false) {} |
| 481 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 482 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 483 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 484 | observed_before_proxy_headers_sent_ = true; |
| 485 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 486 | } |
| 487 | |
| 488 | bool observed_before_proxy_headers_sent() const { |
| 489 | return observed_before_proxy_headers_sent_; |
| 490 | } |
| 491 | |
| 492 | std::string observed_proxy_server_uri() const { |
| 493 | return observed_proxy_server_uri_; |
| 494 | } |
| 495 | |
| 496 | private: |
| 497 | bool observed_before_proxy_headers_sent_; |
| 498 | std::string observed_proxy_server_uri_; |
| 499 | |
| 500 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 501 | }; |
| 502 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 503 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 504 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 505 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 506 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 507 | const int sizeof_row = strlen(row); |
| 508 | const int num_rows = static_cast<int>( |
| 509 | ceil(static_cast<float>(size) / sizeof_row)); |
| 510 | const int sizeof_data = num_rows * sizeof_row; |
| 511 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 512 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 513 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 514 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 515 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 516 | } |
| 517 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 518 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 519 | // Alternative functions that eliminate randomness and dependency on the local |
| 520 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 521 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 522 | static const uint8 bytes[] = { |
| 523 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 524 | }; |
| 525 | static size_t current_byte = 0; |
| 526 | for (size_t i = 0; i < n; ++i) { |
| 527 | output[i] = bytes[current_byte++]; |
| 528 | current_byte %= arraysize(bytes); |
| 529 | } |
| 530 | } |
| 531 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 532 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 533 | static const uint8 bytes[] = { |
| 534 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 535 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 536 | }; |
| 537 | static size_t current_byte = 0; |
| 538 | for (size_t i = 0; i < n; ++i) { |
| 539 | output[i] = bytes[current_byte++]; |
| 540 | current_byte %= arraysize(bytes); |
| 541 | } |
| 542 | } |
| 543 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 544 | std::string MockGetHostName() { |
| 545 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 546 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 547 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 548 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 549 | template<typename ParentPool> |
| 550 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 551 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 552 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 553 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 554 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 555 | const std::string last_group_name_received() const { |
| 556 | return last_group_name_; |
| 557 | } |
| 558 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 559 | int RequestSocket(const std::string& group_name, |
| 560 | const void* socket_params, |
| 561 | RequestPriority priority, |
| 562 | ClientSocketHandle* handle, |
| 563 | const CompletionCallback& callback, |
| 564 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 565 | last_group_name_ = group_name; |
| 566 | return ERR_IO_PENDING; |
| 567 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 568 | void CancelRequest(const std::string& group_name, |
| 569 | ClientSocketHandle* handle) override {} |
| 570 | void ReleaseSocket(const std::string& group_name, |
| 571 | scoped_ptr<StreamSocket> socket, |
| 572 | int id) override {} |
| 573 | void CloseIdleSockets() override {} |
| 574 | int IdleSocketCount() const override { return 0; } |
| 575 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 576 | return 0; |
| 577 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 578 | LoadState GetLoadState(const std::string& group_name, |
| 579 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 580 | return LOAD_STATE_IDLE; |
| 581 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 582 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 583 | return base::TimeDelta(); |
| 584 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 585 | |
| 586 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 587 | std::string last_group_name_; |
| 588 | }; |
| 589 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 590 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 591 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 592 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 593 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 594 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 595 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 596 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 597 | CaptureGroupNameSSLSocketPool; |
| 598 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 599 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 600 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 601 | HostResolver* host_resolver, |
| 602 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 603 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 604 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 605 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 606 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 607 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 608 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 609 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 610 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 611 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 612 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 613 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 614 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 615 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 616 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 617 | : SSLClientSocketPool(0, |
| 618 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 619 | cert_verifier, |
| 620 | NULL, |
| 621 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 622 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 623 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 624 | std::string(), |
| 625 | NULL, |
| 626 | NULL, |
| 627 | NULL, |
| 628 | NULL, |
| 629 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 630 | NULL) { |
| 631 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 632 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 633 | //----------------------------------------------------------------------------- |
| 634 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 635 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 636 | // configured for common cases. |
| 637 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 638 | if (!auth_challenge) |
| 639 | return false; |
| 640 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 641 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 642 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 643 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 648 | if (!auth_challenge) |
| 649 | return false; |
| 650 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 651 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 652 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 653 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 654 | return true; |
| 655 | } |
| 656 | |
| 657 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 658 | if (!auth_challenge) |
| 659 | return false; |
| 660 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 661 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 662 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 663 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 664 | return true; |
| 665 | } |
| 666 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 667 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 668 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 669 | if (!auth_challenge) |
| 670 | return false; |
| 671 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 672 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 673 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 674 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 675 | return true; |
| 676 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 677 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 678 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 679 | } // namespace |
| 680 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 681 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 682 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 683 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 684 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 685 | } |
| 686 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 687 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[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("HTTP/1.0 200 OK\r\n\r\n"), |
| 690 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 691 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 692 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 693 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 694 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 695 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 696 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 697 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 698 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 699 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 700 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 701 | |
| 702 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 706 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 707 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 708 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 710 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 711 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 712 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 713 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 714 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 715 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 716 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 717 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 721 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 723 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 726 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 727 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 728 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 729 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 730 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 731 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 732 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 736 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 738 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 740 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 741 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 742 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 743 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 745 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 746 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 747 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | // 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] | 751 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 752 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 753 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[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] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 759 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 760 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 761 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 762 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 766 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[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("\n"), |
| 769 | MockRead("\n"), |
| 770 | MockRead("Q"), |
| 771 | MockRead("J"), |
| 772 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 773 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 774 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 775 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 776 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 777 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 778 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 779 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 780 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 781 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 785 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 786 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 787 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [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] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 793 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 794 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 795 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 796 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 797 | } |
| 798 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 799 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 800 | // persistent connection. The response should still terminate since a 204 |
| 801 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 802 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 803 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 804 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 805 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 806 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 807 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 808 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 809 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 810 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 811 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 812 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 813 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 814 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 815 | int64_t response_size = reads_size - strlen(junk); |
| 816 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 817 | } |
| 818 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 819 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 820 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 821 | std::string final_chunk = "0\r\n\r\n"; |
| 822 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 823 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 824 | MockRead data_reads[] = { |
| 825 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 826 | MockRead("5\r\nHello\r\n"), |
| 827 | MockRead("1\r\n"), |
| 828 | MockRead(" \r\n"), |
| 829 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 830 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 831 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 832 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 835 | EXPECT_EQ(OK, out.rv); |
| 836 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 837 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 838 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 839 | int64_t response_size = reads_size - extra_data.size(); |
| 840 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 841 | } |
| 842 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 843 | // Next tests deal with http://crbug.com/56344. |
| 844 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 845 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 846 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 847 | MockRead data_reads[] = { |
| 848 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 849 | MockRead("Content-Length: 10\r\n"), |
| 850 | MockRead("Content-Length: 5\r\n\r\n"), |
| 851 | }; |
| 852 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 853 | arraysize(data_reads)); |
| 854 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 855 | } |
| 856 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 857 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 858 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 859 | MockRead data_reads[] = { |
| 860 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 861 | MockRead("Content-Length: 5\r\n"), |
| 862 | MockRead("Content-Length: 5\r\n\r\n"), |
| 863 | MockRead("Hello"), |
| 864 | }; |
| 865 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 866 | arraysize(data_reads)); |
| 867 | EXPECT_EQ(OK, out.rv); |
| 868 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 869 | EXPECT_EQ("Hello", out.response_data); |
| 870 | } |
| 871 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 872 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 873 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 874 | // More than 2 dupes. |
| 875 | { |
| 876 | MockRead data_reads[] = { |
| 877 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 878 | MockRead("Content-Length: 5\r\n"), |
| 879 | MockRead("Content-Length: 5\r\n"), |
| 880 | MockRead("Content-Length: 5\r\n\r\n"), |
| 881 | MockRead("Hello"), |
| 882 | }; |
| 883 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 884 | arraysize(data_reads)); |
| 885 | EXPECT_EQ(OK, out.rv); |
| 886 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 887 | EXPECT_EQ("Hello", out.response_data); |
| 888 | } |
| 889 | // HTTP/1.0 |
| 890 | { |
| 891 | MockRead data_reads[] = { |
| 892 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 893 | MockRead("Content-Length: 5\r\n"), |
| 894 | MockRead("Content-Length: 5\r\n"), |
| 895 | MockRead("Content-Length: 5\r\n\r\n"), |
| 896 | MockRead("Hello"), |
| 897 | }; |
| 898 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 899 | arraysize(data_reads)); |
| 900 | EXPECT_EQ(OK, out.rv); |
| 901 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 902 | EXPECT_EQ("Hello", out.response_data); |
| 903 | } |
| 904 | // 2 dupes and one mismatched. |
| 905 | { |
| 906 | MockRead data_reads[] = { |
| 907 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 908 | MockRead("Content-Length: 10\r\n"), |
| 909 | MockRead("Content-Length: 10\r\n"), |
| 910 | MockRead("Content-Length: 5\r\n\r\n"), |
| 911 | }; |
| 912 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 913 | arraysize(data_reads)); |
| 914 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 915 | } |
| 916 | } |
| 917 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 918 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 919 | MultipleContentLengthHeadersTransferEncoding) { |
| 920 | MockRead data_reads[] = { |
| 921 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 922 | MockRead("Content-Length: 666\r\n"), |
| 923 | MockRead("Content-Length: 1337\r\n"), |
| 924 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 925 | MockRead("5\r\nHello\r\n"), |
| 926 | MockRead("1\r\n"), |
| 927 | MockRead(" \r\n"), |
| 928 | MockRead("5\r\nworld\r\n"), |
| 929 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 931 | }; |
| 932 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 933 | arraysize(data_reads)); |
| 934 | EXPECT_EQ(OK, out.rv); |
| 935 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 936 | EXPECT_EQ("Hello world", out.response_data); |
| 937 | } |
| 938 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 939 | // Next tests deal with http://crbug.com/98895. |
| 940 | |
| 941 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 942 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 943 | MockRead data_reads[] = { |
| 944 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 945 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 946 | MockRead("Content-Length: 5\r\n\r\n"), |
| 947 | MockRead("Hello"), |
| 948 | }; |
| 949 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 950 | arraysize(data_reads)); |
| 951 | EXPECT_EQ(OK, out.rv); |
| 952 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 953 | EXPECT_EQ("Hello", out.response_data); |
| 954 | } |
| 955 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 956 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 957 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 958 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 959 | MockRead data_reads[] = { |
| 960 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 961 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 962 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 963 | MockRead("Content-Length: 5\r\n\r\n"), |
| 964 | MockRead("Hello"), |
| 965 | }; |
| 966 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 967 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 968 | EXPECT_EQ(OK, out.rv); |
| 969 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 970 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 974 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 975 | MockRead data_reads[] = { |
| 976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 977 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 978 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 979 | MockRead("Content-Length: 5\r\n\r\n"), |
| 980 | MockRead("Hello"), |
| 981 | }; |
| 982 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 983 | arraysize(data_reads)); |
| 984 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 985 | } |
| 986 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 987 | // Checks that two identical Location headers result in no error. |
| 988 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 989 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 990 | MockRead data_reads[] = { |
| 991 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 992 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 993 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 994 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 995 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 996 | }; |
| 997 | |
| 998 | HttpRequestInfo request; |
| 999 | request.method = "GET"; |
| 1000 | request.url = GURL("http://redirect.com/"); |
| 1001 | request.load_flags = 0; |
| 1002 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1003 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1004 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1005 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | |
| 1007 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1008 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1010 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1012 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1013 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1014 | |
| 1015 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1016 | |
| 1017 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1018 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1019 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1020 | std::string url; |
| 1021 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1022 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1023 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1026 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1027 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1030 | MockRead("Location: http://good.com/\r\n"), |
| 1031 | MockRead("Location: http://evil.com/\r\n"), |
| 1032 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1033 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1034 | }; |
| 1035 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1036 | arraysize(data_reads)); |
| 1037 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1038 | } |
| 1039 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1040 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1041 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1042 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1043 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1044 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1045 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1046 | request.load_flags = 0; |
| 1047 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1048 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1049 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1051 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1052 | trans->SetBeforeProxyHeadersSentCallback( |
| 1053 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1054 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1055 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1056 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1057 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1058 | "Host: www.example.org\r\n" |
| 1059 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1060 | }; |
| 1061 | MockRead data_reads1[] = { |
| 1062 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1063 | MockRead("Server: Blah\r\n"), |
| 1064 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1065 | |
| 1066 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1067 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1068 | }; |
| 1069 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1070 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1071 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1072 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1074 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1076 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1077 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1078 | |
| 1079 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1080 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1081 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1082 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1083 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1084 | |
| 1085 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1086 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1087 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1088 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1089 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1090 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1091 | |
| 1092 | std::string server_header; |
| 1093 | void* iter = NULL; |
| 1094 | bool has_server_header = response->headers->EnumerateHeader( |
| 1095 | &iter, "Server", &server_header); |
| 1096 | EXPECT_TRUE(has_server_header); |
| 1097 | EXPECT_EQ("Blah", server_header); |
| 1098 | |
| 1099 | // Reading should give EOF right away, since there is no message body |
| 1100 | // (despite non-zero content-length). |
| 1101 | std::string response_data; |
| 1102 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1103 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1104 | EXPECT_EQ("", response_data); |
| 1105 | } |
| 1106 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1107 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1108 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1109 | |
| 1110 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1111 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1112 | MockRead("hello"), |
| 1113 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1114 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1115 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1116 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1117 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1118 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1119 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1120 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1121 | "hello", "world" |
| 1122 | }; |
| 1123 | |
| 1124 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1125 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1127 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1128 | request.load_flags = 0; |
| 1129 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1130 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1131 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1133 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1135 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1136 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1137 | |
| 1138 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1139 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1140 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1141 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1142 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1143 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1144 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1146 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1147 | |
| 1148 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1149 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1150 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1151 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1155 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1156 | ScopedVector<UploadElementReader> element_readers; |
| 1157 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1158 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1159 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1160 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | request.method = "POST"; |
| 1162 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1163 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | request.load_flags = 0; |
| 1165 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1166 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1167 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1168 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1169 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1171 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1172 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1173 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1174 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1175 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1176 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1179 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1183 | |
| 1184 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1185 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1186 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1187 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1188 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1189 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1190 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1191 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1192 | |
| 1193 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1194 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1195 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1196 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1197 | } |
| 1198 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1199 | // This test is almost the same as Ignores100 above, but the response contains |
| 1200 | // 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] | 1201 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1202 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1203 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1204 | request.method = "GET"; |
| 1205 | request.url = GURL("http://www.foo.com/"); |
| 1206 | request.load_flags = 0; |
| 1207 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1208 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1209 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1211 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1212 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1213 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1214 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1215 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1217 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1218 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1219 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1221 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1223 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1224 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1225 | |
| 1226 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1227 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1228 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1229 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1230 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1231 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1232 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1233 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1234 | |
| 1235 | std::string response_data; |
| 1236 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1237 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1238 | EXPECT_EQ("hello world", response_data); |
| 1239 | } |
| 1240 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1241 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1242 | HttpRequestInfo request; |
| 1243 | request.method = "POST"; |
| 1244 | request.url = GURL("http://www.foo.com/"); |
| 1245 | request.load_flags = 0; |
| 1246 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1247 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1248 | scoped_ptr<HttpTransaction> trans( |
| 1249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1250 | |
| 1251 | MockRead data_reads[] = { |
| 1252 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1253 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1254 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1255 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1256 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1257 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1258 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1259 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1260 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1261 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1262 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1263 | rv = callback.WaitForResult(); |
| 1264 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1265 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1266 | std::string response_data; |
| 1267 | rv = ReadTransaction(trans.get(), &response_data); |
| 1268 | EXPECT_EQ(OK, rv); |
| 1269 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1270 | } |
| 1271 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1272 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1273 | HttpRequestInfo request; |
| 1274 | request.method = "POST"; |
| 1275 | request.url = GURL("http://www.foo.com/"); |
| 1276 | request.load_flags = 0; |
| 1277 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1278 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1279 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1281 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1282 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1283 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1284 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1288 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1290 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1292 | |
| 1293 | rv = callback.WaitForResult(); |
| 1294 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1295 | } |
| 1296 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1297 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1298 | const MockWrite* write_failure, |
| 1299 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1300 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | request.method = "GET"; |
| 1302 | request.url = GURL("http://www.foo.com/"); |
| 1303 | request.load_flags = 0; |
| 1304 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1305 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1306 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1307 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1308 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1309 | // Written data for successfully sending both requests. |
| 1310 | MockWrite data1_writes[] = { |
| 1311 | MockWrite("GET / HTTP/1.1\r\n" |
| 1312 | "Host: www.foo.com\r\n" |
| 1313 | "Connection: keep-alive\r\n\r\n"), |
| 1314 | MockWrite("GET / HTTP/1.1\r\n" |
| 1315 | "Host: www.foo.com\r\n" |
| 1316 | "Connection: keep-alive\r\n\r\n") |
| 1317 | }; |
| 1318 | |
| 1319 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1321 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1322 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1323 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1325 | |
| 1326 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1327 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1328 | data1_writes[1] = *write_failure; |
| 1329 | } else { |
| 1330 | ASSERT_TRUE(read_failure); |
| 1331 | data1_reads[2] = *read_failure; |
| 1332 | } |
| 1333 | |
| 1334 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1335 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | |
| 1338 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1339 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1340 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1341 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1343 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1344 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1346 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | "hello", "world" |
| 1348 | }; |
| 1349 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1350 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1352 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1354 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1355 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1357 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
| 1360 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1361 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1363 | LoadTimingInfo load_timing_info; |
| 1364 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1365 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1366 | if (i == 0) { |
| 1367 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1368 | } else { |
| 1369 | // The second request should be using a new socket. |
| 1370 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1371 | } |
| 1372 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1373 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1374 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1376 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
| 1379 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1380 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1381 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1382 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | } |
| 1384 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1385 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1386 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1387 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1388 | const MockRead* read_failure, |
| 1389 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1390 | HttpRequestInfo request; |
| 1391 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1392 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1393 | request.load_flags = 0; |
| 1394 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1395 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1396 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1397 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1398 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1399 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1400 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1401 | if (use_spdy) { |
| 1402 | ssl1.SetNextProto(GetParam()); |
| 1403 | ssl2.SetNextProto(GetParam()); |
| 1404 | } |
| 1405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1407 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1408 | // SPDY versions of the request and response. |
| 1409 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1410 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1411 | scoped_ptr<SpdyFrame> spdy_response( |
| 1412 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1413 | scoped_ptr<SpdyFrame> spdy_data( |
| 1414 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1415 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1416 | // HTTP/1.1 versions of the request and response. |
| 1417 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1418 | "Host: www.foo.com\r\n" |
| 1419 | "Connection: keep-alive\r\n\r\n"; |
| 1420 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1421 | const char kHttpData[] = "hello"; |
| 1422 | |
| 1423 | std::vector<MockRead> data1_reads; |
| 1424 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1425 | if (write_failure) { |
| 1426 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1427 | data1_writes.push_back(*write_failure); |
| 1428 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1429 | } else { |
| 1430 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1431 | if (use_spdy) { |
| 1432 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1433 | } else { |
| 1434 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1435 | } |
| 1436 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1437 | } |
| 1438 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1439 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1440 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1442 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1443 | std::vector<MockRead> data2_reads; |
| 1444 | std::vector<MockWrite> data2_writes; |
| 1445 | |
| 1446 | if (use_spdy) { |
| 1447 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1448 | |
| 1449 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1450 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1451 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1452 | } else { |
| 1453 | data2_writes.push_back( |
| 1454 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1455 | |
| 1456 | data2_reads.push_back( |
| 1457 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1458 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1459 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1460 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1461 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1462 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1463 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1464 | |
| 1465 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1466 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1467 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1468 | session->GetNextProtos(&ssl_config.next_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1469 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1470 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1471 | // Wait for the preconnect to complete. |
| 1472 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1473 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1474 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1475 | |
| 1476 | // Make the request. |
| 1477 | TestCompletionCallback callback; |
| 1478 | |
| 1479 | scoped_ptr<HttpTransaction> trans( |
| 1480 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1481 | |
| 1482 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1483 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1484 | |
| 1485 | rv = callback.WaitForResult(); |
| 1486 | EXPECT_EQ(OK, rv); |
| 1487 | |
| 1488 | LoadTimingInfo load_timing_info; |
| 1489 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1490 | TestLoadTimingNotReused( |
| 1491 | load_timing_info, |
| 1492 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1493 | |
| 1494 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1495 | ASSERT_TRUE(response != NULL); |
| 1496 | |
| 1497 | EXPECT_TRUE(response->headers.get() != NULL); |
| 1498 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1499 | |
| 1500 | std::string response_data; |
| 1501 | rv = ReadTransaction(trans.get(), &response_data); |
| 1502 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1503 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | } |
| 1505 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1506 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1507 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1508 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1509 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1510 | } |
| 1511 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1512 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1513 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1514 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1515 | } |
| 1516 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1517 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1518 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1519 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1520 | } |
| 1521 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1522 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1523 | // if the socket was a reused keep alive socket. |
| 1524 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1525 | MockRead read_failure(SYNCHRONOUS, |
| 1526 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1527 | "Connection: Keep-Alive\r\n" |
| 1528 | "Content-Length: 6\r\n\r\n" |
| 1529 | "Pickle"); |
| 1530 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1531 | } |
| 1532 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1533 | TEST_P(HttpNetworkTransactionTest, |
| 1534 | PreconnectErrorNotConnectedOnWrite) { |
| 1535 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1536 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1540 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1541 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1545 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1546 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1547 | } |
| 1548 | |
| 1549 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1550 | MockRead read_failure(ASYNC, OK); // EOF |
| 1551 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1552 | } |
| 1553 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1554 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1555 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1556 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1557 | MockRead read_failure(SYNCHRONOUS, |
| 1558 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1559 | "Connection: Keep-Alive\r\n" |
| 1560 | "Content-Length: 6\r\n\r\n" |
| 1561 | "Pickle"); |
| 1562 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1563 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1564 | } |
| 1565 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1566 | TEST_P(HttpNetworkTransactionTest, |
| 1567 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1568 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1569 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1570 | } |
| 1571 | |
| 1572 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1573 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1574 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1575 | } |
| 1576 | |
| 1577 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1578 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1579 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1580 | } |
| 1581 | |
| 1582 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1583 | MockRead read_failure(ASYNC, OK); // EOF |
| 1584 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1585 | } |
| 1586 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1587 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1588 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1589 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1590 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1591 | request.load_flags = 0; |
| 1592 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1593 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1594 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1596 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1597 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1598 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1599 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1600 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1601 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1602 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1603 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1606 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1608 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1610 | |
| 1611 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1612 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1613 | |
| 1614 | IPEndPoint endpoint; |
| 1615 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1616 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | // What do various browsers do when the server closes a non-keepalive |
| 1620 | // connection without sending any response header or body? |
| 1621 | // |
| 1622 | // IE7: error page |
| 1623 | // Safari 3.1.2 (Windows): error page |
| 1624 | // Firefox 3.0.1: blank page |
| 1625 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1626 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1627 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1628 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1629 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1630 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1631 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1632 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1633 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1634 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1635 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1636 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1637 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1638 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1639 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1640 | // Test that network access can be deferred and resumed. |
| 1641 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1642 | HttpRequestInfo request; |
| 1643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1644 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1645 | request.load_flags = 0; |
| 1646 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1647 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1648 | scoped_ptr<HttpTransaction> trans( |
| 1649 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1650 | |
| 1651 | // Defer on OnBeforeNetworkStart. |
| 1652 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1653 | trans->SetBeforeNetworkStartCallback( |
| 1654 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1655 | base::Unretained(&net_start_handler))); |
| 1656 | |
| 1657 | MockRead data_reads[] = { |
| 1658 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1659 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1660 | MockRead("hello"), |
| 1661 | MockRead(SYNCHRONOUS, 0), |
| 1662 | }; |
| 1663 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1665 | |
| 1666 | TestCompletionCallback callback; |
| 1667 | |
| 1668 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1669 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1670 | base::MessageLoop::current()->RunUntilIdle(); |
| 1671 | |
| 1672 | // Should have deferred for network start. |
| 1673 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1674 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1675 | |
| 1676 | trans->ResumeNetworkStart(); |
| 1677 | rv = callback.WaitForResult(); |
| 1678 | EXPECT_EQ(OK, rv); |
| 1679 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1680 | |
| 1681 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1682 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1683 | if (rv == ERR_IO_PENDING) |
| 1684 | rv = callback.WaitForResult(); |
| 1685 | EXPECT_EQ(5, rv); |
| 1686 | trans.reset(); |
| 1687 | } |
| 1688 | |
| 1689 | // Test that network use can be deferred and canceled. |
| 1690 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1691 | HttpRequestInfo request; |
| 1692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1693 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1694 | request.load_flags = 0; |
| 1695 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1696 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1697 | scoped_ptr<HttpTransaction> trans( |
| 1698 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1699 | |
| 1700 | // Defer on OnBeforeNetworkStart. |
| 1701 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1702 | trans->SetBeforeNetworkStartCallback( |
| 1703 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1704 | base::Unretained(&net_start_handler))); |
| 1705 | |
| 1706 | TestCompletionCallback callback; |
| 1707 | |
| 1708 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1709 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1710 | base::MessageLoop::current()->RunUntilIdle(); |
| 1711 | |
| 1712 | // Should have deferred for network start. |
| 1713 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1714 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1715 | } |
| 1716 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1717 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1718 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1719 | // destructor in such situations. |
| 1720 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1721 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1722 | HttpRequestInfo request; |
| 1723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1724 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1725 | request.load_flags = 0; |
| 1726 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1727 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1730 | |
| 1731 | MockRead data_reads[] = { |
| 1732 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1733 | MockRead("Connection: keep-alive\r\n"), |
| 1734 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1735 | MockRead("hello"), |
| 1736 | MockRead(SYNCHRONOUS, 0), |
| 1737 | }; |
| 1738 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1739 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1740 | |
| 1741 | TestCompletionCallback callback; |
| 1742 | |
| 1743 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1744 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1745 | |
| 1746 | rv = callback.WaitForResult(); |
| 1747 | EXPECT_EQ(OK, rv); |
| 1748 | |
| 1749 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1750 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1751 | if (rv == ERR_IO_PENDING) |
| 1752 | rv = callback.WaitForResult(); |
| 1753 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1754 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1755 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1756 | |
| 1757 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1758 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1759 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1760 | } |
| 1761 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1762 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1763 | HttpRequestInfo request; |
| 1764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1765 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1766 | request.load_flags = 0; |
| 1767 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1768 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1769 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1771 | |
| 1772 | MockRead data_reads[] = { |
| 1773 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1774 | MockRead("Connection: keep-alive\r\n"), |
| 1775 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1776 | MockRead(SYNCHRONOUS, 0), |
| 1777 | }; |
| 1778 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1780 | |
| 1781 | TestCompletionCallback callback; |
| 1782 | |
| 1783 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1784 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1785 | |
| 1786 | rv = callback.WaitForResult(); |
| 1787 | EXPECT_EQ(OK, rv); |
| 1788 | |
| 1789 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1790 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1791 | if (rv == ERR_IO_PENDING) |
| 1792 | rv = callback.WaitForResult(); |
| 1793 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1794 | |
| 1795 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1796 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1797 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1798 | } |
| 1799 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1800 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1801 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1802 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1803 | HttpRequestInfo request; |
| 1804 | request.method = "GET"; |
| 1805 | request.url = GURL("http://www.foo.com/"); |
| 1806 | request.load_flags = 0; |
| 1807 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1808 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1809 | session_deps_.net_log = &net_log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1810 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1811 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1812 | // Note that because all these reads happen in the same |
| 1813 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1814 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1815 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1816 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1817 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1818 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1819 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1820 | "Content-Length: 0\r\n\r\n"), |
| 1821 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1822 | "Content-Length: 5\r\n\r\n" |
| 1823 | "hello"), |
| 1824 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1825 | "Content-Length: 0\r\n\r\n"), |
| 1826 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1827 | "Content-Length: 5\r\n\r\n" |
| 1828 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1829 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1830 | MockRead("hello"), |
| 1831 | }; |
| 1832 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1833 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1834 | |
| 1835 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1836 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1837 | }; |
| 1838 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1839 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1840 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1841 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1842 | std::string response_lines[kNumUnreadBodies]; |
| 1843 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1844 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1845 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1846 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1847 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1848 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1851 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1852 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1853 | |
| 1854 | rv = callback.WaitForResult(); |
| 1855 | EXPECT_EQ(OK, rv); |
| 1856 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1857 | LoadTimingInfo load_timing_info; |
| 1858 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1859 | if (i == 0) { |
| 1860 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1861 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1862 | } else { |
| 1863 | TestLoadTimingReused(load_timing_info); |
| 1864 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1865 | } |
| 1866 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1867 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1868 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1869 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1870 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1871 | response_lines[i] = response->headers->GetStatusLine(); |
| 1872 | |
| 1873 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1874 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1875 | |
| 1876 | const char* const kStatusLines[] = { |
| 1877 | "HTTP/1.1 204 No Content", |
| 1878 | "HTTP/1.1 205 Reset Content", |
| 1879 | "HTTP/1.1 304 Not Modified", |
| 1880 | "HTTP/1.1 302 Found", |
| 1881 | "HTTP/1.1 302 Found", |
| 1882 | "HTTP/1.1 301 Moved Permanently", |
| 1883 | "HTTP/1.1 301 Moved Permanently", |
| 1884 | }; |
| 1885 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1886 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1887 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1888 | |
| 1889 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1890 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1892 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1893 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1894 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1895 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1897 | rv = callback.WaitForResult(); |
| 1898 | EXPECT_EQ(OK, rv); |
| 1899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1900 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1901 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1902 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1903 | std::string response_data; |
| 1904 | rv = ReadTransaction(trans.get(), &response_data); |
| 1905 | EXPECT_EQ(OK, rv); |
| 1906 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1907 | } |
| 1908 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1909 | // Test the request-challenge-retry sequence for basic auth. |
| 1910 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1911 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1912 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1913 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1914 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1915 | request.load_flags = 0; |
| 1916 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1917 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1918 | session_deps_.net_log = &log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 1919 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1920 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1921 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1922 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1923 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1924 | MockWrite( |
| 1925 | "GET / HTTP/1.1\r\n" |
| 1926 | "Host: www.example.org\r\n" |
| 1927 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1928 | }; |
| 1929 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1930 | MockRead data_reads1[] = { |
| 1931 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1932 | // Give a couple authenticate options (only the middle one is actually |
| 1933 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1934 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1935 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1936 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1937 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1938 | // Large content-length -- won't matter, as connection will be reset. |
| 1939 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1940 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1941 | }; |
| 1942 | |
| 1943 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1944 | // be issuing -- the final header line contains the credentials. |
| 1945 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1946 | MockWrite( |
| 1947 | "GET / HTTP/1.1\r\n" |
| 1948 | "Host: www.example.org\r\n" |
| 1949 | "Connection: keep-alive\r\n" |
| 1950 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1951 | }; |
| 1952 | |
| 1953 | // Lastly, the server responds with the actual content. |
| 1954 | MockRead data_reads2[] = { |
| 1955 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1957 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1959 | }; |
| 1960 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1961 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1962 | data_writes1, arraysize(data_writes1)); |
| 1963 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1964 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1965 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1966 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1968 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1970 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1971 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1972 | |
| 1973 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1974 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1975 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1976 | LoadTimingInfo load_timing_info1; |
| 1977 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 1978 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1979 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1980 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 1981 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 1982 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1983 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 1984 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1986 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 1987 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1989 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1991 | rv = trans->RestartWithAuth( |
| 1992 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1994 | |
| 1995 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1996 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1997 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1998 | LoadTimingInfo load_timing_info2; |
| 1999 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2000 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2001 | // The load timing after restart should have a new socket ID, and times after |
| 2002 | // those of the first load timing. |
| 2003 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2004 | load_timing_info2.connect_timing.connect_start); |
| 2005 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2006 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2007 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2008 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2009 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2010 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2011 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2012 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2013 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2014 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2015 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2016 | } |
| 2017 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2018 | // Test the request-challenge-retry sequence for basic auth. |
| 2019 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2020 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2021 | HttpRequestInfo request; |
| 2022 | request.method = "GET"; |
| 2023 | request.url = GURL("http://www.example.org/"); |
| 2024 | request.load_flags = 0; |
| 2025 | |
| 2026 | TestNetLog log; |
| 2027 | MockHostResolver* resolver = new MockHostResolver(); |
| 2028 | session_deps_.net_log = &log; |
| 2029 | session_deps_.host_resolver.reset(resolver); |
| 2030 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2031 | scoped_ptr<HttpTransaction> trans( |
| 2032 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2033 | |
| 2034 | resolver->rules()->ClearRules(); |
| 2035 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2036 | |
| 2037 | MockWrite data_writes1[] = { |
| 2038 | MockWrite("GET / HTTP/1.1\r\n" |
| 2039 | "Host: www.example.org\r\n" |
| 2040 | "Connection: keep-alive\r\n\r\n"), |
| 2041 | }; |
| 2042 | |
| 2043 | MockRead data_reads1[] = { |
| 2044 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2045 | // Give a couple authenticate options (only the middle one is actually |
| 2046 | // supported). |
| 2047 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2048 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2049 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2050 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2051 | // Large content-length -- won't matter, as connection will be reset. |
| 2052 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2053 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2054 | }; |
| 2055 | |
| 2056 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2057 | // be issuing -- the final header line contains the credentials. |
| 2058 | MockWrite data_writes2[] = { |
| 2059 | MockWrite("GET / HTTP/1.1\r\n" |
| 2060 | "Host: www.example.org\r\n" |
| 2061 | "Connection: keep-alive\r\n" |
| 2062 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2063 | }; |
| 2064 | |
| 2065 | // Lastly, the server responds with the actual content. |
| 2066 | MockRead data_reads2[] = { |
| 2067 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2068 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2069 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2070 | }; |
| 2071 | |
| 2072 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2073 | data_writes1, arraysize(data_writes1)); |
| 2074 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2075 | data_writes2, arraysize(data_writes2)); |
| 2076 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2077 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2078 | |
| 2079 | TestCompletionCallback callback1; |
| 2080 | |
| 2081 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2082 | BoundNetLog()))); |
| 2083 | |
| 2084 | LoadTimingInfo load_timing_info1; |
| 2085 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2086 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2087 | |
| 2088 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2089 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2090 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2091 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2092 | |
| 2093 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2094 | ASSERT_TRUE(response); |
| 2095 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2096 | |
| 2097 | IPEndPoint endpoint; |
| 2098 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2099 | ASSERT_FALSE(endpoint.address().empty()); |
| 2100 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2101 | |
| 2102 | resolver->rules()->ClearRules(); |
| 2103 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2104 | |
| 2105 | TestCompletionCallback callback2; |
| 2106 | |
| 2107 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2108 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2109 | |
| 2110 | LoadTimingInfo load_timing_info2; |
| 2111 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2112 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2113 | // The load timing after restart should have a new socket ID, and times after |
| 2114 | // those of the first load timing. |
| 2115 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2116 | load_timing_info2.connect_timing.connect_start); |
| 2117 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2118 | |
| 2119 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2120 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2121 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2122 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2123 | |
| 2124 | response = trans->GetResponseInfo(); |
| 2125 | ASSERT_TRUE(response); |
| 2126 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2127 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2128 | |
| 2129 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2130 | ASSERT_FALSE(endpoint.address().empty()); |
| 2131 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2132 | } |
| 2133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2134 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2135 | HttpRequestInfo request; |
| 2136 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2137 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2138 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2139 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2140 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2141 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2142 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2143 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2144 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2145 | MockWrite( |
| 2146 | "GET / HTTP/1.1\r\n" |
| 2147 | "Host: www.example.org\r\n" |
| 2148 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2149 | }; |
| 2150 | |
| 2151 | MockRead data_reads[] = { |
| 2152 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2153 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2154 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2155 | // Large content-length -- won't matter, as connection will be reset. |
| 2156 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2157 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2158 | }; |
| 2159 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2160 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2161 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2162 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2163 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2165 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2167 | |
| 2168 | rv = callback.WaitForResult(); |
| 2169 | EXPECT_EQ(0, rv); |
| 2170 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2171 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2172 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2173 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2174 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2175 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2176 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2177 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2178 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2179 | } |
| 2180 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2181 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2182 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2183 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2184 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2185 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2186 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2187 | request.load_flags = 0; |
| 2188 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2189 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2190 | session_deps_.net_log = &log; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2191 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2192 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2193 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2194 | MockWrite( |
| 2195 | "GET / HTTP/1.1\r\n" |
| 2196 | "Host: www.example.org\r\n" |
| 2197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2199 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2200 | // be issuing -- the final header line contains the credentials. |
| 2201 | MockWrite( |
| 2202 | "GET / HTTP/1.1\r\n" |
| 2203 | "Host: www.example.org\r\n" |
| 2204 | "Connection: keep-alive\r\n" |
| 2205 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2206 | }; |
| 2207 | |
| 2208 | MockRead data_reads1[] = { |
| 2209 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2210 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2211 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2212 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2213 | MockRead("Unauthorized\r\n"), |
| 2214 | |
| 2215 | // Lastly, the server responds with the actual content. |
| 2216 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2217 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2218 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2219 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2220 | }; |
| 2221 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2222 | // If there is a regression where we disconnect a Keep-Alive |
| 2223 | // connection during an auth roundtrip, we'll end up reading this. |
| 2224 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2225 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2226 | }; |
| 2227 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2228 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2229 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2230 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2231 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2232 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2233 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2235 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2236 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2237 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2239 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2240 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2241 | |
| 2242 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2243 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2244 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2245 | LoadTimingInfo load_timing_info1; |
| 2246 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2247 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2248 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2249 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2250 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2251 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2253 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2255 | rv = trans->RestartWithAuth( |
| 2256 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2257 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2258 | |
| 2259 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2260 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2261 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2262 | LoadTimingInfo load_timing_info2; |
| 2263 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2264 | TestLoadTimingReused(load_timing_info2); |
| 2265 | // The load timing after restart should have the same socket ID, and times |
| 2266 | // those of the first load timing. |
| 2267 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2268 | load_timing_info2.send_start); |
| 2269 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2270 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2271 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2272 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2273 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2274 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2275 | |
| 2276 | std::string response_data; |
| 2277 | rv = ReadTransaction(trans.get(), &response_data); |
| 2278 | EXPECT_EQ(OK, rv); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2279 | |
| 2280 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2281 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2282 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2283 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2287 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2288 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2289 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2290 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2291 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2292 | request.load_flags = 0; |
| 2293 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2294 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2295 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2296 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2297 | MockWrite( |
| 2298 | "GET / HTTP/1.1\r\n" |
| 2299 | "Host: www.example.org\r\n" |
| 2300 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2301 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2302 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2303 | // be issuing -- the final header line contains the credentials. |
| 2304 | MockWrite( |
| 2305 | "GET / HTTP/1.1\r\n" |
| 2306 | "Host: www.example.org\r\n" |
| 2307 | "Connection: keep-alive\r\n" |
| 2308 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2309 | }; |
| 2310 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2311 | MockRead data_reads1[] = { |
| 2312 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2313 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2314 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2315 | |
| 2316 | // Lastly, the server responds with the actual content. |
| 2317 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2318 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2319 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2320 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2321 | }; |
| 2322 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2323 | // An incorrect reconnect would cause this to be read. |
| 2324 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2325 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2326 | }; |
| 2327 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2328 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2329 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2330 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2331 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2332 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2333 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2335 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2336 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2337 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2338 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2339 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2341 | |
| 2342 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2343 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2344 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2346 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2347 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2349 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2351 | rv = trans->RestartWithAuth( |
| 2352 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2354 | |
| 2355 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2356 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2357 | |
| 2358 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2359 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2360 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2361 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2365 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2366 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2367 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2369 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2370 | request.load_flags = 0; |
| 2371 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2372 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2373 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2374 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2375 | MockWrite( |
| 2376 | "GET / HTTP/1.1\r\n" |
| 2377 | "Host: www.example.org\r\n" |
| 2378 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2379 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2380 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2381 | // be issuing -- the final header line contains the credentials. |
| 2382 | MockWrite( |
| 2383 | "GET / HTTP/1.1\r\n" |
| 2384 | "Host: www.example.org\r\n" |
| 2385 | "Connection: keep-alive\r\n" |
| 2386 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2387 | }; |
| 2388 | |
| 2389 | // Respond with 5 kb of response body. |
| 2390 | std::string large_body_string("Unauthorized"); |
| 2391 | large_body_string.append(5 * 1024, ' '); |
| 2392 | large_body_string.append("\r\n"); |
| 2393 | |
| 2394 | MockRead data_reads1[] = { |
| 2395 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2396 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2397 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2398 | // 5134 = 12 + 5 * 1024 + 2 |
| 2399 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2400 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2401 | |
| 2402 | // Lastly, the server responds with the actual content. |
| 2403 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2404 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2405 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2406 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2407 | }; |
| 2408 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2409 | // An incorrect reconnect would cause this to be read. |
| 2410 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2411 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2412 | }; |
| 2413 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2414 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2415 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2416 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2417 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2418 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2419 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2421 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2422 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2423 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2425 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2426 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2427 | |
| 2428 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2429 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2430 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2431 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2432 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2433 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2435 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2437 | rv = trans->RestartWithAuth( |
| 2438 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2440 | |
| 2441 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2442 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2443 | |
| 2444 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2445 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2446 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2447 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2451 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2452 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2453 | HttpRequestInfo request; |
| 2454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2455 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2456 | request.load_flags = 0; |
| 2457 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2458 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2459 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2460 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2461 | MockWrite( |
| 2462 | "GET / HTTP/1.1\r\n" |
| 2463 | "Host: www.example.org\r\n" |
| 2464 | "Connection: keep-alive\r\n\r\n"), |
| 2465 | // This simulates the seemingly successful write to a closed connection |
| 2466 | // if the bug is not fixed. |
| 2467 | MockWrite( |
| 2468 | "GET / HTTP/1.1\r\n" |
| 2469 | "Host: www.example.org\r\n" |
| 2470 | "Connection: keep-alive\r\n" |
| 2471 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2472 | }; |
| 2473 | |
| 2474 | MockRead data_reads1[] = { |
| 2475 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2476 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2477 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2478 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2479 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2480 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2481 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2482 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2483 | }; |
| 2484 | |
| 2485 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2486 | // be issuing -- the final header line contains the credentials. |
| 2487 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2488 | MockWrite( |
| 2489 | "GET / HTTP/1.1\r\n" |
| 2490 | "Host: www.example.org\r\n" |
| 2491 | "Connection: keep-alive\r\n" |
| 2492 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2493 | }; |
| 2494 | |
| 2495 | // Lastly, the server responds with the actual content. |
| 2496 | MockRead data_reads2[] = { |
| 2497 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2498 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2499 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2500 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2501 | }; |
| 2502 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2503 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2504 | data_writes1, arraysize(data_writes1)); |
| 2505 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2506 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2507 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2508 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2510 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2511 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2512 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2513 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2514 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2515 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2516 | |
| 2517 | rv = callback1.WaitForResult(); |
| 2518 | EXPECT_EQ(OK, rv); |
| 2519 | |
| 2520 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2521 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2522 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2524 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2526 | rv = trans->RestartWithAuth( |
| 2527 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2528 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2529 | |
| 2530 | rv = callback2.WaitForResult(); |
| 2531 | EXPECT_EQ(OK, rv); |
| 2532 | |
| 2533 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2534 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2535 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2536 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2537 | } |
| 2538 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2539 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2540 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2541 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2542 | HttpRequestInfo request; |
| 2543 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2544 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2545 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2546 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2547 | |
| 2548 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2549 | session_deps_.proxy_service = |
| 2550 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2551 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2552 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2553 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2554 | |
| 2555 | // Since we have proxy, should try to establish tunnel. |
| 2556 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2557 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2558 | "Host: www.example.org\r\n" |
| 2559 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2560 | }; |
| 2561 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2562 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2563 | // connection. |
| 2564 | MockRead data_reads1[] = { |
| 2565 | // No credentials. |
| 2566 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2567 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2568 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2569 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2570 | // Since the first connection couldn't be reused, need to establish another |
| 2571 | // once given credentials. |
| 2572 | MockWrite data_writes2[] = { |
| 2573 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2574 | // be issuing -- the final header line contains the credentials. |
| 2575 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2576 | "Host: www.example.org\r\n" |
| 2577 | "Proxy-Connection: keep-alive\r\n" |
| 2578 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2579 | |
| 2580 | MockWrite("GET / HTTP/1.1\r\n" |
| 2581 | "Host: www.example.org\r\n" |
| 2582 | "Connection: keep-alive\r\n\r\n"), |
| 2583 | }; |
| 2584 | |
| 2585 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2586 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2587 | |
| 2588 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2589 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2590 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2591 | MockRead(SYNCHRONOUS, "hello"), |
| 2592 | }; |
| 2593 | |
| 2594 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2595 | data_writes1, arraysize(data_writes1)); |
| 2596 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2597 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2598 | data_writes2, arraysize(data_writes2)); |
| 2599 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2600 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2601 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2602 | |
| 2603 | TestCompletionCallback callback1; |
| 2604 | |
| 2605 | scoped_ptr<HttpTransaction> trans( |
| 2606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2607 | |
| 2608 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2610 | |
| 2611 | rv = callback1.WaitForResult(); |
| 2612 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2613 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2614 | log.GetEntries(&entries); |
| 2615 | size_t pos = ExpectLogContainsSomewhere( |
| 2616 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2617 | NetLog::PHASE_NONE); |
| 2618 | ExpectLogContainsSomewhere( |
| 2619 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2620 | NetLog::PHASE_NONE); |
| 2621 | |
| 2622 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2623 | ASSERT_TRUE(response != NULL); |
| 2624 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2625 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2626 | EXPECT_EQ(407, response->headers->response_code()); |
| 2627 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2628 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2629 | |
| 2630 | LoadTimingInfo load_timing_info; |
| 2631 | // CONNECT requests and responses are handled at the connect job level, so |
| 2632 | // the transaction does not yet have a connection. |
| 2633 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2634 | |
| 2635 | TestCompletionCallback callback2; |
| 2636 | |
| 2637 | rv = |
| 2638 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2640 | |
| 2641 | rv = callback2.WaitForResult(); |
| 2642 | EXPECT_EQ(OK, rv); |
| 2643 | |
| 2644 | response = trans->GetResponseInfo(); |
| 2645 | ASSERT_TRUE(response != NULL); |
| 2646 | |
| 2647 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2648 | EXPECT_EQ(200, response->headers->response_code()); |
| 2649 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2650 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2651 | |
| 2652 | // The password prompt info should not be set. |
| 2653 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2654 | |
| 2655 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2656 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2657 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2658 | |
| 2659 | trans.reset(); |
| 2660 | session->CloseAllConnections(); |
| 2661 | } |
| 2662 | |
| 2663 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2664 | // that requires a restart when setting up an SSL tunnel. |
| 2665 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2666 | HttpRequestInfo request; |
| 2667 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2668 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2669 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2670 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2671 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2672 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2673 | session_deps_.proxy_service = |
| 2674 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2675 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2676 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2677 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2678 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2679 | // Since we have proxy, should try to establish tunnel. |
| 2680 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2681 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2682 | "Host: www.example.org\r\n" |
| 2683 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2684 | }; |
| 2685 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2686 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2687 | // connection. |
| 2688 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2689 | // No credentials. |
| 2690 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2691 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2692 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2693 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2694 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2695 | MockWrite data_writes2[] = { |
| 2696 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2697 | // be issuing -- the final header line contains the credentials. |
| 2698 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2699 | "Host: www.example.org\r\n" |
| 2700 | "Proxy-Connection: keep-alive\r\n" |
| 2701 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2702 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2703 | MockWrite("GET / HTTP/1.1\r\n" |
| 2704 | "Host: www.example.org\r\n" |
| 2705 | "Connection: keep-alive\r\n\r\n"), |
| 2706 | }; |
| 2707 | |
| 2708 | MockRead data_reads2[] = { |
| 2709 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2710 | |
| 2711 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2712 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2713 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2714 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2715 | }; |
| 2716 | |
| 2717 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2718 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2719 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2720 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2721 | data_writes2, arraysize(data_writes2)); |
| 2722 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2723 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2726 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2727 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2728 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2731 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2733 | |
| 2734 | rv = callback1.WaitForResult(); |
| 2735 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2736 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2737 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2738 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2739 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2740 | NetLog::PHASE_NONE); |
| 2741 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2742 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2743 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2744 | NetLog::PHASE_NONE); |
| 2745 | |
| 2746 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2747 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2748 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2749 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2750 | EXPECT_EQ(407, response->headers->response_code()); |
| 2751 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2752 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2753 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2754 | LoadTimingInfo load_timing_info; |
| 2755 | // CONNECT requests and responses are handled at the connect job level, so |
| 2756 | // the transaction does not yet have a connection. |
| 2757 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2758 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2759 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2761 | rv = trans->RestartWithAuth( |
| 2762 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2763 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2764 | |
| 2765 | rv = callback2.WaitForResult(); |
| 2766 | EXPECT_EQ(OK, rv); |
| 2767 | |
| 2768 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2769 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2770 | |
| 2771 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2772 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2773 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2774 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2775 | |
| 2776 | // The password prompt info should not be set. |
| 2777 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2778 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2779 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2780 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2781 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2782 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2783 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2784 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2785 | } |
| 2786 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2787 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2788 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2789 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2790 | HttpRequestInfo request; |
| 2791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2792 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2793 | // Ensure that proxy authentication is attempted even |
| 2794 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2795 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2796 | |
| 2797 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2798 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2799 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2800 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2801 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2802 | |
| 2803 | scoped_ptr<HttpTransaction> trans( |
| 2804 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2805 | |
| 2806 | // Since we have proxy, should try to establish tunnel. |
| 2807 | MockWrite data_writes1[] = { |
| 2808 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2809 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2810 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2811 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2812 | |
| 2813 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2814 | // be issuing -- the final header line contains the credentials. |
| 2815 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2816 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2817 | "Host: www.example.org\r\n" |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2818 | "Proxy-Connection: keep-alive\r\n" |
| 2819 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2820 | }; |
| 2821 | |
| 2822 | // The proxy responds to the connect with a 407, using a persistent |
| 2823 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2824 | MockRead data_reads1[] = { |
| 2825 | // No credentials. |
| 2826 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2827 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2828 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2829 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2830 | MockRead("0123456789"), |
| 2831 | |
| 2832 | // Wrong credentials (wrong password). |
| 2833 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2834 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2835 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2836 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2837 | // No response body because the test stops reading here. |
| 2838 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2839 | }; |
| 2840 | |
| 2841 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2842 | data_writes1, arraysize(data_writes1)); |
| 2843 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2844 | |
| 2845 | TestCompletionCallback callback1; |
| 2846 | |
| 2847 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2848 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2849 | |
| 2850 | rv = callback1.WaitForResult(); |
| 2851 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2852 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2853 | log.GetEntries(&entries); |
| 2854 | size_t pos = ExpectLogContainsSomewhere( |
| 2855 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2856 | NetLog::PHASE_NONE); |
| 2857 | ExpectLogContainsSomewhere( |
| 2858 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2859 | NetLog::PHASE_NONE); |
| 2860 | |
| 2861 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2862 | ASSERT_TRUE(response); |
| 2863 | ASSERT_TRUE(response->headers); |
| 2864 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2865 | EXPECT_EQ(407, response->headers->response_code()); |
| 2866 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2867 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2868 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2869 | |
| 2870 | TestCompletionCallback callback2; |
| 2871 | |
| 2872 | // Wrong password (should be "bar"). |
| 2873 | rv = |
| 2874 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2876 | |
| 2877 | rv = callback2.WaitForResult(); |
| 2878 | EXPECT_EQ(OK, rv); |
| 2879 | |
| 2880 | response = trans->GetResponseInfo(); |
| 2881 | ASSERT_TRUE(response); |
| 2882 | ASSERT_TRUE(response->headers); |
| 2883 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2884 | EXPECT_EQ(407, response->headers->response_code()); |
| 2885 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2886 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2887 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2888 | |
| 2889 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2890 | // out of scope. |
| 2891 | session->CloseAllConnections(); |
| 2892 | } |
| 2893 | |
| 2894 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2895 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2896 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2897 | HttpRequestInfo request; |
| 2898 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2899 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2900 | // Ensure that proxy authentication is attempted even |
| 2901 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2902 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2903 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2904 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2905 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2906 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2907 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 2908 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2909 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2910 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2911 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2912 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2913 | // Since we have proxy, should try to establish tunnel. |
| 2914 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2915 | MockWrite( |
| 2916 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2917 | "Host: www.example.org\r\n" |
| 2918 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2919 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2920 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2921 | // be issuing -- the final header line contains the credentials. |
| 2922 | MockWrite( |
| 2923 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2924 | "Host: www.example.org\r\n" |
| 2925 | "Proxy-Connection: keep-alive\r\n" |
| 2926 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2927 | }; |
| 2928 | |
| 2929 | // The proxy responds to the connect with a 407, using a persistent |
| 2930 | // connection. |
| 2931 | MockRead data_reads1[] = { |
| 2932 | // No credentials. |
| 2933 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2934 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2935 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2936 | MockRead("0123456789"), |
| 2937 | |
| 2938 | // Wrong credentials (wrong password). |
| 2939 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2940 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2941 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2942 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2943 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2944 | }; |
| 2945 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2946 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2947 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2948 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2950 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2952 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2953 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2954 | |
| 2955 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2956 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2957 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2958 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2959 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2960 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2961 | NetLog::PHASE_NONE); |
| 2962 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2963 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2964 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2965 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2966 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2967 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2968 | ASSERT_TRUE(response); |
| 2969 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2970 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2971 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2972 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2973 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2974 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2975 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2976 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2977 | |
| 2978 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2979 | rv = trans->RestartWithAuth( |
| 2980 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2981 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2982 | |
| 2983 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2984 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2985 | |
| 2986 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2987 | ASSERT_TRUE(response); |
| 2988 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2989 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2990 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2991 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2992 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2993 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 2994 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 2995 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2996 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2997 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2998 | } |
| 2999 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3000 | // Test the case a proxy closes a socket while the challenge body is being |
| 3001 | // drained. |
| 3002 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3003 | HttpRequestInfo request; |
| 3004 | request.method = "GET"; |
| 3005 | request.url = GURL("https://www.example.org/"); |
| 3006 | // Ensure that proxy authentication is attempted even |
| 3007 | // when the no authentication data flag is set. |
| 3008 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3009 | |
| 3010 | // Configure against proxy server "myproxy:70". |
| 3011 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3012 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3013 | |
| 3014 | scoped_ptr<HttpTransaction> trans( |
| 3015 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3016 | |
| 3017 | // Since we have proxy, should try to establish tunnel. |
| 3018 | MockWrite data_writes1[] = { |
| 3019 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3020 | "Host: www.example.org\r\n" |
| 3021 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3022 | }; |
| 3023 | |
| 3024 | // The proxy responds to the connect with a 407, using a persistent |
| 3025 | // connection. |
| 3026 | MockRead data_reads1[] = { |
| 3027 | // No credentials. |
| 3028 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3029 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3030 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3031 | // Server hands up in the middle of the body. |
| 3032 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3033 | }; |
| 3034 | |
| 3035 | MockWrite data_writes2[] = { |
| 3036 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3037 | // be issuing -- the final header line contains the credentials. |
| 3038 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3039 | "Host: www.example.org\r\n" |
| 3040 | "Proxy-Connection: keep-alive\r\n" |
| 3041 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3042 | |
| 3043 | MockWrite("GET / HTTP/1.1\r\n" |
| 3044 | "Host: www.example.org\r\n" |
| 3045 | "Connection: keep-alive\r\n\r\n"), |
| 3046 | }; |
| 3047 | |
| 3048 | MockRead data_reads2[] = { |
| 3049 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3050 | |
| 3051 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3052 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3053 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3054 | MockRead(SYNCHRONOUS, "hello"), |
| 3055 | }; |
| 3056 | |
| 3057 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3058 | data_writes1, arraysize(data_writes1)); |
| 3059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3060 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3061 | data_writes2, arraysize(data_writes2)); |
| 3062 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3063 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3065 | |
| 3066 | TestCompletionCallback callback; |
| 3067 | |
| 3068 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3069 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3070 | |
| 3071 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3072 | ASSERT_TRUE(response); |
| 3073 | ASSERT_TRUE(response->headers); |
| 3074 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3075 | EXPECT_EQ(407, response->headers->response_code()); |
| 3076 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3077 | |
| 3078 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3079 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3080 | |
| 3081 | response = trans->GetResponseInfo(); |
| 3082 | ASSERT_TRUE(response); |
| 3083 | ASSERT_TRUE(response->headers); |
| 3084 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3085 | EXPECT_EQ(200, response->headers->response_code()); |
| 3086 | std::string body; |
| 3087 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3088 | EXPECT_EQ("hello", body); |
| 3089 | } |
| 3090 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3091 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3092 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3093 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3094 | HttpRequestInfo request; |
| 3095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3096 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3097 | request.load_flags = 0; |
| 3098 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3099 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3100 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3101 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3102 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3103 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3104 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3105 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3106 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3107 | // Since we have proxy, should try to establish tunnel. |
| 3108 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3109 | MockWrite( |
| 3110 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3111 | "Host: www.example.org\r\n" |
| 3112 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3113 | }; |
| 3114 | |
| 3115 | // The proxy responds to the connect with a 407. |
| 3116 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3117 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3118 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3119 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3120 | MockRead("0123456789"), // Should not be reached. |
| 3121 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3122 | }; |
| 3123 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3124 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3125 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3128 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3129 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3130 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3131 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3132 | |
| 3133 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3134 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3135 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3136 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3137 | ASSERT_TRUE(response); |
| 3138 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3139 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3140 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3141 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3142 | |
| 3143 | std::string response_data; |
| 3144 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3145 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3146 | |
| 3147 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3148 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3149 | } |
| 3150 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3151 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3152 | // caller when the proxy responds to CONNECT with 407. |
| 3153 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3154 | HttpRequestInfo request; |
| 3155 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3156 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3157 | request.load_flags = 0; |
| 3158 | |
| 3159 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3160 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3161 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3162 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3163 | |
| 3164 | scoped_ptr<HttpTransaction> trans( |
| 3165 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3166 | |
| 3167 | // Since we have proxy, should try to establish tunnel. |
| 3168 | MockWrite data_writes[] = { |
| 3169 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3170 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3171 | "Host: www.example.org\r\n" |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3172 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3173 | }; |
| 3174 | |
| 3175 | // The proxy responds to the connect with a 407. |
| 3176 | MockRead data_reads[] = { |
| 3177 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3178 | MockRead("X-Foo: bar\r\n"), |
| 3179 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3180 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3181 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3182 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3183 | }; |
| 3184 | |
| 3185 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3186 | arraysize(data_writes)); |
| 3187 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3188 | |
| 3189 | TestCompletionCallback callback; |
| 3190 | |
| 3191 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3192 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3193 | |
| 3194 | rv = callback.WaitForResult(); |
| 3195 | EXPECT_EQ(OK, rv); |
| 3196 | |
| 3197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3198 | ASSERT_TRUE(response); |
| 3199 | ASSERT_TRUE(response->headers); |
| 3200 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3201 | EXPECT_EQ(407, response->headers->response_code()); |
| 3202 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3203 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3204 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3205 | |
| 3206 | std::string response_data; |
| 3207 | rv = ReadTransaction(trans.get(), &response_data); |
| 3208 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3209 | |
| 3210 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3211 | session->CloseAllConnections(); |
| 3212 | } |
| 3213 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3214 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3215 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3216 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3217 | HttpRequestInfo request; |
| 3218 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3219 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3220 | request.load_flags = 0; |
| 3221 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3222 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3223 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3224 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3225 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3226 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3227 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3228 | MockWrite( |
| 3229 | "GET / HTTP/1.1\r\n" |
| 3230 | "Host: www.example.org\r\n" |
| 3231 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3232 | }; |
| 3233 | |
| 3234 | MockRead data_reads1[] = { |
| 3235 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3236 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3237 | // Large content-length -- won't matter, as connection will be reset. |
| 3238 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3239 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3240 | }; |
| 3241 | |
| 3242 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3243 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3244 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3246 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3248 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3250 | |
| 3251 | rv = callback.WaitForResult(); |
| 3252 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3253 | } |
| 3254 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3255 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3256 | // through a non-authenticating proxy. The request should fail with |
| 3257 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3258 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3259 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3260 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3261 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3262 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3263 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3264 | HttpRequestInfo request; |
| 3265 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3266 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3267 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3268 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3269 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3270 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3271 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3272 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3273 | // Since we have proxy, should try to establish tunnel. |
| 3274 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3275 | MockWrite( |
| 3276 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3277 | "Host: www.example.org\r\n" |
| 3278 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3279 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3280 | MockWrite( |
| 3281 | "GET / HTTP/1.1\r\n" |
| 3282 | "Host: www.example.org\r\n" |
| 3283 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3284 | }; |
| 3285 | |
| 3286 | MockRead data_reads1[] = { |
| 3287 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3288 | |
| 3289 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3290 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3291 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3292 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3293 | }; |
| 3294 | |
| 3295 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3296 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3297 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3298 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3301 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3302 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3303 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3304 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3306 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3307 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3308 | |
| 3309 | rv = callback1.WaitForResult(); |
| 3310 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3311 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3312 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3313 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3314 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3315 | NetLog::PHASE_NONE); |
| 3316 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3317 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3318 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3319 | NetLog::PHASE_NONE); |
| 3320 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3321 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame^] | 3322 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3323 | // that uses non-persistent connections. |
| 3324 | TEST_P(HttpNetworkTransactionTest, |
| 3325 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3326 | HttpRequestInfo request; |
| 3327 | request.method = "GET"; |
| 3328 | request.url = GURL("https://www.example.org/"); |
| 3329 | |
| 3330 | // Configure against proxy server "myproxy:70". |
| 3331 | session_deps_.proxy_service = |
| 3332 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3333 | |
| 3334 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3335 | new HttpAuthHandlerMock::Factory()); |
| 3336 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3337 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3338 | mock_handler->set_allows_default_credentials(true); |
| 3339 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3340 | HttpAuth::AUTH_PROXY); |
| 3341 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3342 | |
| 3343 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3344 | NetLog net_log; |
| 3345 | session_deps_.net_log = &net_log; |
| 3346 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3347 | |
| 3348 | // Since we have proxy, should try to establish tunnel. |
| 3349 | MockWrite data_writes1[] = { |
| 3350 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3351 | "Host: www.example.org\r\n" |
| 3352 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3353 | }; |
| 3354 | |
| 3355 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3356 | // connection. |
| 3357 | MockRead data_reads1[] = { |
| 3358 | // No credentials. |
| 3359 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3360 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3361 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3362 | }; |
| 3363 | |
| 3364 | // Since the first connection couldn't be reused, need to establish another |
| 3365 | // once given credentials. |
| 3366 | MockWrite data_writes2[] = { |
| 3367 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3368 | // be issuing -- the final header line contains the credentials. |
| 3369 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3370 | "Host: www.example.org\r\n" |
| 3371 | "Proxy-Connection: keep-alive\r\n" |
| 3372 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3373 | |
| 3374 | MockWrite("GET / HTTP/1.1\r\n" |
| 3375 | "Host: www.example.org\r\n" |
| 3376 | "Connection: keep-alive\r\n\r\n"), |
| 3377 | }; |
| 3378 | |
| 3379 | MockRead data_reads2[] = { |
| 3380 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3381 | |
| 3382 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3383 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3384 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3385 | MockRead(SYNCHRONOUS, "hello"), |
| 3386 | }; |
| 3387 | |
| 3388 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3389 | data_writes1, arraysize(data_writes1)); |
| 3390 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3391 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3392 | data_writes2, arraysize(data_writes2)); |
| 3393 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3394 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3396 | |
| 3397 | scoped_ptr<HttpTransaction> trans( |
| 3398 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3399 | |
| 3400 | TestCompletionCallback callback; |
| 3401 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3402 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3403 | |
| 3404 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3405 | ASSERT_TRUE(response); |
| 3406 | ASSERT_TRUE(response->headers); |
| 3407 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3408 | EXPECT_EQ(407, response->headers->response_code()); |
| 3409 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3410 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3411 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3412 | |
| 3413 | LoadTimingInfo load_timing_info; |
| 3414 | // CONNECT requests and responses are handled at the connect job level, so |
| 3415 | // the transaction does not yet have a connection. |
| 3416 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3417 | |
| 3418 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3419 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3420 | response = trans->GetResponseInfo(); |
| 3421 | ASSERT_TRUE(response); |
| 3422 | ASSERT_TRUE(response->headers); |
| 3423 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3424 | EXPECT_EQ(200, response->headers->response_code()); |
| 3425 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3426 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3427 | |
| 3428 | // The password prompt info should not be set. |
| 3429 | EXPECT_FALSE(response->auth_challenge); |
| 3430 | |
| 3431 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3432 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3433 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3434 | |
| 3435 | trans.reset(); |
| 3436 | session->CloseAllConnections(); |
| 3437 | } |
| 3438 | |
| 3439 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3440 | // that hangs up when credentials are initially sent. |
| 3441 | TEST_P(HttpNetworkTransactionTest, |
| 3442 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3443 | HttpRequestInfo request; |
| 3444 | request.method = "GET"; |
| 3445 | request.url = GURL("https://www.example.org/"); |
| 3446 | |
| 3447 | // Configure against proxy server "myproxy:70". |
| 3448 | session_deps_.proxy_service = |
| 3449 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3450 | |
| 3451 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3452 | new HttpAuthHandlerMock::Factory()); |
| 3453 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3454 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3455 | mock_handler->set_allows_default_credentials(true); |
| 3456 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3457 | HttpAuth::AUTH_PROXY); |
| 3458 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3459 | |
| 3460 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3461 | NetLog net_log; |
| 3462 | session_deps_.net_log = &net_log; |
| 3463 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3464 | |
| 3465 | // Should try to establish tunnel. |
| 3466 | MockWrite data_writes1[] = { |
| 3467 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3468 | "Host: www.example.org\r\n" |
| 3469 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3470 | |
| 3471 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3472 | "Host: www.example.org\r\n" |
| 3473 | "Proxy-Connection: keep-alive\r\n" |
| 3474 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3475 | }; |
| 3476 | |
| 3477 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3478 | // connection. |
| 3479 | MockRead data_reads1[] = { |
| 3480 | // No credentials. |
| 3481 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3482 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3483 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3484 | }; |
| 3485 | |
| 3486 | // Since the first connection was closed, need to establish another once given |
| 3487 | // credentials. |
| 3488 | MockWrite data_writes2[] = { |
| 3489 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3490 | "Host: www.example.org\r\n" |
| 3491 | "Proxy-Connection: keep-alive\r\n" |
| 3492 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3493 | |
| 3494 | MockWrite("GET / HTTP/1.1\r\n" |
| 3495 | "Host: www.example.org\r\n" |
| 3496 | "Connection: keep-alive\r\n\r\n"), |
| 3497 | }; |
| 3498 | |
| 3499 | MockRead data_reads2[] = { |
| 3500 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3501 | |
| 3502 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3503 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3504 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3505 | MockRead(SYNCHRONOUS, "hello"), |
| 3506 | }; |
| 3507 | |
| 3508 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3509 | data_writes1, arraysize(data_writes1)); |
| 3510 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3511 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3512 | data_writes2, arraysize(data_writes2)); |
| 3513 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3514 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3516 | |
| 3517 | scoped_ptr<HttpTransaction> trans( |
| 3518 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3519 | |
| 3520 | TestCompletionCallback callback; |
| 3521 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3522 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3523 | |
| 3524 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3525 | ASSERT_TRUE(response); |
| 3526 | ASSERT_TRUE(response->headers); |
| 3527 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3528 | EXPECT_EQ(407, response->headers->response_code()); |
| 3529 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3530 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3531 | EXPECT_FALSE(response->auth_challenge); |
| 3532 | |
| 3533 | LoadTimingInfo load_timing_info; |
| 3534 | // CONNECT requests and responses are handled at the connect job level, so |
| 3535 | // the transaction does not yet have a connection. |
| 3536 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3537 | |
| 3538 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3539 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3540 | |
| 3541 | response = trans->GetResponseInfo(); |
| 3542 | ASSERT_TRUE(response); |
| 3543 | ASSERT_TRUE(response->headers); |
| 3544 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3545 | EXPECT_EQ(200, response->headers->response_code()); |
| 3546 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3547 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3548 | |
| 3549 | // The password prompt info should not be set. |
| 3550 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3551 | |
| 3552 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3553 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3554 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3555 | |
| 3556 | trans.reset(); |
| 3557 | session->CloseAllConnections(); |
| 3558 | } |
| 3559 | |
| 3560 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3561 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3562 | // they are retried. |
| 3563 | TEST_P(HttpNetworkTransactionTest, |
| 3564 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3565 | HttpRequestInfo request; |
| 3566 | request.method = "GET"; |
| 3567 | request.url = GURL("https://www.example.org/"); |
| 3568 | |
| 3569 | // Configure against proxy server "myproxy:70". |
| 3570 | session_deps_.proxy_service = |
| 3571 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3572 | |
| 3573 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3574 | new HttpAuthHandlerMock::Factory()); |
| 3575 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3576 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3577 | mock_handler->set_allows_default_credentials(true); |
| 3578 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3579 | HttpAuth::AUTH_PROXY); |
| 3580 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3581 | |
| 3582 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3583 | NetLog net_log; |
| 3584 | session_deps_.net_log = &net_log; |
| 3585 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3586 | |
| 3587 | // Should try to establish tunnel. |
| 3588 | MockWrite data_writes1[] = { |
| 3589 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3590 | "Host: www.example.org\r\n" |
| 3591 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3592 | |
| 3593 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3594 | "Host: www.example.org\r\n" |
| 3595 | "Proxy-Connection: keep-alive\r\n" |
| 3596 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3597 | }; |
| 3598 | |
| 3599 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3600 | // second request is sent. |
| 3601 | MockRead data_reads1[] = { |
| 3602 | // No credentials. |
| 3603 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3604 | MockRead("Content-Length: 0\r\n"), |
| 3605 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3606 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3607 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3608 | }; |
| 3609 | |
| 3610 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3611 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3612 | // request. |
| 3613 | MockWrite data_writes2[] = { |
| 3614 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3615 | "Host: www.example.org\r\n" |
| 3616 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3617 | }; |
| 3618 | |
| 3619 | // The proxy, having had more than enough of us, just hangs up. |
| 3620 | MockRead data_reads2[] = { |
| 3621 | // No credentials. |
| 3622 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3623 | }; |
| 3624 | |
| 3625 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3626 | data_writes1, arraysize(data_writes1)); |
| 3627 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3628 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3629 | data_writes2, arraysize(data_writes2)); |
| 3630 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3631 | |
| 3632 | scoped_ptr<HttpTransaction> trans( |
| 3633 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3634 | |
| 3635 | TestCompletionCallback callback; |
| 3636 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3637 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3638 | |
| 3639 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3640 | ASSERT_TRUE(response); |
| 3641 | ASSERT_TRUE(response->headers); |
| 3642 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3643 | EXPECT_EQ(407, response->headers->response_code()); |
| 3644 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3645 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3646 | EXPECT_FALSE(response->auth_challenge); |
| 3647 | |
| 3648 | LoadTimingInfo load_timing_info; |
| 3649 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3650 | |
| 3651 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3652 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3653 | |
| 3654 | trans.reset(); |
| 3655 | session->CloseAllConnections(); |
| 3656 | } |
| 3657 | |
| 3658 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3659 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3660 | // again they are retried. |
| 3661 | TEST_P(HttpNetworkTransactionTest, |
| 3662 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3663 | HttpRequestInfo request; |
| 3664 | request.method = "GET"; |
| 3665 | request.url = GURL("https://www.example.org/"); |
| 3666 | |
| 3667 | // Configure against proxy server "myproxy:70". |
| 3668 | session_deps_.proxy_service = |
| 3669 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3670 | |
| 3671 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3672 | new HttpAuthHandlerMock::Factory()); |
| 3673 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3674 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3675 | mock_handler->set_allows_default_credentials(true); |
| 3676 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3677 | HttpAuth::AUTH_PROXY); |
| 3678 | // Add another handler for the second challenge. It supports default |
| 3679 | // credentials, but they shouldn't be used, since they were already tried. |
| 3680 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3681 | mock_handler->set_allows_default_credentials(true); |
| 3682 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3683 | HttpAuth::AUTH_PROXY); |
| 3684 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3685 | |
| 3686 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3687 | NetLog net_log; |
| 3688 | session_deps_.net_log = &net_log; |
| 3689 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3690 | |
| 3691 | // Should try to establish tunnel. |
| 3692 | MockWrite data_writes1[] = { |
| 3693 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3694 | "Host: www.example.org\r\n" |
| 3695 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3696 | }; |
| 3697 | |
| 3698 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3699 | // connection. |
| 3700 | MockRead data_reads1[] = { |
| 3701 | // No credentials. |
| 3702 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3703 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3704 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3705 | }; |
| 3706 | |
| 3707 | // Since the first connection was closed, need to establish another once given |
| 3708 | // credentials. |
| 3709 | MockWrite data_writes2[] = { |
| 3710 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3711 | "Host: www.example.org\r\n" |
| 3712 | "Proxy-Connection: keep-alive\r\n" |
| 3713 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3714 | }; |
| 3715 | |
| 3716 | MockRead data_reads2[] = { |
| 3717 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3718 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3719 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3720 | }; |
| 3721 | |
| 3722 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3723 | data_writes1, arraysize(data_writes1)); |
| 3724 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3725 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3726 | data_writes2, arraysize(data_writes2)); |
| 3727 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3728 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3729 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3730 | |
| 3731 | scoped_ptr<HttpTransaction> trans( |
| 3732 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3733 | |
| 3734 | TestCompletionCallback callback; |
| 3735 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3736 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3737 | |
| 3738 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3739 | ASSERT_TRUE(response); |
| 3740 | ASSERT_TRUE(response->headers); |
| 3741 | EXPECT_EQ(407, response->headers->response_code()); |
| 3742 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3743 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3744 | EXPECT_FALSE(response->auth_challenge); |
| 3745 | |
| 3746 | LoadTimingInfo load_timing_info; |
| 3747 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3748 | |
| 3749 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3750 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3751 | response = trans->GetResponseInfo(); |
| 3752 | ASSERT_TRUE(response); |
| 3753 | ASSERT_TRUE(response->headers); |
| 3754 | EXPECT_EQ(407, response->headers->response_code()); |
| 3755 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3756 | EXPECT_TRUE(response->auth_challenge); |
| 3757 | |
| 3758 | trans.reset(); |
| 3759 | session->CloseAllConnections(); |
| 3760 | } |
| 3761 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3762 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3763 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3764 | HttpRequestInfo request1; |
| 3765 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3766 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3767 | |
| 3768 | HttpRequestInfo request2; |
| 3769 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3770 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3771 | |
| 3772 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3773 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3774 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3775 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3776 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3777 | |
| 3778 | // Since we have proxy, should try to establish tunnel. |
| 3779 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3780 | MockWrite( |
| 3781 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3782 | "Host: www.example.org\r\n" |
| 3783 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3784 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3785 | MockWrite( |
| 3786 | "GET /1 HTTP/1.1\r\n" |
| 3787 | "Host: www.example.org\r\n" |
| 3788 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3789 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3790 | MockWrite( |
| 3791 | "GET /2 HTTP/1.1\r\n" |
| 3792 | "Host: www.example.org\r\n" |
| 3793 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3794 | }; |
| 3795 | |
| 3796 | // The proxy responds to the connect with a 407, using a persistent |
| 3797 | // connection. |
| 3798 | MockRead data_reads1[] = { |
| 3799 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3800 | |
| 3801 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3802 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3803 | MockRead(SYNCHRONOUS, "1"), |
| 3804 | |
| 3805 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3806 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3807 | MockRead(SYNCHRONOUS, "22"), |
| 3808 | }; |
| 3809 | |
| 3810 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3811 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3812 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3813 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3814 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3815 | |
| 3816 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3817 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3819 | |
| 3820 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3821 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3822 | |
| 3823 | rv = callback1.WaitForResult(); |
| 3824 | EXPECT_EQ(OK, rv); |
| 3825 | |
| 3826 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3827 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3828 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3829 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3830 | |
| 3831 | LoadTimingInfo load_timing_info1; |
| 3832 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3833 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3834 | |
| 3835 | trans1.reset(); |
| 3836 | |
| 3837 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3838 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3839 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3840 | |
| 3841 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3843 | |
| 3844 | rv = callback2.WaitForResult(); |
| 3845 | EXPECT_EQ(OK, rv); |
| 3846 | |
| 3847 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3848 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3849 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3850 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3851 | |
| 3852 | LoadTimingInfo load_timing_info2; |
| 3853 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3854 | TestLoadTimingReused(load_timing_info2); |
| 3855 | |
| 3856 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3857 | |
| 3858 | trans2.reset(); |
| 3859 | session->CloseAllConnections(); |
| 3860 | } |
| 3861 | |
| 3862 | // 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] | 3863 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3864 | HttpRequestInfo request1; |
| 3865 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3866 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3867 | |
| 3868 | HttpRequestInfo request2; |
| 3869 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3870 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3871 | |
| 3872 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3873 | session_deps_.proxy_service = |
| 3874 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3875 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3876 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3877 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3878 | |
| 3879 | // Since we have proxy, should try to establish tunnel. |
| 3880 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3881 | MockWrite( |
| 3882 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3883 | "Host: www.example.org\r\n" |
| 3884 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3885 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3886 | MockWrite( |
| 3887 | "GET /1 HTTP/1.1\r\n" |
| 3888 | "Host: www.example.org\r\n" |
| 3889 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3890 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3891 | MockWrite( |
| 3892 | "GET /2 HTTP/1.1\r\n" |
| 3893 | "Host: www.example.org\r\n" |
| 3894 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3895 | }; |
| 3896 | |
| 3897 | // The proxy responds to the connect with a 407, using a persistent |
| 3898 | // connection. |
| 3899 | MockRead data_reads1[] = { |
| 3900 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3901 | |
| 3902 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3903 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3904 | MockRead(SYNCHRONOUS, "1"), |
| 3905 | |
| 3906 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3907 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3908 | MockRead(SYNCHRONOUS, "22"), |
| 3909 | }; |
| 3910 | |
| 3911 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3912 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3913 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3914 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3915 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3916 | |
| 3917 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3918 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3919 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3920 | |
| 3921 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3922 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3923 | |
| 3924 | rv = callback1.WaitForResult(); |
| 3925 | EXPECT_EQ(OK, rv); |
| 3926 | |
| 3927 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3928 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3929 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3930 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3931 | |
| 3932 | LoadTimingInfo load_timing_info1; |
| 3933 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3934 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3935 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3936 | |
| 3937 | trans1.reset(); |
| 3938 | |
| 3939 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3940 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3941 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3942 | |
| 3943 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3944 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3945 | |
| 3946 | rv = callback2.WaitForResult(); |
| 3947 | EXPECT_EQ(OK, rv); |
| 3948 | |
| 3949 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3950 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3951 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3952 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3953 | |
| 3954 | LoadTimingInfo load_timing_info2; |
| 3955 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3956 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3957 | |
| 3958 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3959 | |
| 3960 | trans2.reset(); |
| 3961 | session->CloseAllConnections(); |
| 3962 | } |
| 3963 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3964 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3965 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3966 | HttpRequestInfo request; |
| 3967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3968 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3969 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3970 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3971 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3972 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3973 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 3974 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3975 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3976 | // Since we have proxy, should use full url |
| 3977 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3978 | MockWrite( |
| 3979 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3980 | "Host: www.example.org\r\n" |
| 3981 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3982 | }; |
| 3983 | |
| 3984 | MockRead data_reads1[] = { |
| 3985 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3986 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3987 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3988 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3989 | }; |
| 3990 | |
| 3991 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3992 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3993 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3994 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3997 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3998 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3999 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4002 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4004 | |
| 4005 | rv = callback1.WaitForResult(); |
| 4006 | EXPECT_EQ(OK, rv); |
| 4007 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4008 | LoadTimingInfo load_timing_info; |
| 4009 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4010 | TestLoadTimingNotReused(load_timing_info, |
| 4011 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4012 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4013 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4014 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4015 | |
| 4016 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4017 | EXPECT_EQ(200, response->headers->response_code()); |
| 4018 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4019 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4020 | |
| 4021 | // The password prompt info should not be set. |
| 4022 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4023 | } |
| 4024 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4025 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4026 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4027 | HttpRequestInfo request; |
| 4028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4029 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4030 | request.load_flags = 0; |
| 4031 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4032 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4033 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4034 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4035 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4036 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4037 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4038 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4039 | scoped_ptr<SpdyFrame> req( |
| 4040 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4041 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4042 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4043 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4044 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4045 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4046 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4047 | }; |
| 4048 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4049 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4050 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4051 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4052 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4053 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4054 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4057 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4058 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4059 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4060 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4062 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4063 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4064 | |
| 4065 | rv = callback1.WaitForResult(); |
| 4066 | EXPECT_EQ(OK, rv); |
| 4067 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4068 | LoadTimingInfo load_timing_info; |
| 4069 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4070 | TestLoadTimingNotReused(load_timing_info, |
| 4071 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4072 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4073 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4074 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4075 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4077 | |
| 4078 | std::string response_data; |
| 4079 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4080 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4081 | } |
| 4082 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4083 | // Verifies that a session which races and wins against the owning transaction |
| 4084 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4085 | // Regression test for crbug.com/334413. |
| 4086 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4087 | HttpRequestInfo request; |
| 4088 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4089 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4090 | request.load_flags = 0; |
| 4091 | |
| 4092 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4093 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4094 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4095 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4096 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4097 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4098 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4099 | scoped_ptr<SpdyFrame> req( |
| 4100 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4101 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4102 | |
| 4103 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4104 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4105 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4106 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4107 | }; |
| 4108 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4109 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4110 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4111 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4112 | |
| 4113 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4114 | ssl.SetNextProto(GetParam()); |
| 4115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4116 | |
| 4117 | TestCompletionCallback callback1; |
| 4118 | |
| 4119 | scoped_ptr<HttpTransaction> trans( |
| 4120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4121 | |
| 4122 | // Stall the hostname resolution begun by the transaction. |
| 4123 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4124 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4125 | |
| 4126 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4127 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4128 | |
| 4129 | // Race a session to the proxy, which completes first. |
| 4130 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4131 | SpdySessionKey key( |
| 4132 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4133 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4134 | CreateSecureSpdySession(session, key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4135 | |
| 4136 | // Unstall the resolution begun by the transaction. |
| 4137 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4138 | session_deps_.host_resolver->ResolveAllPending(); |
| 4139 | |
| 4140 | EXPECT_FALSE(callback1.have_result()); |
| 4141 | rv = callback1.WaitForResult(); |
| 4142 | EXPECT_EQ(OK, rv); |
| 4143 | |
| 4144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4145 | ASSERT_TRUE(response != NULL); |
| 4146 | ASSERT_TRUE(response->headers.get() != NULL); |
| 4147 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4148 | |
| 4149 | std::string response_data; |
| 4150 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4151 | EXPECT_EQ(kUploadData, response_data); |
| 4152 | } |
| 4153 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4154 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4155 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4156 | HttpRequestInfo request; |
| 4157 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4158 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4159 | request.load_flags = 0; |
| 4160 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4161 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4162 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4163 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4164 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4165 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4166 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4167 | // The first request will be a bare GET, the second request will be a |
| 4168 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4169 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4170 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4171 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4172 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4173 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4174 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4175 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4176 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4177 | false, |
| 4178 | 3, |
| 4179 | LOWEST, |
| 4180 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4181 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4182 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4183 | }; |
| 4184 | |
| 4185 | // The first response is a 407 proxy authentication challenge, and the second |
| 4186 | // response will be a 200 response since the second request includes a valid |
| 4187 | // Authorization header. |
| 4188 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4189 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4190 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4191 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4192 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4193 | "407 Proxy Authentication Required", |
| 4194 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4195 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4196 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4197 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4198 | scoped_ptr<SpdyFrame> resp_data( |
| 4199 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4200 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4201 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4202 | CreateMockRead(*resp_authentication, 1), |
| 4203 | CreateMockRead(*body_authentication, 2), |
| 4204 | CreateMockRead(*resp_data, 4), |
| 4205 | CreateMockRead(*body_data, 5), |
| 4206 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4207 | }; |
| 4208 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4209 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4210 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4211 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4212 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4213 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4214 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4215 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4217 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4218 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4219 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4222 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4223 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4224 | |
| 4225 | rv = callback1.WaitForResult(); |
| 4226 | EXPECT_EQ(OK, rv); |
| 4227 | |
| 4228 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4229 | |
| 4230 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4231 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4232 | EXPECT_EQ(407, response->headers->response_code()); |
| 4233 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4234 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4236 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4238 | rv = trans->RestartWithAuth( |
| 4239 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4240 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4241 | |
| 4242 | rv = callback2.WaitForResult(); |
| 4243 | EXPECT_EQ(OK, rv); |
| 4244 | |
| 4245 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4246 | |
| 4247 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4248 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4249 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4250 | // The password prompt info should not be set. |
| 4251 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4252 | } |
| 4253 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4254 | // 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] | 4255 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4256 | HttpRequestInfo request; |
| 4257 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4258 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4259 | request.load_flags = 0; |
| 4260 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4261 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4262 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4263 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4264 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4265 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4266 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4267 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4268 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4269 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4270 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4271 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4272 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4273 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4274 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4275 | const char get[] = |
| 4276 | "GET / HTTP/1.1\r\n" |
| 4277 | "Host: www.example.org\r\n" |
| 4278 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4279 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4280 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4281 | scoped_ptr<SpdyFrame> conn_resp( |
| 4282 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4283 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4284 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4285 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4286 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4287 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4288 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4289 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4290 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4291 | |
| 4292 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4293 | CreateMockWrite(*connect, 0), |
| 4294 | CreateMockWrite(*wrapped_get, 2), |
| 4295 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4296 | }; |
| 4297 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4298 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4299 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4300 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4301 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4302 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4303 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4304 | }; |
| 4305 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4306 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4307 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4308 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4309 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4310 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4311 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4313 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4314 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4316 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4317 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4318 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4319 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4320 | |
| 4321 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4322 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4323 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4324 | LoadTimingInfo load_timing_info; |
| 4325 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4326 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4327 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4328 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4329 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4330 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4331 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4332 | |
| 4333 | std::string response_data; |
| 4334 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4335 | EXPECT_EQ("1234567890", response_data); |
| 4336 | } |
| 4337 | |
| 4338 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4339 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4340 | HttpRequestInfo request; |
| 4341 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4342 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4343 | request.load_flags = 0; |
| 4344 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4345 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4346 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4347 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4348 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4349 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4350 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4351 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4352 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4353 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4354 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4355 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4356 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4357 | // fetch https://www.example.org/ via SPDY |
| 4358 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4359 | scoped_ptr<SpdyFrame> get( |
| 4360 | spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4361 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4362 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4363 | scoped_ptr<SpdyFrame> conn_resp( |
| 4364 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4365 | scoped_ptr<SpdyFrame> get_resp( |
| 4366 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4367 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4368 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 4369 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4370 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4371 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4372 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4373 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4374 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4375 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4376 | |
| 4377 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4378 | CreateMockWrite(*connect, 0), |
| 4379 | CreateMockWrite(*wrapped_get, 2), |
| 4380 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4381 | CreateMockWrite(*window_update_body, 7), |
| 4382 | }; |
| 4383 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4384 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4385 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4386 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4387 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4388 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4389 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4390 | }; |
| 4391 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4392 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4393 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4394 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4395 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4396 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4397 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4399 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4400 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4403 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4405 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4406 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4407 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4408 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4409 | base::MessageLoop::current()->RunUntilIdle(); |
| 4410 | // Now allow the read of the response to complete. |
| 4411 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4412 | rv = callback1.WaitForResult(); |
| 4413 | EXPECT_EQ(OK, rv); |
| 4414 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4415 | LoadTimingInfo load_timing_info; |
| 4416 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4417 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4418 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4419 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4420 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4421 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4422 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4423 | |
| 4424 | std::string response_data; |
| 4425 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4426 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4430 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4431 | HttpRequestInfo request; |
| 4432 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4433 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4434 | request.load_flags = 0; |
| 4435 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4436 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4437 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4438 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4439 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4440 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4441 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4442 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4443 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4444 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4445 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4446 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4447 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4448 | scoped_ptr<SpdyFrame> get( |
| 4449 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4450 | |
| 4451 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4452 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4453 | }; |
| 4454 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4455 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4456 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4457 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4458 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4459 | }; |
| 4460 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4461 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4462 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4463 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4464 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4465 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4466 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4468 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4469 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4472 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4474 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4475 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4476 | |
| 4477 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4478 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4479 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4480 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4481 | } |
| 4482 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4483 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4484 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4485 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4486 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4487 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4488 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4489 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4490 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4491 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4492 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4493 | |
| 4494 | HttpRequestInfo request1; |
| 4495 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4496 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4497 | request1.load_flags = 0; |
| 4498 | |
| 4499 | HttpRequestInfo request2; |
| 4500 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4501 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4502 | request2.load_flags = 0; |
| 4503 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4504 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4505 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4506 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4507 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4508 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4509 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4510 | // Fetch https://www.example.org/ via HTTP. |
| 4511 | const char get1[] = |
| 4512 | "GET / HTTP/1.1\r\n" |
| 4513 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4514 | "Connection: keep-alive\r\n\r\n"; |
| 4515 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4516 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4517 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4518 | "Content-Length: 1\r\n\r\n"; |
| 4519 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4520 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4521 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4522 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4523 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4524 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4525 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4526 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4527 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4528 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4529 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 4530 | if (GetParam() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4531 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4532 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4533 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4534 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4535 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4536 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4537 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4538 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4539 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4540 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4541 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4542 | // Fetch https://mail.example.org/ via HTTP. |
| 4543 | const char get2[] = |
| 4544 | "GET / HTTP/1.1\r\n" |
| 4545 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4546 | "Connection: keep-alive\r\n\r\n"; |
| 4547 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4548 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4549 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4550 | "Content-Length: 2\r\n\r\n"; |
| 4551 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4552 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4553 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4554 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4555 | |
| 4556 | MockWrite spdy_writes[] = { |
| 4557 | CreateMockWrite(*connect1, 0), |
| 4558 | CreateMockWrite(*wrapped_get1, 2), |
| 4559 | CreateMockWrite(*connect2, 5), |
| 4560 | CreateMockWrite(*wrapped_get2, 7), |
| 4561 | }; |
| 4562 | |
| 4563 | MockRead spdy_reads[] = { |
| 4564 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4565 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4566 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4567 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4568 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4569 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4570 | MockRead(ASYNC, 0, 10), |
| 4571 | }; |
| 4572 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4573 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4574 | arraysize(spdy_writes)); |
| 4575 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4576 | |
| 4577 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4578 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4580 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4581 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4582 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4584 | |
| 4585 | TestCompletionCallback callback; |
| 4586 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4587 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4589 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4590 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4591 | |
| 4592 | LoadTimingInfo load_timing_info; |
| 4593 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4594 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4595 | |
| 4596 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4597 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4598 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4599 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4600 | |
| 4601 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4602 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4603 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4604 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4605 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4606 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4607 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4608 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4609 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4610 | |
| 4611 | LoadTimingInfo load_timing_info2; |
| 4612 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4613 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4614 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4615 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4616 | |
| 4617 | // The requests should have different IDs, since they each are using their own |
| 4618 | // separate stream. |
| 4619 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4620 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4621 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4622 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4626 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4627 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4628 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4629 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4630 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4631 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4632 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4633 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4634 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4635 | |
| 4636 | HttpRequestInfo request1; |
| 4637 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4638 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4639 | request1.load_flags = 0; |
| 4640 | |
| 4641 | HttpRequestInfo request2; |
| 4642 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4643 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4644 | request2.load_flags = 0; |
| 4645 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4646 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4647 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4648 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4649 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4650 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4651 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4652 | // Fetch https://www.example.org/ via HTTP. |
| 4653 | const char get1[] = |
| 4654 | "GET / HTTP/1.1\r\n" |
| 4655 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4656 | "Connection: keep-alive\r\n\r\n"; |
| 4657 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4658 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4659 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4660 | "Content-Length: 1\r\n\r\n"; |
| 4661 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4662 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4663 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4664 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4665 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4666 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4667 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4668 | // Fetch https://www.example.org/2 via HTTP. |
| 4669 | const char get2[] = |
| 4670 | "GET /2 HTTP/1.1\r\n" |
| 4671 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4672 | "Connection: keep-alive\r\n\r\n"; |
| 4673 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4674 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4675 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4676 | "Content-Length: 2\r\n\r\n"; |
| 4677 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4678 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4679 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4680 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4681 | |
| 4682 | MockWrite spdy_writes[] = { |
| 4683 | CreateMockWrite(*connect1, 0), |
| 4684 | CreateMockWrite(*wrapped_get1, 2), |
| 4685 | CreateMockWrite(*wrapped_get2, 5), |
| 4686 | }; |
| 4687 | |
| 4688 | MockRead spdy_reads[] = { |
| 4689 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4690 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4691 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4692 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4693 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4694 | MockRead(ASYNC, 0, 8), |
| 4695 | }; |
| 4696 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4697 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4698 | arraysize(spdy_writes)); |
| 4699 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4700 | |
| 4701 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4702 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4704 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4706 | |
| 4707 | TestCompletionCallback callback; |
| 4708 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4709 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4710 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4711 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4712 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4713 | |
| 4714 | rv = callback.WaitForResult(); |
| 4715 | EXPECT_EQ(OK, rv); |
| 4716 | |
| 4717 | LoadTimingInfo load_timing_info; |
| 4718 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4719 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4720 | |
| 4721 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4722 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4723 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4724 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4725 | |
| 4726 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4727 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4728 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4729 | trans.reset(); |
| 4730 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4731 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4732 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4733 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4734 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4735 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4736 | rv = callback.WaitForResult(); |
| 4737 | EXPECT_EQ(OK, rv); |
| 4738 | |
| 4739 | LoadTimingInfo load_timing_info2; |
| 4740 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4741 | TestLoadTimingReused(load_timing_info2); |
| 4742 | |
| 4743 | // The requests should have the same ID. |
| 4744 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4745 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4746 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4750 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4751 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4752 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4753 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4754 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4755 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4756 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4757 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4758 | |
| 4759 | HttpRequestInfo request1; |
| 4760 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4761 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4762 | request1.load_flags = 0; |
| 4763 | |
| 4764 | HttpRequestInfo request2; |
| 4765 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4766 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4767 | request2.load_flags = 0; |
| 4768 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4769 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4770 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4771 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4772 | scoped_ptr<SpdyFrame> get1( |
| 4773 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4774 | scoped_ptr<SpdyFrame> get_resp1( |
| 4775 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4776 | scoped_ptr<SpdyFrame> body1( |
| 4777 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4778 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4779 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4780 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4781 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4782 | scoped_ptr<SpdyFrame> get2( |
| 4783 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4784 | scoped_ptr<SpdyFrame> get_resp2( |
| 4785 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4786 | scoped_ptr<SpdyFrame> body2( |
| 4787 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4788 | |
| 4789 | MockWrite spdy_writes[] = { |
| 4790 | CreateMockWrite(*get1, 0), |
| 4791 | CreateMockWrite(*get2, 3), |
| 4792 | }; |
| 4793 | |
| 4794 | MockRead spdy_reads[] = { |
| 4795 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4796 | CreateMockRead(*body1, 2, ASYNC), |
| 4797 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4798 | CreateMockRead(*body2, 5, ASYNC), |
| 4799 | MockRead(ASYNC, 0, 6), |
| 4800 | }; |
| 4801 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4802 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4803 | arraysize(spdy_writes)); |
| 4804 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4805 | |
| 4806 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4807 | ssl.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4808 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4809 | |
| 4810 | TestCompletionCallback callback; |
| 4811 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4812 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4813 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4814 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4815 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4816 | |
| 4817 | LoadTimingInfo load_timing_info; |
| 4818 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4819 | TestLoadTimingNotReused(load_timing_info, |
| 4820 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4821 | |
| 4822 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4823 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4824 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4825 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4826 | |
| 4827 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4828 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4829 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4830 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4831 | // Delete the first request, so the second one can reuse the socket. |
| 4832 | trans.reset(); |
| 4833 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4834 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4835 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4836 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4837 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4838 | |
| 4839 | LoadTimingInfo load_timing_info2; |
| 4840 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4841 | TestLoadTimingReused(load_timing_info2); |
| 4842 | |
| 4843 | // The requests should have the same ID. |
| 4844 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4845 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4846 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4847 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4848 | } |
| 4849 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4850 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4851 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4852 | HttpRequestInfo request; |
| 4853 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4854 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4855 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4856 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4857 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4858 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4859 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4860 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4861 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4862 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4863 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4864 | // Since we have proxy, should use full url |
| 4865 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4866 | MockWrite( |
| 4867 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4868 | "Host: www.example.org\r\n" |
| 4869 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4870 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4871 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4872 | // be issuing -- the final header line contains the credentials. |
| 4873 | MockWrite( |
| 4874 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4875 | "Host: www.example.org\r\n" |
| 4876 | "Proxy-Connection: keep-alive\r\n" |
| 4877 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4878 | }; |
| 4879 | |
| 4880 | // The proxy responds to the GET with a 407, using a persistent |
| 4881 | // connection. |
| 4882 | MockRead data_reads1[] = { |
| 4883 | // No credentials. |
| 4884 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4885 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4886 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4887 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4888 | |
| 4889 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4890 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4891 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4892 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4893 | }; |
| 4894 | |
| 4895 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4896 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4897 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4898 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4901 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4902 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4903 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4904 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4906 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4907 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4908 | |
| 4909 | rv = callback1.WaitForResult(); |
| 4910 | EXPECT_EQ(OK, rv); |
| 4911 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4912 | LoadTimingInfo load_timing_info; |
| 4913 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4914 | TestLoadTimingNotReused(load_timing_info, |
| 4915 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4916 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4917 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4918 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4919 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4920 | EXPECT_EQ(407, response->headers->response_code()); |
| 4921 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4922 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4924 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4926 | rv = trans->RestartWithAuth( |
| 4927 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4928 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4929 | |
| 4930 | rv = callback2.WaitForResult(); |
| 4931 | EXPECT_EQ(OK, rv); |
| 4932 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4933 | load_timing_info = LoadTimingInfo(); |
| 4934 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4935 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4936 | TestLoadTimingReused(load_timing_info); |
| 4937 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4938 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4939 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4940 | |
| 4941 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4942 | EXPECT_EQ(200, response->headers->response_code()); |
| 4943 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4944 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4945 | |
| 4946 | // The password prompt info should not be set. |
| 4947 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4948 | } |
| 4949 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4950 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4951 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4952 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4954 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4955 | request.load_flags = 0; |
| 4956 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4957 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4958 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 4959 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4960 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4961 | // Since we have proxy, should try to establish tunnel. |
| 4962 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4963 | MockWrite( |
| 4964 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4965 | "Host: www.example.org\r\n" |
| 4966 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4967 | }; |
| 4968 | |
| 4969 | MockRead data_reads[] = { |
| 4970 | status, |
| 4971 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4972 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4973 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4974 | }; |
| 4975 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4977 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4980 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4981 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4982 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4985 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4986 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4987 | |
| 4988 | rv = callback.WaitForResult(); |
| 4989 | EXPECT_EQ(expected_status, rv); |
| 4990 | } |
| 4991 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4992 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4993 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4994 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4995 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4996 | } |
| 4997 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4998 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4999 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5000 | } |
| 5001 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5002 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5003 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5004 | } |
| 5005 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5006 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5007 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5008 | } |
| 5009 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5010 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5011 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5012 | } |
| 5013 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5014 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5015 | ConnectStatusHelper( |
| 5016 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5017 | } |
| 5018 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5019 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5020 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5021 | } |
| 5022 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5023 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5024 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5025 | } |
| 5026 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5027 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5028 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5029 | } |
| 5030 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5031 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5032 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5033 | } |
| 5034 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5035 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5036 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5037 | } |
| 5038 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5039 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5040 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5041 | } |
| 5042 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5043 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5044 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5045 | } |
| 5046 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5047 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5048 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5049 | } |
| 5050 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5051 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5052 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5053 | } |
| 5054 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5055 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5056 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5057 | } |
| 5058 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5059 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5060 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5061 | } |
| 5062 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5063 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5064 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5065 | } |
| 5066 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5067 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5068 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5069 | } |
| 5070 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5071 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5072 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5073 | } |
| 5074 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5075 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5076 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5077 | } |
| 5078 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5079 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5080 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5081 | } |
| 5082 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5083 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5084 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5085 | } |
| 5086 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5087 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5088 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5089 | } |
| 5090 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5091 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5092 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5093 | } |
| 5094 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5095 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5096 | ConnectStatusHelperWithExpectedStatus( |
| 5097 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5098 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5099 | } |
| 5100 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5101 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5102 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5103 | } |
| 5104 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5105 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5106 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5107 | } |
| 5108 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5109 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5110 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5111 | } |
| 5112 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5113 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5114 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5115 | } |
| 5116 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5117 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5118 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5119 | } |
| 5120 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5121 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5122 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5123 | } |
| 5124 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5125 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5126 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5127 | } |
| 5128 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5129 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5130 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5131 | } |
| 5132 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5133 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5134 | ConnectStatusHelper( |
| 5135 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5136 | } |
| 5137 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5138 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5139 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5140 | } |
| 5141 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5142 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5143 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5144 | } |
| 5145 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5146 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5147 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5148 | } |
| 5149 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5150 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5151 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5152 | } |
| 5153 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5154 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5155 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5156 | } |
| 5157 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5158 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5159 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5160 | } |
| 5161 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5162 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5163 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5164 | } |
| 5165 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5166 | // Test the flow when both the proxy server AND origin server require |
| 5167 | // authentication. Again, this uses basic auth for both since that is |
| 5168 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5169 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5170 | HttpRequestInfo request; |
| 5171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5172 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5173 | request.load_flags = 0; |
| 5174 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5175 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5176 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5177 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5178 | |
| 5179 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5180 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5181 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5182 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5183 | MockWrite( |
| 5184 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5185 | "Host: www.example.org\r\n" |
| 5186 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5187 | }; |
| 5188 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5189 | MockRead data_reads1[] = { |
| 5190 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5191 | // Give a couple authenticate options (only the middle one is actually |
| 5192 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5193 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5194 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5195 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5196 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5197 | // Large content-length -- won't matter, as connection will be reset. |
| 5198 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5199 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5200 | }; |
| 5201 | |
| 5202 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5203 | // request we should be issuing -- the final header line contains the |
| 5204 | // proxy's credentials. |
| 5205 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5206 | MockWrite( |
| 5207 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5208 | "Host: www.example.org\r\n" |
| 5209 | "Proxy-Connection: keep-alive\r\n" |
| 5210 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5211 | }; |
| 5212 | |
| 5213 | // Now the proxy server lets the request pass through to origin server. |
| 5214 | // The origin server responds with a 401. |
| 5215 | MockRead data_reads2[] = { |
| 5216 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5217 | // Note: We are using the same realm-name as the proxy server. This is |
| 5218 | // completely valid, as realms are unique across hosts. |
| 5219 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5220 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5221 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5222 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5223 | }; |
| 5224 | |
| 5225 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5226 | // the credentials for both the proxy and origin server. |
| 5227 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5228 | MockWrite( |
| 5229 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5230 | "Host: www.example.org\r\n" |
| 5231 | "Proxy-Connection: keep-alive\r\n" |
| 5232 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5233 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5234 | }; |
| 5235 | |
| 5236 | // Lastly we get the desired content. |
| 5237 | MockRead data_reads3[] = { |
| 5238 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5239 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5240 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5241 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5242 | }; |
| 5243 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5244 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5245 | data_writes1, arraysize(data_writes1)); |
| 5246 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5247 | data_writes2, arraysize(data_writes2)); |
| 5248 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5249 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5250 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5251 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5252 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5254 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5256 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5257 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5258 | |
| 5259 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5260 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5261 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5262 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5263 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5264 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5266 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5267 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5268 | rv = trans->RestartWithAuth( |
| 5269 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5270 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5271 | |
| 5272 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5273 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5274 | |
| 5275 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5276 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5277 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5279 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5281 | rv = trans->RestartWithAuth( |
| 5282 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5283 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5284 | |
| 5285 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5286 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5287 | |
| 5288 | response = trans->GetResponseInfo(); |
| 5289 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5290 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5291 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5292 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5293 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5294 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5295 | // authorization headers. |
| 5296 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5297 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5298 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5299 | // bytes in the debugger. |
| 5300 | |
| 5301 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5302 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5303 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5304 | request.method = "GET"; |
| 5305 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5306 | |
| 5307 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5308 | // to other auth schemes. |
| 5309 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5310 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5311 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5312 | MockGetHostName); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5313 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5314 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5315 | MockWrite data_writes1[] = { |
| 5316 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5317 | "Host: 172.22.68.17\r\n" |
| 5318 | "Connection: keep-alive\r\n\r\n"), |
| 5319 | }; |
| 5320 | |
| 5321 | MockRead data_reads1[] = { |
| 5322 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5323 | // Negotiate and NTLM are often requested together. However, we only want |
| 5324 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5325 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5326 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5327 | MockRead("Connection: close\r\n"), |
| 5328 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5329 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5330 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5331 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5332 | }; |
| 5333 | |
| 5334 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5335 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5336 | // request we should be issuing -- the final header line contains a Type |
| 5337 | // 1 message. |
| 5338 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5339 | "Host: 172.22.68.17\r\n" |
| 5340 | "Connection: keep-alive\r\n" |
| 5341 | "Authorization: NTLM " |
| 5342 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5343 | |
| 5344 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5345 | // (the credentials for the origin server). The second request continues |
| 5346 | // on the same connection. |
| 5347 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5348 | "Host: 172.22.68.17\r\n" |
| 5349 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5350 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5351 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5352 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5353 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5354 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5355 | }; |
| 5356 | |
| 5357 | MockRead data_reads2[] = { |
| 5358 | // The origin server responds with a Type 2 message. |
| 5359 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5360 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5361 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5362 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5363 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5364 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5365 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5366 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5367 | "BtAAAAAAA=\r\n"), |
| 5368 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5369 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5370 | MockRead("You are not authorized to view this page\r\n"), |
| 5371 | |
| 5372 | // Lastly we get the desired content. |
| 5373 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5374 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5375 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5376 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5377 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5378 | }; |
| 5379 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5380 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5381 | data_writes1, arraysize(data_writes1)); |
| 5382 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5383 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5384 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5385 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5387 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5388 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5389 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5390 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5391 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5392 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5393 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5394 | |
| 5395 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5396 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5397 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5398 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5399 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5400 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5401 | ASSERT_FALSE(response == NULL); |
| 5402 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5404 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5405 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5406 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5407 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5409 | |
| 5410 | rv = callback2.WaitForResult(); |
| 5411 | EXPECT_EQ(OK, rv); |
| 5412 | |
| 5413 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5414 | |
| 5415 | response = trans->GetResponseInfo(); |
| 5416 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5417 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5419 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5421 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5422 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5423 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5424 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5425 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5426 | |
| 5427 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5428 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5429 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5430 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5431 | } |
| 5432 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5433 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5434 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5435 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5436 | request.method = "GET"; |
| 5437 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5438 | request.load_flags = 0; |
| 5439 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5440 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5441 | MockGetHostName); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5442 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5443 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5444 | MockWrite data_writes1[] = { |
| 5445 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5446 | "Host: 172.22.68.17\r\n" |
| 5447 | "Connection: keep-alive\r\n\r\n"), |
| 5448 | }; |
| 5449 | |
| 5450 | MockRead data_reads1[] = { |
| 5451 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5452 | // Negotiate and NTLM are often requested together. However, we only want |
| 5453 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5454 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5455 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5456 | MockRead("Connection: close\r\n"), |
| 5457 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5458 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5459 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5460 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5461 | }; |
| 5462 | |
| 5463 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5464 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5465 | // request we should be issuing -- the final header line contains a Type |
| 5466 | // 1 message. |
| 5467 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5468 | "Host: 172.22.68.17\r\n" |
| 5469 | "Connection: keep-alive\r\n" |
| 5470 | "Authorization: NTLM " |
| 5471 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5472 | |
| 5473 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5474 | // (the credentials for the origin server). The second request continues |
| 5475 | // on the same connection. |
| 5476 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5477 | "Host: 172.22.68.17\r\n" |
| 5478 | "Connection: keep-alive\r\n" |
| 5479 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5480 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5481 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5482 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5483 | "4Ww7b7E=\r\n\r\n"), |
| 5484 | }; |
| 5485 | |
| 5486 | MockRead data_reads2[] = { |
| 5487 | // The origin server responds with a Type 2 message. |
| 5488 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5489 | MockRead("WWW-Authenticate: NTLM " |
| 5490 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5491 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5492 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5493 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5494 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5495 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5496 | "BtAAAAAAA=\r\n"), |
| 5497 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5498 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5499 | MockRead("You are not authorized to view this page\r\n"), |
| 5500 | |
| 5501 | // Wrong password. |
| 5502 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5503 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5504 | MockRead("Connection: close\r\n"), |
| 5505 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5506 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5507 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5508 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5509 | }; |
| 5510 | |
| 5511 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5512 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5513 | // request we should be issuing -- the final header line contains a Type |
| 5514 | // 1 message. |
| 5515 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5516 | "Host: 172.22.68.17\r\n" |
| 5517 | "Connection: keep-alive\r\n" |
| 5518 | "Authorization: NTLM " |
| 5519 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5520 | |
| 5521 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5522 | // (the credentials for the origin server). The second request continues |
| 5523 | // on the same connection. |
| 5524 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5525 | "Host: 172.22.68.17\r\n" |
| 5526 | "Connection: keep-alive\r\n" |
| 5527 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5528 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5529 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5530 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5531 | "+4MUm7c=\r\n\r\n"), |
| 5532 | }; |
| 5533 | |
| 5534 | MockRead data_reads3[] = { |
| 5535 | // The origin server responds with a Type 2 message. |
| 5536 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5537 | MockRead("WWW-Authenticate: NTLM " |
| 5538 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5539 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5540 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5541 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5542 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5543 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5544 | "BtAAAAAAA=\r\n"), |
| 5545 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5546 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5547 | MockRead("You are not authorized to view this page\r\n"), |
| 5548 | |
| 5549 | // Lastly we get the desired content. |
| 5550 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5551 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5552 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5553 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5554 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5555 | }; |
| 5556 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5558 | data_writes1, arraysize(data_writes1)); |
| 5559 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5560 | data_writes2, arraysize(data_writes2)); |
| 5561 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5562 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5563 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5564 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5565 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5567 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5568 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5569 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5572 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5573 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5574 | |
| 5575 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5576 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5577 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5578 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5579 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5580 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5581 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5582 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5584 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5585 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5586 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5587 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5588 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5589 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5590 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5591 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5592 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5593 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5594 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5595 | TestCompletionCallback callback3; |
| 5596 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5597 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5598 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5599 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5600 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5601 | |
| 5602 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5603 | ASSERT_FALSE(response == NULL); |
| 5604 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5606 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5607 | |
| 5608 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5609 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5610 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5612 | |
| 5613 | rv = callback4.WaitForResult(); |
| 5614 | EXPECT_EQ(OK, rv); |
| 5615 | |
| 5616 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5618 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5619 | |
| 5620 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5621 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5622 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5623 | |
| 5624 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5625 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5626 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5627 | response = trans->GetResponseInfo(); |
| 5628 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5629 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5630 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5631 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5632 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5633 | // Test reading a server response which has only headers, and no body. |
| 5634 | // After some maximum number of bytes is consumed, the transaction should |
| 5635 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5636 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5637 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5638 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5639 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5640 | request.load_flags = 0; |
| 5641 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5642 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5643 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5644 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5645 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5646 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5647 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5648 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5649 | |
| 5650 | MockRead data_reads[] = { |
| 5651 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5652 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5653 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5654 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5655 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5656 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5657 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5659 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5661 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5662 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5663 | |
| 5664 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5665 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5666 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5667 | |
| 5668 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5669 | // establish tunnel. |
| 5670 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5671 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5672 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5673 | HttpRequestInfo request; |
| 5674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5675 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5676 | request.load_flags = 0; |
| 5677 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5678 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5679 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5680 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5681 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5682 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5683 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5684 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5685 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5686 | // Since we have proxy, should try to establish tunnel. |
| 5687 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5688 | MockWrite( |
| 5689 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5690 | "Host: www.example.org\r\n" |
| 5691 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5692 | }; |
| 5693 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5694 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5695 | // connection. Usually a proxy would return 501 (not implemented), |
| 5696 | // or 200 (tunnel established). |
| 5697 | MockRead data_reads1[] = { |
| 5698 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5699 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5700 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5701 | }; |
| 5702 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5703 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5704 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5705 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5707 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5709 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5710 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5711 | |
| 5712 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5713 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5714 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5715 | // Empty the current queue. This is necessary because idle sockets are |
| 5716 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5717 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5718 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5719 | // We now check to make sure the TCPClientSocket was not added back to |
| 5720 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5721 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5722 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5723 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5724 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5725 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5726 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5727 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5728 | // 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] | 5729 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5730 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5731 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5732 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5733 | request.load_flags = 0; |
| 5734 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5735 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5736 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5737 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5738 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5739 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5740 | MockRead data_reads[] = { |
| 5741 | // A part of the response body is received with the response headers. |
| 5742 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5743 | // The rest of the response body is received in two parts. |
| 5744 | MockRead("lo"), |
| 5745 | MockRead(" world"), |
| 5746 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5747 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5748 | }; |
| 5749 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5750 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5753 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5755 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5757 | |
| 5758 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5759 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5760 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5761 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5762 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5763 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5764 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5765 | std::string status_line = response->headers->GetStatusLine(); |
| 5766 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5767 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5768 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5769 | |
| 5770 | std::string response_data; |
| 5771 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5772 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5773 | EXPECT_EQ("hello world", response_data); |
| 5774 | |
| 5775 | // Empty the current queue. This is necessary because idle sockets are |
| 5776 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5777 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5778 | |
| 5779 | // 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] | 5780 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5781 | } |
| 5782 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5783 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5784 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5785 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5786 | HttpRequestInfo request; |
| 5787 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5788 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5789 | request.load_flags = 0; |
| 5790 | |
| 5791 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5792 | MockWrite( |
| 5793 | "GET / HTTP/1.1\r\n" |
| 5794 | "Host: www.example.org\r\n" |
| 5795 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5796 | }; |
| 5797 | |
| 5798 | MockRead data_reads[] = { |
| 5799 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5800 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5801 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5802 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5803 | }; |
| 5804 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5805 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5807 | |
| 5808 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5809 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5810 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5812 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5813 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5814 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5815 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5816 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5818 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5819 | |
| 5820 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5821 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5822 | |
| 5823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5824 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5825 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5826 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5827 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5828 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5829 | |
| 5830 | std::string response_data; |
| 5831 | rv = ReadTransaction(trans.get(), &response_data); |
| 5832 | EXPECT_EQ(OK, rv); |
| 5833 | EXPECT_EQ("hello world", response_data); |
| 5834 | |
| 5835 | // Empty the current queue. This is necessary because idle sockets are |
| 5836 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5837 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5838 | |
| 5839 | // 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] | 5840 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5844 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5845 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5846 | HttpRequestInfo request; |
| 5847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5848 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5849 | request.load_flags = 0; |
| 5850 | |
| 5851 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5852 | MockWrite( |
| 5853 | "GET / HTTP/1.1\r\n" |
| 5854 | "Host: www.example.org\r\n" |
| 5855 | "Connection: keep-alive\r\n\r\n"), |
| 5856 | MockWrite( |
| 5857 | "GET / HTTP/1.1\r\n" |
| 5858 | "Host: www.example.org\r\n" |
| 5859 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5860 | }; |
| 5861 | |
| 5862 | MockRead data_reads[] = { |
| 5863 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5864 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5865 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5866 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5867 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5868 | }; |
| 5869 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5870 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5871 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5872 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5874 | |
| 5875 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5876 | data_writes, arraysize(data_writes)); |
| 5877 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5878 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5880 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5882 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5883 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5884 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5885 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5886 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5888 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5889 | |
| 5890 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5891 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5892 | |
| 5893 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5894 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5895 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5896 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5897 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5898 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5899 | |
| 5900 | std::string response_data; |
| 5901 | rv = ReadTransaction(trans.get(), &response_data); |
| 5902 | EXPECT_EQ(OK, rv); |
| 5903 | EXPECT_EQ("hello world", response_data); |
| 5904 | |
| 5905 | // Empty the current queue. This is necessary because idle sockets are |
| 5906 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5907 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5908 | |
| 5909 | // 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] | 5910 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5911 | |
| 5912 | // Now start the second transaction, which should reuse the previous socket. |
| 5913 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5914 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5916 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5917 | |
| 5918 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5919 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5920 | |
| 5921 | response = trans->GetResponseInfo(); |
| 5922 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5923 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5924 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5925 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5926 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5927 | |
| 5928 | rv = ReadTransaction(trans.get(), &response_data); |
| 5929 | EXPECT_EQ(OK, rv); |
| 5930 | EXPECT_EQ("hello world", response_data); |
| 5931 | |
| 5932 | // Empty the current queue. This is necessary because idle sockets are |
| 5933 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5934 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5935 | |
| 5936 | // 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] | 5937 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5938 | } |
| 5939 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5940 | // Make sure that we recycle a socket after a zero-length response. |
| 5941 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5942 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5943 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5944 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5945 | request.url = GURL( |
| 5946 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5947 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5948 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5949 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5950 | request.load_flags = 0; |
| 5951 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 5952 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5953 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5954 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5955 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5956 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5957 | MockRead data_reads[] = { |
| 5958 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5959 | "Content-Length: 0\r\n" |
| 5960 | "Content-Type: text/html\r\n\r\n"), |
| 5961 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5962 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5963 | }; |
| 5964 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5965 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5966 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5968 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5970 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5971 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5972 | |
| 5973 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5974 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5975 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5976 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5977 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5978 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5979 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5980 | std::string status_line = response->headers->GetStatusLine(); |
| 5981 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 5982 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5983 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5984 | |
| 5985 | std::string response_data; |
| 5986 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5987 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5988 | EXPECT_EQ("", response_data); |
| 5989 | |
| 5990 | // Empty the current queue. This is necessary because idle sockets are |
| 5991 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5992 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5993 | |
| 5994 | // 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] | 5995 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5996 | } |
| 5997 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5998 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 5999 | ScopedVector<UploadElementReader> element_readers; |
| 6000 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 6001 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6002 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6003 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6004 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6005 | // after use. |
| 6006 | request[0].method = "GET"; |
| 6007 | request[0].url = GURL("http://www.google.com/"); |
| 6008 | request[0].load_flags = 0; |
| 6009 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6010 | // transaction 1. The first attempts fails when writing the POST data. |
| 6011 | // This causes the transaction to retry with a new socket. The second |
| 6012 | // attempt succeeds. |
| 6013 | request[1].method = "POST"; |
| 6014 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6015 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6016 | request[1].load_flags = 0; |
| 6017 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6018 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6019 | |
| 6020 | // The first socket is used for transaction 1 and the first attempt of |
| 6021 | // transaction 2. |
| 6022 | |
| 6023 | // The response of transaction 1. |
| 6024 | MockRead data_reads1[] = { |
| 6025 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6026 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6027 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6028 | }; |
| 6029 | // The mock write results of transaction 1 and the first attempt of |
| 6030 | // transaction 2. |
| 6031 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6032 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6033 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6034 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6035 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6036 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6037 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6038 | |
| 6039 | // The second socket is used for the second attempt of transaction 2. |
| 6040 | |
| 6041 | // The response of transaction 2. |
| 6042 | MockRead data_reads2[] = { |
| 6043 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6044 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6045 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6046 | }; |
| 6047 | // The mock write results of the second attempt of transaction 2. |
| 6048 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6049 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6050 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6051 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6052 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6053 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6054 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6055 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6056 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6057 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6058 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6059 | "hello world", "welcome" |
| 6060 | }; |
| 6061 | |
| 6062 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6063 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6066 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6068 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6069 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6070 | |
| 6071 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6072 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6073 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6075 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6076 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6077 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6078 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6079 | |
| 6080 | std::string response_data; |
| 6081 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6082 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6083 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6084 | } |
| 6085 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6086 | |
| 6087 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6088 | // 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] | 6089 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6090 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6091 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6092 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6093 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6094 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6095 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6096 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6097 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6098 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6099 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6100 | // The password contains an escaped character -- for this test to pass it |
| 6101 | // will need to be unescaped by HttpNetworkTransaction. |
| 6102 | EXPECT_EQ("b%40r", request.url.password()); |
| 6103 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6104 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6105 | MockWrite( |
| 6106 | "GET / HTTP/1.1\r\n" |
| 6107 | "Host: www.example.org\r\n" |
| 6108 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6109 | }; |
| 6110 | |
| 6111 | MockRead data_reads1[] = { |
| 6112 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6113 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6114 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6115 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6116 | }; |
| 6117 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6118 | // After the challenge above, the transaction will be restarted using the |
| 6119 | // identity from the url (foo, b@r) to answer the challenge. |
| 6120 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6121 | MockWrite( |
| 6122 | "GET / HTTP/1.1\r\n" |
| 6123 | "Host: www.example.org\r\n" |
| 6124 | "Connection: keep-alive\r\n" |
| 6125 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6126 | }; |
| 6127 | |
| 6128 | MockRead data_reads2[] = { |
| 6129 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6130 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6131 | MockRead(SYNCHRONOUS, OK), |
| 6132 | }; |
| 6133 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6134 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6135 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6136 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6137 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6138 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6139 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6141 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6142 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6144 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6145 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6146 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6147 | |
| 6148 | TestCompletionCallback callback2; |
| 6149 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6150 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6151 | rv = callback2.WaitForResult(); |
| 6152 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6153 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6154 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6155 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6156 | ASSERT_TRUE(response != NULL); |
| 6157 | |
| 6158 | // There is no challenge info, since the identity in URL worked. |
| 6159 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6160 | |
| 6161 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6162 | |
| 6163 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6164 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6168 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6169 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6170 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6171 | HttpRequestInfo request; |
| 6172 | request.method = "GET"; |
| 6173 | // Note: the URL has a username:password in it. The password "baz" is |
| 6174 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6175 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6176 | |
| 6177 | request.load_flags = LOAD_NORMAL; |
| 6178 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6179 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6180 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6182 | |
| 6183 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6184 | MockWrite( |
| 6185 | "GET / HTTP/1.1\r\n" |
| 6186 | "Host: www.example.org\r\n" |
| 6187 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6188 | }; |
| 6189 | |
| 6190 | MockRead data_reads1[] = { |
| 6191 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6192 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6193 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6194 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6195 | }; |
| 6196 | |
| 6197 | // After the challenge above, the transaction will be restarted using the |
| 6198 | // identity from the url (foo, baz) to answer the challenge. |
| 6199 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6200 | MockWrite( |
| 6201 | "GET / HTTP/1.1\r\n" |
| 6202 | "Host: www.example.org\r\n" |
| 6203 | "Connection: keep-alive\r\n" |
| 6204 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6205 | }; |
| 6206 | |
| 6207 | MockRead data_reads2[] = { |
| 6208 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6209 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6210 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6211 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6212 | }; |
| 6213 | |
| 6214 | // After the challenge above, the transaction will be restarted using the |
| 6215 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6216 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6217 | MockWrite( |
| 6218 | "GET / HTTP/1.1\r\n" |
| 6219 | "Host: www.example.org\r\n" |
| 6220 | "Connection: keep-alive\r\n" |
| 6221 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6222 | }; |
| 6223 | |
| 6224 | MockRead data_reads3[] = { |
| 6225 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6226 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6227 | MockRead(SYNCHRONOUS, OK), |
| 6228 | }; |
| 6229 | |
| 6230 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6231 | data_writes1, arraysize(data_writes1)); |
| 6232 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6233 | data_writes2, arraysize(data_writes2)); |
| 6234 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6235 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6236 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6237 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6238 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6239 | |
| 6240 | TestCompletionCallback callback1; |
| 6241 | |
| 6242 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6244 | |
| 6245 | rv = callback1.WaitForResult(); |
| 6246 | EXPECT_EQ(OK, rv); |
| 6247 | |
| 6248 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6249 | TestCompletionCallback callback2; |
| 6250 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6251 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6252 | rv = callback2.WaitForResult(); |
| 6253 | EXPECT_EQ(OK, rv); |
| 6254 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6255 | |
| 6256 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6257 | ASSERT_TRUE(response != NULL); |
| 6258 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6259 | |
| 6260 | TestCompletionCallback callback3; |
| 6261 | rv = trans->RestartWithAuth( |
| 6262 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6264 | rv = callback3.WaitForResult(); |
| 6265 | EXPECT_EQ(OK, rv); |
| 6266 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6267 | |
| 6268 | response = trans->GetResponseInfo(); |
| 6269 | ASSERT_TRUE(response != NULL); |
| 6270 | |
| 6271 | // There is no challenge info, since the identity worked. |
| 6272 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6273 | |
| 6274 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6275 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6276 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6277 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6278 | } |
| 6279 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6280 | |
| 6281 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6282 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6283 | // from the URL should never be used. |
| 6284 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6285 | HttpRequestInfo request; |
| 6286 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6287 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6288 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6289 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6290 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6291 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6292 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6293 | |
| 6294 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6295 | MockWrite( |
| 6296 | "GET / HTTP/1.1\r\n" |
| 6297 | "Host: www.example.org\r\n" |
| 6298 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6299 | }; |
| 6300 | |
| 6301 | MockRead data_reads1[] = { |
| 6302 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6303 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6304 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6305 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6306 | }; |
| 6307 | |
| 6308 | // After the challenge above, the transaction will be restarted using the |
| 6309 | // identity supplied by the user, not the one in the URL, to answer the |
| 6310 | // challenge. |
| 6311 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6312 | MockWrite( |
| 6313 | "GET / HTTP/1.1\r\n" |
| 6314 | "Host: www.example.org\r\n" |
| 6315 | "Connection: keep-alive\r\n" |
| 6316 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6317 | }; |
| 6318 | |
| 6319 | MockRead data_reads3[] = { |
| 6320 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6321 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6322 | MockRead(SYNCHRONOUS, OK), |
| 6323 | }; |
| 6324 | |
| 6325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6326 | data_writes1, arraysize(data_writes1)); |
| 6327 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6328 | data_writes3, arraysize(data_writes3)); |
| 6329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6330 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6331 | |
| 6332 | TestCompletionCallback callback1; |
| 6333 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6334 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6335 | rv = callback1.WaitForResult(); |
| 6336 | EXPECT_EQ(OK, rv); |
| 6337 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6338 | |
| 6339 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6340 | ASSERT_TRUE(response != NULL); |
| 6341 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6342 | |
| 6343 | TestCompletionCallback callback3; |
| 6344 | rv = trans->RestartWithAuth( |
| 6345 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6346 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6347 | rv = callback3.WaitForResult(); |
| 6348 | EXPECT_EQ(OK, rv); |
| 6349 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6350 | |
| 6351 | response = trans->GetResponseInfo(); |
| 6352 | ASSERT_TRUE(response != NULL); |
| 6353 | |
| 6354 | // There is no challenge info, since the identity worked. |
| 6355 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6356 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6357 | |
| 6358 | // Empty the current queue. |
| 6359 | base::MessageLoop::current()->RunUntilIdle(); |
| 6360 | } |
| 6361 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6362 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6363 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6364 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6365 | |
| 6366 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6367 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6368 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6370 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6371 | request.load_flags = 0; |
| 6372 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6373 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6375 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6376 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6377 | MockWrite( |
| 6378 | "GET /x/y/z HTTP/1.1\r\n" |
| 6379 | "Host: www.example.org\r\n" |
| 6380 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6381 | }; |
| 6382 | |
| 6383 | MockRead data_reads1[] = { |
| 6384 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6385 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6386 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6387 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6388 | }; |
| 6389 | |
| 6390 | // Resend with authorization (username=foo, password=bar) |
| 6391 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6392 | MockWrite( |
| 6393 | "GET /x/y/z HTTP/1.1\r\n" |
| 6394 | "Host: www.example.org\r\n" |
| 6395 | "Connection: keep-alive\r\n" |
| 6396 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6397 | }; |
| 6398 | |
| 6399 | // Sever accepts the authorization. |
| 6400 | MockRead data_reads2[] = { |
| 6401 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6402 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6403 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6404 | }; |
| 6405 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6406 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6407 | data_writes1, arraysize(data_writes1)); |
| 6408 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6409 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6410 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6411 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6413 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6415 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6416 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6417 | |
| 6418 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6419 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6420 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6421 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6422 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6423 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6425 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6427 | rv = trans->RestartWithAuth( |
| 6428 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6430 | |
| 6431 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6432 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6433 | |
| 6434 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6435 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6436 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6437 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6438 | } |
| 6439 | |
| 6440 | // ------------------------------------------------------------------------ |
| 6441 | |
| 6442 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6443 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6444 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6445 | request.method = "GET"; |
| 6446 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6447 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6448 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6449 | request.load_flags = 0; |
| 6450 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6451 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6452 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6453 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6454 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6455 | MockWrite( |
| 6456 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6457 | "Host: www.example.org\r\n" |
| 6458 | "Connection: keep-alive\r\n" |
| 6459 | // Send preemptive authorization for MyRealm1 |
| 6460 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6461 | }; |
| 6462 | |
| 6463 | // The server didn't like the preemptive authorization, and |
| 6464 | // challenges us for a different realm (MyRealm2). |
| 6465 | MockRead data_reads1[] = { |
| 6466 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6467 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6468 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6469 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6470 | }; |
| 6471 | |
| 6472 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6473 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6474 | MockWrite( |
| 6475 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6476 | "Host: www.example.org\r\n" |
| 6477 | "Connection: keep-alive\r\n" |
| 6478 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6479 | }; |
| 6480 | |
| 6481 | // Sever accepts the authorization. |
| 6482 | MockRead data_reads2[] = { |
| 6483 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6484 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6485 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6486 | }; |
| 6487 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6488 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6489 | data_writes1, arraysize(data_writes1)); |
| 6490 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6491 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6492 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6493 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6495 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6497 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6499 | |
| 6500 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6501 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6502 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6503 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6504 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6505 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6506 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6507 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6508 | response->auth_challenge->challenger.ToString()); |
| 6509 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 6510 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6512 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6514 | rv = trans->RestartWithAuth( |
| 6515 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6516 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6517 | |
| 6518 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6519 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6520 | |
| 6521 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6522 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6523 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6524 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6525 | } |
| 6526 | |
| 6527 | // ------------------------------------------------------------------------ |
| 6528 | |
| 6529 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6530 | // succeed with preemptive authorization. |
| 6531 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6532 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6533 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6534 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6535 | request.load_flags = 0; |
| 6536 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6537 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6538 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6539 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6540 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6541 | MockWrite( |
| 6542 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6543 | "Host: www.example.org\r\n" |
| 6544 | "Connection: keep-alive\r\n" |
| 6545 | // The authorization for MyRealm1 gets sent preemptively |
| 6546 | // (since the url is in the same protection space) |
| 6547 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6548 | }; |
| 6549 | |
| 6550 | // Sever accepts the preemptive authorization |
| 6551 | MockRead data_reads1[] = { |
| 6552 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6553 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6554 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6555 | }; |
| 6556 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6558 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6561 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6563 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6565 | |
| 6566 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6567 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6568 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6569 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6570 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6571 | |
| 6572 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6573 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6574 | } |
| 6575 | |
| 6576 | // ------------------------------------------------------------------------ |
| 6577 | |
| 6578 | // Transaction 4: request another URL in MyRealm (however the |
| 6579 | // url is not known to belong to the protection space, so no pre-auth). |
| 6580 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6581 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6582 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6583 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6584 | request.load_flags = 0; |
| 6585 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6586 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6587 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6588 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6589 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6590 | MockWrite( |
| 6591 | "GET /x/1 HTTP/1.1\r\n" |
| 6592 | "Host: www.example.org\r\n" |
| 6593 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6594 | }; |
| 6595 | |
| 6596 | MockRead data_reads1[] = { |
| 6597 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6598 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6599 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6600 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6601 | }; |
| 6602 | |
| 6603 | // Resend with authorization from MyRealm's cache. |
| 6604 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6605 | MockWrite( |
| 6606 | "GET /x/1 HTTP/1.1\r\n" |
| 6607 | "Host: www.example.org\r\n" |
| 6608 | "Connection: keep-alive\r\n" |
| 6609 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6610 | }; |
| 6611 | |
| 6612 | // Sever accepts the authorization. |
| 6613 | MockRead data_reads2[] = { |
| 6614 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6615 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6616 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6617 | }; |
| 6618 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6619 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6620 | data_writes1, arraysize(data_writes1)); |
| 6621 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6622 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6623 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6624 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6626 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6628 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6629 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6630 | |
| 6631 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6632 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6633 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6634 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6635 | TestCompletionCallback callback2; |
| 6636 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6637 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6638 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6639 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6640 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6641 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6642 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6643 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6644 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6645 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6646 | } |
| 6647 | |
| 6648 | // ------------------------------------------------------------------------ |
| 6649 | |
| 6650 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6651 | // cached identity. Should invalidate and re-prompt. |
| 6652 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6653 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6654 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6655 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6656 | request.load_flags = 0; |
| 6657 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6658 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6659 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6660 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6661 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6662 | MockWrite( |
| 6663 | "GET /p/q/t HTTP/1.1\r\n" |
| 6664 | "Host: www.example.org\r\n" |
| 6665 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6666 | }; |
| 6667 | |
| 6668 | MockRead data_reads1[] = { |
| 6669 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6670 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6671 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6672 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6673 | }; |
| 6674 | |
| 6675 | // Resend with authorization from cache for MyRealm. |
| 6676 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6677 | MockWrite( |
| 6678 | "GET /p/q/t HTTP/1.1\r\n" |
| 6679 | "Host: www.example.org\r\n" |
| 6680 | "Connection: keep-alive\r\n" |
| 6681 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6682 | }; |
| 6683 | |
| 6684 | // Sever rejects the authorization. |
| 6685 | MockRead data_reads2[] = { |
| 6686 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6687 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6688 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6689 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6690 | }; |
| 6691 | |
| 6692 | // At this point we should prompt for new credentials for MyRealm. |
| 6693 | // Restart with username=foo3, password=foo4. |
| 6694 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6695 | MockWrite( |
| 6696 | "GET /p/q/t HTTP/1.1\r\n" |
| 6697 | "Host: www.example.org\r\n" |
| 6698 | "Connection: keep-alive\r\n" |
| 6699 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6700 | }; |
| 6701 | |
| 6702 | // Sever accepts the authorization. |
| 6703 | MockRead data_reads3[] = { |
| 6704 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6705 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6706 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6707 | }; |
| 6708 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6709 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6710 | data_writes1, arraysize(data_writes1)); |
| 6711 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6712 | data_writes2, arraysize(data_writes2)); |
| 6713 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6714 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6715 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6716 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6717 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6719 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6721 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6723 | |
| 6724 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6725 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6726 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6727 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6728 | TestCompletionCallback callback2; |
| 6729 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6730 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6731 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6732 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6733 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6734 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6735 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6736 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6737 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6739 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6741 | rv = trans->RestartWithAuth( |
| 6742 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6744 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6745 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6746 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6747 | |
| 6748 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6749 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6750 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6751 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6752 | } |
| 6753 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6754 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6755 | // Tests that nonce count increments when multiple auth attempts |
| 6756 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6757 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6758 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6759 | new HttpAuthHandlerDigest::Factory(); |
| 6760 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6761 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6762 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6763 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6764 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6765 | |
| 6766 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6767 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6768 | HttpRequestInfo request; |
| 6769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6770 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6771 | request.load_flags = 0; |
| 6772 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6773 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6774 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6775 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6776 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6777 | MockWrite( |
| 6778 | "GET /x/y/z HTTP/1.1\r\n" |
| 6779 | "Host: www.example.org\r\n" |
| 6780 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6781 | }; |
| 6782 | |
| 6783 | MockRead data_reads1[] = { |
| 6784 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6785 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6786 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6788 | }; |
| 6789 | |
| 6790 | // Resend with authorization (username=foo, password=bar) |
| 6791 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6792 | MockWrite( |
| 6793 | "GET /x/y/z HTTP/1.1\r\n" |
| 6794 | "Host: www.example.org\r\n" |
| 6795 | "Connection: keep-alive\r\n" |
| 6796 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6797 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6798 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6799 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6800 | }; |
| 6801 | |
| 6802 | // Sever accepts the authorization. |
| 6803 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6804 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6806 | }; |
| 6807 | |
| 6808 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6809 | data_writes1, arraysize(data_writes1)); |
| 6810 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6811 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6812 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6813 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6815 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6817 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6819 | |
| 6820 | rv = callback1.WaitForResult(); |
| 6821 | EXPECT_EQ(OK, rv); |
| 6822 | |
| 6823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6824 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6825 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6827 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6829 | rv = trans->RestartWithAuth( |
| 6830 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6832 | |
| 6833 | rv = callback2.WaitForResult(); |
| 6834 | EXPECT_EQ(OK, rv); |
| 6835 | |
| 6836 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6837 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6838 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6839 | } |
| 6840 | |
| 6841 | // ------------------------------------------------------------------------ |
| 6842 | |
| 6843 | // Transaction 2: Request another resource in digestive's protection space. |
| 6844 | // This will preemptively add an Authorization header which should have an |
| 6845 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6846 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6847 | HttpRequestInfo request; |
| 6848 | request.method = "GET"; |
| 6849 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6850 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6851 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6852 | request.load_flags = 0; |
| 6853 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6854 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6855 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6856 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6857 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6858 | MockWrite( |
| 6859 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6860 | "Host: www.example.org\r\n" |
| 6861 | "Connection: keep-alive\r\n" |
| 6862 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6863 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6864 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6865 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6866 | }; |
| 6867 | |
| 6868 | // Sever accepts the authorization. |
| 6869 | MockRead data_reads1[] = { |
| 6870 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6871 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6872 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6873 | }; |
| 6874 | |
| 6875 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6876 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6879 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6881 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6882 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6883 | |
| 6884 | rv = callback1.WaitForResult(); |
| 6885 | EXPECT_EQ(OK, rv); |
| 6886 | |
| 6887 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6888 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6889 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6890 | } |
| 6891 | } |
| 6892 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6893 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6894 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6895 | // Create a transaction (the dependencies aren't important). |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6896 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6897 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6898 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6899 | |
| 6900 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6901 | trans->read_buf_ = new IOBuffer(15); |
| 6902 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6903 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6904 | |
| 6905 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6906 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6907 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6908 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6909 | response->response_time = base::Time::Now(); |
| 6910 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6911 | |
| 6912 | { // Setup state for response_.vary_data |
| 6913 | HttpRequestInfo request; |
| 6914 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6915 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6916 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6917 | request.extra_headers.SetHeader("Foo", "1"); |
| 6918 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6919 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6920 | } |
| 6921 | |
| 6922 | // Cause the above state to be reset. |
| 6923 | trans->ResetStateForRestart(); |
| 6924 | |
| 6925 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6926 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6927 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6928 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6929 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6930 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6931 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6932 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6933 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6934 | } |
| 6935 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6936 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6937 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6938 | HttpRequestInfo request; |
| 6939 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6940 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6941 | request.load_flags = 0; |
| 6942 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 6943 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6944 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6945 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6946 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6947 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6948 | MockWrite( |
| 6949 | "GET / HTTP/1.1\r\n" |
| 6950 | "Host: www.example.org\r\n" |
| 6951 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6952 | }; |
| 6953 | |
| 6954 | MockRead data_reads[] = { |
| 6955 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6957 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6959 | }; |
| 6960 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6961 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6962 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6963 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6964 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6965 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6966 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6967 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6968 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6972 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6973 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6974 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6976 | |
| 6977 | rv = callback.WaitForResult(); |
| 6978 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 6979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6980 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6981 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6982 | |
| 6983 | rv = callback.WaitForResult(); |
| 6984 | EXPECT_EQ(OK, rv); |
| 6985 | |
| 6986 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6987 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6988 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6989 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6990 | } |
| 6991 | |
| 6992 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 6993 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6994 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6995 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6996 | |
| 6997 | HttpRequestInfo request; |
| 6998 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6999 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7000 | request.load_flags = 0; |
| 7001 | |
| 7002 | MockWrite proxy_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7003 | MockWrite( |
| 7004 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7005 | "Host: www.example.org\r\n" |
| 7006 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7007 | }; |
| 7008 | |
| 7009 | MockRead proxy_reads[] = { |
| 7010 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7011 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7012 | }; |
| 7013 | |
| 7014 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7015 | MockWrite( |
| 7016 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7017 | "Host: www.example.org\r\n" |
| 7018 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7019 | MockWrite( |
| 7020 | "GET / HTTP/1.1\r\n" |
| 7021 | "Host: www.example.org\r\n" |
| 7022 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7023 | }; |
| 7024 | |
| 7025 | MockRead data_reads[] = { |
| 7026 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7027 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7028 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7029 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7030 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7031 | }; |
| 7032 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7033 | StaticSocketDataProvider ssl_bad_certificate( |
| 7034 | proxy_reads, arraysize(proxy_reads), |
| 7035 | proxy_writes, arraysize(proxy_writes)); |
| 7036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7037 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7038 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7039 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7040 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7041 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7042 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7043 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7046 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7047 | |
| 7048 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7049 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7050 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7051 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7052 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7053 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7055 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7056 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7057 | |
| 7058 | rv = callback.WaitForResult(); |
| 7059 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7061 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7062 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7063 | |
| 7064 | rv = callback.WaitForResult(); |
| 7065 | EXPECT_EQ(OK, rv); |
| 7066 | |
| 7067 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7068 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7069 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7070 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7071 | } |
| 7072 | } |
| 7073 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7074 | |
| 7075 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7076 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7077 | session_deps_.proxy_service = |
| 7078 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7079 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7080 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7081 | |
| 7082 | HttpRequestInfo request; |
| 7083 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7084 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7085 | request.load_flags = 0; |
| 7086 | |
| 7087 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7088 | MockWrite( |
| 7089 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7090 | "Host: www.example.org\r\n" |
| 7091 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7092 | MockWrite( |
| 7093 | "GET / HTTP/1.1\r\n" |
| 7094 | "Host: www.example.org\r\n" |
| 7095 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7096 | }; |
| 7097 | |
| 7098 | MockRead data_reads[] = { |
| 7099 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7100 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7101 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7102 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7103 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7104 | }; |
| 7105 | |
| 7106 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7107 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7108 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7109 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7110 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7115 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7116 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7117 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7118 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7120 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7121 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7122 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7123 | |
| 7124 | rv = callback.WaitForResult(); |
| 7125 | EXPECT_EQ(OK, rv); |
| 7126 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7127 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7128 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7129 | |
| 7130 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7131 | EXPECT_EQ(200, response->headers->response_code()); |
| 7132 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7133 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7134 | |
| 7135 | LoadTimingInfo load_timing_info; |
| 7136 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7137 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7138 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7139 | } |
| 7140 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7141 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7142 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7143 | session_deps_.proxy_service = |
| 7144 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7145 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7146 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7147 | |
| 7148 | HttpRequestInfo request; |
| 7149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7150 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7151 | request.load_flags = 0; |
| 7152 | |
| 7153 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7154 | MockWrite( |
| 7155 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7156 | "Host: www.example.org\r\n" |
| 7157 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7158 | }; |
| 7159 | |
| 7160 | MockRead data_reads[] = { |
| 7161 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7162 | MockRead("Location: http://login.example.com/\r\n"), |
| 7163 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7164 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7165 | }; |
| 7166 | |
| 7167 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7168 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7169 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7170 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7171 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7174 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7175 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7176 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7177 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7178 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7180 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7182 | |
| 7183 | rv = callback.WaitForResult(); |
| 7184 | EXPECT_EQ(OK, rv); |
| 7185 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7186 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7187 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7188 | |
| 7189 | EXPECT_EQ(302, response->headers->response_code()); |
| 7190 | std::string url; |
| 7191 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7192 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7193 | |
| 7194 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7195 | // timing for the proxy connection instead of the connection to the host, |
| 7196 | // and no send / receive times. |
| 7197 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7198 | LoadTimingInfo load_timing_info; |
| 7199 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7200 | |
| 7201 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7202 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7203 | |
| 7204 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7205 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7206 | load_timing_info.proxy_resolve_end); |
| 7207 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7208 | load_timing_info.connect_timing.connect_start); |
| 7209 | ExpectConnectTimingHasTimes( |
| 7210 | load_timing_info.connect_timing, |
| 7211 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7212 | |
| 7213 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7214 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7215 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7216 | } |
| 7217 | |
| 7218 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7219 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7220 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7221 | |
| 7222 | HttpRequestInfo request; |
| 7223 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7224 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7225 | request.load_flags = 0; |
| 7226 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7227 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7228 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7229 | scoped_ptr<SpdyFrame> goaway( |
| 7230 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7231 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7232 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7233 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7234 | }; |
| 7235 | |
| 7236 | static const char* const kExtraHeaders[] = { |
| 7237 | "location", |
| 7238 | "http://login.example.com/", |
| 7239 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7240 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7241 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7242 | arraysize(kExtraHeaders)/2, 1)); |
| 7243 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7244 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7245 | }; |
| 7246 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7247 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7248 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7249 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7250 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7251 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7252 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7255 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7256 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7257 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7258 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7259 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7261 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7262 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7263 | |
| 7264 | rv = callback.WaitForResult(); |
| 7265 | EXPECT_EQ(OK, rv); |
| 7266 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7267 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7268 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7269 | |
| 7270 | EXPECT_EQ(302, response->headers->response_code()); |
| 7271 | std::string url; |
| 7272 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7273 | EXPECT_EQ("http://login.example.com/", url); |
| 7274 | } |
| 7275 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7276 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7277 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7278 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7279 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7280 | |
| 7281 | HttpRequestInfo request; |
| 7282 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7283 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7284 | request.load_flags = 0; |
| 7285 | |
| 7286 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7287 | MockWrite( |
| 7288 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7289 | "Host: www.example.org\r\n" |
| 7290 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7291 | }; |
| 7292 | |
| 7293 | MockRead data_reads[] = { |
| 7294 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7295 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7296 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7297 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7298 | }; |
| 7299 | |
| 7300 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7301 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7302 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7303 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7304 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7307 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7308 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7309 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7310 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7313 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7314 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7315 | |
| 7316 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7317 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7318 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7319 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7320 | } |
| 7321 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7322 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7323 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7324 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7325 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7326 | |
| 7327 | HttpRequestInfo request; |
| 7328 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7329 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7330 | request.load_flags = 0; |
| 7331 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7332 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7333 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7334 | scoped_ptr<SpdyFrame> rst( |
| 7335 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7336 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7337 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7338 | }; |
| 7339 | |
| 7340 | static const char* const kExtraHeaders[] = { |
| 7341 | "location", |
| 7342 | "http://login.example.com/", |
| 7343 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7344 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7345 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7346 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7347 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7348 | spdy_util_.ConstructSpdyBodyFrame( |
| 7349 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7350 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7351 | CreateMockRead(*resp.get(), 1), |
| 7352 | CreateMockRead(*body.get(), 2), |
| 7353 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7354 | }; |
| 7355 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7356 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7357 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7358 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7359 | proxy_ssl.SetNextProto(GetParam()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7360 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7364 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7365 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7366 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7367 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7368 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7370 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7372 | |
| 7373 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7374 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7375 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7376 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7377 | } |
| 7378 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7379 | // Test the request-challenge-retry sequence for basic auth, through |
| 7380 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7381 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7382 | HttpRequestInfo request; |
| 7383 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7384 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7385 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7386 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7387 | |
| 7388 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7389 | session_deps_.proxy_service = |
| 7390 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7391 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7392 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7393 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7394 | |
| 7395 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7396 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7397 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7398 | scoped_ptr<SpdyFrame> rst( |
| 7399 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7400 | |
| 7401 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7402 | // be issuing -- the final header line contains the credentials. |
| 7403 | const char* const kAuthCredentials[] = { |
| 7404 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7405 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7406 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7407 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7408 | HostPortPair("www.example.org", 443))); |
| 7409 | // fetch https://www.example.org/ via HTTP |
| 7410 | const char get[] = |
| 7411 | "GET / HTTP/1.1\r\n" |
| 7412 | "Host: www.example.org\r\n" |
| 7413 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7414 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7415 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7416 | |
| 7417 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7418 | CreateMockWrite(*req, 0, ASYNC), |
| 7419 | CreateMockWrite(*rst, 2, ASYNC), |
| 7420 | CreateMockWrite(*connect2, 3), |
| 7421 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7422 | }; |
| 7423 | |
| 7424 | // The proxy responds to the connect with a 407, using a persistent |
| 7425 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7426 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7427 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7428 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7429 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7430 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7431 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7432 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7433 | scoped_ptr<SpdyFrame> conn_resp( |
| 7434 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7435 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7436 | "Content-Length: 5\r\n\r\n"; |
| 7437 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7438 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7439 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7440 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7441 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7442 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7443 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7444 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7445 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7446 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7447 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7448 | }; |
| 7449 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7450 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7451 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7452 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7453 | // Negotiate SPDY to the proxy |
| 7454 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7455 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7457 | // Vanilla SSL to the server |
| 7458 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7460 | |
| 7461 | TestCompletionCallback callback1; |
| 7462 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7463 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7465 | |
| 7466 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7467 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7468 | |
| 7469 | rv = callback1.WaitForResult(); |
| 7470 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7471 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7472 | log.GetEntries(&entries); |
| 7473 | size_t pos = ExpectLogContainsSomewhere( |
| 7474 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7475 | NetLog::PHASE_NONE); |
| 7476 | ExpectLogContainsSomewhere( |
| 7477 | entries, pos, |
| 7478 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7479 | NetLog::PHASE_NONE); |
| 7480 | |
| 7481 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7482 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7483 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7484 | EXPECT_EQ(407, response->headers->response_code()); |
| 7485 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7486 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7487 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7488 | |
| 7489 | TestCompletionCallback callback2; |
| 7490 | |
| 7491 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7492 | callback2.callback()); |
| 7493 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7494 | |
| 7495 | rv = callback2.WaitForResult(); |
| 7496 | EXPECT_EQ(OK, rv); |
| 7497 | |
| 7498 | response = trans->GetResponseInfo(); |
| 7499 | ASSERT_TRUE(response != NULL); |
| 7500 | |
| 7501 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7502 | EXPECT_EQ(200, response->headers->response_code()); |
| 7503 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7504 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7505 | |
| 7506 | // The password prompt info should not be set. |
| 7507 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7508 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7509 | LoadTimingInfo load_timing_info; |
| 7510 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7511 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7512 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7513 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7514 | trans.reset(); |
| 7515 | session->CloseAllConnections(); |
| 7516 | } |
| 7517 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7518 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7519 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7520 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7521 | HttpRequestInfo request; |
| 7522 | HttpRequestInfo push_request; |
| 7523 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7524 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7525 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7526 | push_request.method = "GET"; |
| 7527 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7528 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7529 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7530 | session_deps_.proxy_service = |
| 7531 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7532 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7533 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7534 | |
| 7535 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7536 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7537 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7538 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7539 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7540 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7541 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7542 | |
| 7543 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7544 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7545 | }; |
| 7546 | |
| 7547 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7548 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7549 | |
| 7550 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7551 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7552 | |
| 7553 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7554 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7555 | 0, |
| 7556 | 2, |
| 7557 | 1, |
| 7558 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7559 | const char kPushedData[] = "pushed"; |
| 7560 | scoped_ptr<SpdyFrame> stream2_body( |
| 7561 | spdy_util_.ConstructSpdyBodyFrame( |
| 7562 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7563 | |
| 7564 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7565 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7566 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7567 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7568 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7569 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7570 | }; |
| 7571 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7572 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7573 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7574 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7575 | // Negotiate SPDY to the proxy |
| 7576 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7577 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7579 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7580 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7581 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7582 | TestCompletionCallback callback; |
| 7583 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7584 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7585 | |
| 7586 | rv = callback.WaitForResult(); |
| 7587 | EXPECT_EQ(OK, rv); |
| 7588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7589 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7590 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7591 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7592 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7593 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7594 | |
| 7595 | rv = callback.WaitForResult(); |
| 7596 | EXPECT_EQ(OK, rv); |
| 7597 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7598 | |
| 7599 | ASSERT_TRUE(response != NULL); |
| 7600 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7601 | |
| 7602 | EXPECT_EQ(200, response->headers->response_code()); |
| 7603 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7604 | |
| 7605 | std::string response_data; |
| 7606 | rv = ReadTransaction(trans.get(), &response_data); |
| 7607 | EXPECT_EQ(OK, rv); |
| 7608 | EXPECT_EQ("hello!", response_data); |
| 7609 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7610 | LoadTimingInfo load_timing_info; |
| 7611 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7612 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7613 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7614 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7615 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7616 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7617 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7618 | |
| 7619 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7620 | EXPECT_EQ(OK, rv); |
| 7621 | EXPECT_EQ("pushed", response_data); |
| 7622 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7623 | LoadTimingInfo push_load_timing_info; |
| 7624 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7625 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7626 | // The transactions should share a socket ID, despite being for different |
| 7627 | // origins. |
| 7628 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7629 | push_load_timing_info.socket_log_id); |
| 7630 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7631 | trans.reset(); |
| 7632 | push_trans.reset(); |
| 7633 | session->CloseAllConnections(); |
| 7634 | } |
| 7635 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7636 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7637 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7638 | HttpRequestInfo request; |
| 7639 | |
| 7640 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7641 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7642 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7643 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7644 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7645 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7646 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7647 | |
| 7648 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7649 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7650 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7651 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7652 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7653 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7654 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7655 | |
| 7656 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7657 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7658 | |
| 7659 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7660 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7661 | }; |
| 7662 | |
| 7663 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7664 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7665 | |
| 7666 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7667 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7668 | |
| 7669 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7670 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7671 | 0, |
| 7672 | 2, |
| 7673 | 1, |
| 7674 | "https://www.another-origin.com/foo.dat")); |
| 7675 | |
| 7676 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7677 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7678 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7679 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7680 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7681 | }; |
| 7682 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7683 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7684 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7685 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7686 | // Negotiate SPDY to the proxy |
| 7687 | SSLSocketDataProvider proxy(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7688 | proxy.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7690 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7691 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7692 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7693 | TestCompletionCallback callback; |
| 7694 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7696 | |
| 7697 | rv = callback.WaitForResult(); |
| 7698 | EXPECT_EQ(OK, rv); |
| 7699 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7700 | |
| 7701 | ASSERT_TRUE(response != NULL); |
| 7702 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7703 | |
| 7704 | EXPECT_EQ(200, response->headers->response_code()); |
| 7705 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7706 | |
| 7707 | std::string response_data; |
| 7708 | rv = ReadTransaction(trans.get(), &response_data); |
| 7709 | EXPECT_EQ(OK, rv); |
| 7710 | EXPECT_EQ("hello!", response_data); |
| 7711 | |
| 7712 | trans.reset(); |
| 7713 | session->CloseAllConnections(); |
| 7714 | } |
| 7715 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7716 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7717 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7718 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7719 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7720 | |
| 7721 | HttpRequestInfo request; |
| 7722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7723 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7724 | request.load_flags = 0; |
| 7725 | |
| 7726 | // Attempt to fetch the URL from a server with a bad cert |
| 7727 | MockWrite bad_cert_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7728 | MockWrite( |
| 7729 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7730 | "Host: www.example.org\r\n" |
| 7731 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7732 | }; |
| 7733 | |
| 7734 | MockRead bad_cert_reads[] = { |
| 7735 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7736 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7737 | }; |
| 7738 | |
| 7739 | // Attempt to fetch the URL with a good cert |
| 7740 | MockWrite good_data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7741 | MockWrite( |
| 7742 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7743 | "Host: www.example.org\r\n" |
| 7744 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7745 | MockWrite( |
| 7746 | "GET / HTTP/1.1\r\n" |
| 7747 | "Host: www.example.org\r\n" |
| 7748 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7749 | }; |
| 7750 | |
| 7751 | MockRead good_cert_reads[] = { |
| 7752 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7753 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7754 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7755 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7756 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7757 | }; |
| 7758 | |
| 7759 | StaticSocketDataProvider ssl_bad_certificate( |
| 7760 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7761 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7762 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7763 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7764 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7765 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7766 | |
| 7767 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7768 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7769 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7770 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7771 | |
| 7772 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7777 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7778 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7779 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7780 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7783 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7784 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7785 | |
| 7786 | rv = callback.WaitForResult(); |
| 7787 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7788 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7789 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7790 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7791 | |
| 7792 | rv = callback.WaitForResult(); |
| 7793 | EXPECT_EQ(OK, rv); |
| 7794 | |
| 7795 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7796 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7797 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7798 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7799 | } |
| 7800 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7801 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7802 | HttpRequestInfo request; |
| 7803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7804 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7805 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7806 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7807 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7808 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7809 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7810 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7811 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7812 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7813 | MockWrite( |
| 7814 | "GET / HTTP/1.1\r\n" |
| 7815 | "Host: www.example.org\r\n" |
| 7816 | "Connection: keep-alive\r\n" |
| 7817 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7818 | }; |
| 7819 | |
| 7820 | // Lastly, the server responds with the actual content. |
| 7821 | MockRead data_reads[] = { |
| 7822 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7823 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7824 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7826 | }; |
| 7827 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7828 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7829 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7830 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7831 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7832 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7834 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7835 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7836 | |
| 7837 | rv = callback.WaitForResult(); |
| 7838 | EXPECT_EQ(OK, rv); |
| 7839 | } |
| 7840 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7841 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7842 | HttpRequestInfo request; |
| 7843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7844 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7845 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7846 | "Chromium Ultra Awesome X Edition"); |
| 7847 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7848 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7849 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7850 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7851 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7852 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7853 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7854 | MockWrite( |
| 7855 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7856 | "Host: www.example.org\r\n" |
| 7857 | "Proxy-Connection: keep-alive\r\n" |
| 7858 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7859 | }; |
| 7860 | MockRead data_reads[] = { |
| 7861 | // Return an error, so the transaction stops here (this test isn't |
| 7862 | // interested in the rest). |
| 7863 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7864 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7865 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7866 | }; |
| 7867 | |
| 7868 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7869 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7870 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7872 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7874 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7875 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7876 | |
| 7877 | rv = callback.WaitForResult(); |
| 7878 | EXPECT_EQ(OK, rv); |
| 7879 | } |
| 7880 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7881 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7882 | HttpRequestInfo request; |
| 7883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7884 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7885 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7886 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7887 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7888 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7889 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7890 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7892 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7893 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7894 | MockWrite( |
| 7895 | "GET / HTTP/1.1\r\n" |
| 7896 | "Host: www.example.org\r\n" |
| 7897 | "Connection: keep-alive\r\n" |
| 7898 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7899 | }; |
| 7900 | |
| 7901 | // Lastly, the server responds with the actual content. |
| 7902 | MockRead data_reads[] = { |
| 7903 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7904 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7905 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7906 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7907 | }; |
| 7908 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7909 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7910 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7911 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7913 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7915 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7916 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7917 | |
| 7918 | rv = callback.WaitForResult(); |
| 7919 | EXPECT_EQ(OK, rv); |
| 7920 | } |
| 7921 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7922 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7923 | HttpRequestInfo request; |
| 7924 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7925 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7926 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7927 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7928 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7929 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7930 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7931 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7932 | MockWrite( |
| 7933 | "POST / HTTP/1.1\r\n" |
| 7934 | "Host: www.example.org\r\n" |
| 7935 | "Connection: keep-alive\r\n" |
| 7936 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7937 | }; |
| 7938 | |
| 7939 | // Lastly, the server responds with the actual content. |
| 7940 | MockRead data_reads[] = { |
| 7941 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7942 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7943 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7944 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7945 | }; |
| 7946 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7947 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7948 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7949 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7951 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7953 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7954 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7955 | |
| 7956 | rv = callback.WaitForResult(); |
| 7957 | EXPECT_EQ(OK, rv); |
| 7958 | } |
| 7959 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7960 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7961 | HttpRequestInfo request; |
| 7962 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7963 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7964 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 7965 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7966 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7967 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7968 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7969 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7970 | MockWrite( |
| 7971 | "PUT / HTTP/1.1\r\n" |
| 7972 | "Host: www.example.org\r\n" |
| 7973 | "Connection: keep-alive\r\n" |
| 7974 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7975 | }; |
| 7976 | |
| 7977 | // Lastly, the server responds with the actual content. |
| 7978 | MockRead data_reads[] = { |
| 7979 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7980 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7981 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7982 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7983 | }; |
| 7984 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7986 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7989 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7991 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7992 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7993 | |
| 7994 | rv = callback.WaitForResult(); |
| 7995 | EXPECT_EQ(OK, rv); |
| 7996 | } |
| 7997 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7998 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7999 | HttpRequestInfo request; |
| 8000 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8001 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8002 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8003 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8004 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8005 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8006 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8007 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8008 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8009 | "Host: www.example.org\r\n" |
| 8010 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8011 | }; |
| 8012 | |
| 8013 | // Lastly, the server responds with the actual content. |
| 8014 | MockRead data_reads[] = { |
| 8015 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8016 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8017 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8018 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8019 | }; |
| 8020 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8021 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8022 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8025 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8026 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8027 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8028 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8029 | |
| 8030 | rv = callback.WaitForResult(); |
| 8031 | EXPECT_EQ(OK, rv); |
| 8032 | } |
| 8033 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8034 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8035 | HttpRequestInfo request; |
| 8036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8037 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8038 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8039 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8040 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8041 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8043 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8044 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8045 | MockWrite( |
| 8046 | "GET / HTTP/1.1\r\n" |
| 8047 | "Host: www.example.org\r\n" |
| 8048 | "Connection: keep-alive\r\n" |
| 8049 | "Pragma: no-cache\r\n" |
| 8050 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8051 | }; |
| 8052 | |
| 8053 | // Lastly, the server responds with the actual content. |
| 8054 | MockRead data_reads[] = { |
| 8055 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8056 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8057 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8058 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8059 | }; |
| 8060 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8061 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8062 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8065 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8067 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8068 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8069 | |
| 8070 | rv = callback.WaitForResult(); |
| 8071 | EXPECT_EQ(OK, rv); |
| 8072 | } |
| 8073 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8074 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8075 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8076 | HttpRequestInfo request; |
| 8077 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8078 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8079 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8080 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8081 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8082 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8083 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8084 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8085 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8086 | MockWrite( |
| 8087 | "GET / HTTP/1.1\r\n" |
| 8088 | "Host: www.example.org\r\n" |
| 8089 | "Connection: keep-alive\r\n" |
| 8090 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8091 | }; |
| 8092 | |
| 8093 | // Lastly, the server responds with the actual content. |
| 8094 | MockRead data_reads[] = { |
| 8095 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8096 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8097 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8098 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8099 | }; |
| 8100 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8101 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8102 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8103 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8105 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8107 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8108 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8109 | |
| 8110 | rv = callback.WaitForResult(); |
| 8111 | EXPECT_EQ(OK, rv); |
| 8112 | } |
| 8113 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8114 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8115 | HttpRequestInfo request; |
| 8116 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8117 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8118 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8119 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8120 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8121 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8122 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8123 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8124 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8125 | MockWrite( |
| 8126 | "GET / HTTP/1.1\r\n" |
| 8127 | "Host: www.example.org\r\n" |
| 8128 | "Connection: keep-alive\r\n" |
| 8129 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8130 | }; |
| 8131 | |
| 8132 | // Lastly, the server responds with the actual content. |
| 8133 | MockRead data_reads[] = { |
| 8134 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8135 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8136 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8137 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8138 | }; |
| 8139 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8140 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8141 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8142 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8144 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8145 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8146 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8147 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8148 | |
| 8149 | rv = callback.WaitForResult(); |
| 8150 | EXPECT_EQ(OK, rv); |
| 8151 | } |
| 8152 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8153 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8154 | HttpRequestInfo request; |
| 8155 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8156 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8157 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8158 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8159 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8160 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8161 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8162 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8163 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8164 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8165 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8166 | MockWrite( |
| 8167 | "GET / HTTP/1.1\r\n" |
| 8168 | "Host: www.example.org\r\n" |
| 8169 | "Connection: keep-alive\r\n" |
| 8170 | "referer: www.foo.com\r\n" |
| 8171 | "hEllo: Kitty\r\n" |
| 8172 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8173 | }; |
| 8174 | |
| 8175 | // Lastly, the server responds with the actual content. |
| 8176 | MockRead data_reads[] = { |
| 8177 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8178 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8179 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8180 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8181 | }; |
| 8182 | |
| 8183 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8184 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8185 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8187 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8189 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8191 | |
| 8192 | rv = callback.WaitForResult(); |
| 8193 | EXPECT_EQ(OK, rv); |
| 8194 | } |
| 8195 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8196 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8197 | HttpRequestInfo request; |
| 8198 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8199 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8200 | request.load_flags = 0; |
| 8201 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8202 | session_deps_.proxy_service = |
| 8203 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8204 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8205 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8206 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8207 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8208 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8209 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8210 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8211 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8212 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8213 | |
| 8214 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8215 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8216 | MockWrite( |
| 8217 | "GET / HTTP/1.1\r\n" |
| 8218 | "Host: www.example.org\r\n" |
| 8219 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8220 | |
| 8221 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8222 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8223 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8224 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8225 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8226 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8227 | }; |
| 8228 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8229 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8230 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8233 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8235 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8236 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8237 | |
| 8238 | rv = callback.WaitForResult(); |
| 8239 | EXPECT_EQ(OK, rv); |
| 8240 | |
| 8241 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8242 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8243 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8244 | LoadTimingInfo load_timing_info; |
| 8245 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8246 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8247 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8248 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8249 | std::string response_text; |
| 8250 | rv = ReadTransaction(trans.get(), &response_text); |
| 8251 | EXPECT_EQ(OK, rv); |
| 8252 | EXPECT_EQ("Payload", response_text); |
| 8253 | } |
| 8254 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8255 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8256 | HttpRequestInfo request; |
| 8257 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8258 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8259 | request.load_flags = 0; |
| 8260 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8261 | session_deps_.proxy_service = |
| 8262 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8263 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8264 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8265 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8266 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8267 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8268 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8269 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8270 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8271 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8272 | |
| 8273 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8274 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8275 | arraysize(write_buffer)), |
| 8276 | MockWrite( |
| 8277 | "GET / HTTP/1.1\r\n" |
| 8278 | "Host: www.example.org\r\n" |
| 8279 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8280 | |
| 8281 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8282 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8283 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8284 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8285 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8286 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8287 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8288 | }; |
| 8289 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8290 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8291 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8293 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8294 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8297 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8299 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8300 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8301 | |
| 8302 | rv = callback.WaitForResult(); |
| 8303 | EXPECT_EQ(OK, rv); |
| 8304 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8305 | LoadTimingInfo load_timing_info; |
| 8306 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8307 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8308 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8309 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8310 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8311 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8312 | |
| 8313 | std::string response_text; |
| 8314 | rv = ReadTransaction(trans.get(), &response_text); |
| 8315 | EXPECT_EQ(OK, rv); |
| 8316 | EXPECT_EQ("Payload", response_text); |
| 8317 | } |
| 8318 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8319 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8320 | HttpRequestInfo request; |
| 8321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8322 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8323 | request.load_flags = 0; |
| 8324 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8325 | session_deps_.proxy_service = |
| 8326 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8327 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8328 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8329 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8330 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8331 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8332 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8333 | |
| 8334 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8335 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8336 | |
| 8337 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8338 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8339 | MockWrite( |
| 8340 | "GET / HTTP/1.1\r\n" |
| 8341 | "Host: www.example.org\r\n" |
| 8342 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8343 | |
| 8344 | MockRead data_reads[] = { |
| 8345 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8346 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8347 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8348 | MockRead("Payload"), |
| 8349 | MockRead(SYNCHRONOUS, OK) |
| 8350 | }; |
| 8351 | |
| 8352 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8353 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8354 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8355 | |
| 8356 | TestCompletionCallback callback; |
| 8357 | |
| 8358 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8359 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8360 | |
| 8361 | rv = callback.WaitForResult(); |
| 8362 | EXPECT_EQ(OK, rv); |
| 8363 | |
| 8364 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8365 | ASSERT_TRUE(response != NULL); |
| 8366 | |
| 8367 | LoadTimingInfo load_timing_info; |
| 8368 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8369 | TestLoadTimingNotReused(load_timing_info, |
| 8370 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8371 | |
| 8372 | std::string response_text; |
| 8373 | rv = ReadTransaction(trans.get(), &response_text); |
| 8374 | EXPECT_EQ(OK, rv); |
| 8375 | EXPECT_EQ("Payload", response_text); |
| 8376 | } |
| 8377 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8378 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8379 | HttpRequestInfo request; |
| 8380 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8381 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8382 | request.load_flags = 0; |
| 8383 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8384 | session_deps_.proxy_service = |
| 8385 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8386 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8387 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8388 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8389 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8390 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8391 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8392 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8393 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8394 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8395 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8396 | 0x05, // Version |
| 8397 | 0x01, // Command (CONNECT) |
| 8398 | 0x00, // Reserved. |
| 8399 | 0x03, // Address type (DOMAINNAME). |
| 8400 | 0x0F, // Length of domain (15) |
| 8401 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8402 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8403 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8404 | const char kSOCKS5OkResponse[] = |
| 8405 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8406 | |
| 8407 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8408 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8409 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8410 | MockWrite( |
| 8411 | "GET / HTTP/1.1\r\n" |
| 8412 | "Host: www.example.org\r\n" |
| 8413 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8414 | |
| 8415 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8416 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8417 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8418 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8420 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8421 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8422 | }; |
| 8423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8425 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8428 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8430 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8431 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8432 | |
| 8433 | rv = callback.WaitForResult(); |
| 8434 | EXPECT_EQ(OK, rv); |
| 8435 | |
| 8436 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8437 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8438 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8439 | LoadTimingInfo load_timing_info; |
| 8440 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8441 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8442 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8443 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8444 | std::string response_text; |
| 8445 | rv = ReadTransaction(trans.get(), &response_text); |
| 8446 | EXPECT_EQ(OK, rv); |
| 8447 | EXPECT_EQ("Payload", response_text); |
| 8448 | } |
| 8449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8450 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8451 | HttpRequestInfo request; |
| 8452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8453 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8454 | request.load_flags = 0; |
| 8455 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8456 | session_deps_.proxy_service = |
| 8457 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8458 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8459 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8460 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8461 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8462 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8463 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8464 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8465 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8466 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8467 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8468 | 0x05, // Version |
| 8469 | 0x01, // Command (CONNECT) |
| 8470 | 0x00, // Reserved. |
| 8471 | 0x03, // Address type (DOMAINNAME). |
| 8472 | 0x0F, // Length of domain (15) |
| 8473 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8474 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8475 | }; |
| 8476 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8477 | const char kSOCKS5OkResponse[] = |
| 8478 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8479 | |
| 8480 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8481 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8482 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8483 | arraysize(kSOCKS5OkRequest)), |
| 8484 | MockWrite( |
| 8485 | "GET / HTTP/1.1\r\n" |
| 8486 | "Host: www.example.org\r\n" |
| 8487 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8488 | |
| 8489 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8490 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8491 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8492 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8493 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8494 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8495 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8496 | }; |
| 8497 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8498 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8499 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8501 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8502 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8505 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8507 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8508 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8509 | |
| 8510 | rv = callback.WaitForResult(); |
| 8511 | EXPECT_EQ(OK, rv); |
| 8512 | |
| 8513 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8514 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8515 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8516 | LoadTimingInfo load_timing_info; |
| 8517 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8518 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8519 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8520 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8521 | std::string response_text; |
| 8522 | rv = ReadTransaction(trans.get(), &response_text); |
| 8523 | EXPECT_EQ(OK, rv); |
| 8524 | EXPECT_EQ("Payload", response_text); |
| 8525 | } |
| 8526 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8527 | namespace { |
| 8528 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8529 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8530 | |
| 8531 | struct GroupNameTest { |
| 8532 | std::string proxy_server; |
| 8533 | std::string url; |
| 8534 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8535 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8536 | }; |
| 8537 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8538 | scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8539 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8540 | SpdySessionDependencies* session_deps_) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8541 | scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8542 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8543 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8544 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8545 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8546 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8547 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8548 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8549 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8550 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8551 | |
| 8552 | return session; |
| 8553 | } |
| 8554 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8555 | int GroupNameTransactionHelper( |
| 8556 | const std::string& url, |
| 8557 | const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8558 | HttpRequestInfo request; |
| 8559 | request.method = "GET"; |
| 8560 | request.url = GURL(url); |
| 8561 | request.load_flags = 0; |
| 8562 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8563 | scoped_ptr<HttpTransaction> trans( |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8564 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8566 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8567 | |
| 8568 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8569 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8570 | } |
| 8571 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8572 | } // namespace |
| 8573 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8574 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8575 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8576 | { |
| 8577 | "", // unused |
| 8578 | "http://www.example.org/direct", |
| 8579 | "www.example.org:80", |
| 8580 | false, |
| 8581 | }, |
| 8582 | { |
| 8583 | "", // unused |
| 8584 | "http://[2001:1418:13:1::25]/direct", |
| 8585 | "[2001:1418:13:1::25]:80", |
| 8586 | false, |
| 8587 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8588 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8589 | // SSL Tests |
| 8590 | { |
| 8591 | "", // unused |
| 8592 | "https://www.example.org/direct_ssl", |
| 8593 | "ssl/www.example.org:443", |
| 8594 | true, |
| 8595 | }, |
| 8596 | { |
| 8597 | "", // unused |
| 8598 | "https://[2001:1418:13:1::25]/direct", |
| 8599 | "ssl/[2001:1418:13:1::25]:443", |
| 8600 | true, |
| 8601 | }, |
| 8602 | { |
| 8603 | "", // unused |
| 8604 | "http://host.with.alternate/direct", |
| 8605 | "ssl/host.with.alternate:443", |
| 8606 | true, |
| 8607 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8608 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8609 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8610 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8611 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8612 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8613 | session_deps_.proxy_service = |
| 8614 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8615 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8616 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8617 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8618 | HttpNetworkSessionPeer peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8619 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8620 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8621 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8622 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8623 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8624 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8625 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8626 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8627 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8628 | |
| 8629 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8630 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8631 | if (tests[i].ssl) |
| 8632 | EXPECT_EQ(tests[i].expected_group_name, |
| 8633 | ssl_conn_pool->last_group_name_received()); |
| 8634 | else |
| 8635 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8636 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8637 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8638 | } |
| 8639 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8640 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8641 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8642 | { |
| 8643 | "http_proxy", |
| 8644 | "http://www.example.org/http_proxy_normal", |
| 8645 | "www.example.org:80", |
| 8646 | false, |
| 8647 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8648 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8649 | // SSL Tests |
| 8650 | { |
| 8651 | "http_proxy", |
| 8652 | "https://www.example.org/http_connect_ssl", |
| 8653 | "ssl/www.example.org:443", |
| 8654 | true, |
| 8655 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8656 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8657 | { |
| 8658 | "http_proxy", |
| 8659 | "http://host.with.alternate/direct", |
| 8660 | "ssl/host.with.alternate:443", |
| 8661 | true, |
| 8662 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8663 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8664 | { |
| 8665 | "http_proxy", |
| 8666 | "ftp://ftp.google.com/http_proxy_normal", |
| 8667 | "ftp/ftp.google.com:21", |
| 8668 | false, |
| 8669 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8670 | }; |
| 8671 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8672 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8673 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8674 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8675 | session_deps_.proxy_service = |
| 8676 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8677 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8678 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8679 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8680 | HttpNetworkSessionPeer peer(session); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8681 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8682 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8683 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8684 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8685 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8686 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8687 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8688 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8689 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8690 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8691 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8692 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8693 | |
| 8694 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8695 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8696 | if (tests[i].ssl) |
| 8697 | EXPECT_EQ(tests[i].expected_group_name, |
| 8698 | ssl_conn_pool->last_group_name_received()); |
| 8699 | else |
| 8700 | EXPECT_EQ(tests[i].expected_group_name, |
| 8701 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8702 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8703 | } |
| 8704 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8705 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8706 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8707 | { |
| 8708 | "socks4://socks_proxy:1080", |
| 8709 | "http://www.example.org/socks4_direct", |
| 8710 | "socks4/www.example.org:80", |
| 8711 | false, |
| 8712 | }, |
| 8713 | { |
| 8714 | "socks5://socks_proxy:1080", |
| 8715 | "http://www.example.org/socks5_direct", |
| 8716 | "socks5/www.example.org:80", |
| 8717 | false, |
| 8718 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8719 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8720 | // SSL Tests |
| 8721 | { |
| 8722 | "socks4://socks_proxy:1080", |
| 8723 | "https://www.example.org/socks4_ssl", |
| 8724 | "socks4/ssl/www.example.org:443", |
| 8725 | true, |
| 8726 | }, |
| 8727 | { |
| 8728 | "socks5://socks_proxy:1080", |
| 8729 | "https://www.example.org/socks5_ssl", |
| 8730 | "socks5/ssl/www.example.org:443", |
| 8731 | true, |
| 8732 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8733 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8734 | { |
| 8735 | "socks4://socks_proxy:1080", |
| 8736 | "http://host.with.alternate/direct", |
| 8737 | "socks4/ssl/host.with.alternate:443", |
| 8738 | true, |
| 8739 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8740 | }; |
| 8741 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8742 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8743 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8744 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8745 | session_deps_.proxy_service = |
| 8746 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8747 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8748 | SetupSessionForGroupNameTests(GetParam(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8749 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8750 | HttpNetworkSessionPeer peer(session); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8751 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8752 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8753 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8754 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8755 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8756 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8757 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8758 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8759 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8760 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8761 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8762 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8763 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8764 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8766 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8767 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8768 | GroupNameTransactionHelper(tests[i].url, session)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8769 | if (tests[i].ssl) |
| 8770 | EXPECT_EQ(tests[i].expected_group_name, |
| 8771 | ssl_conn_pool->last_group_name_received()); |
| 8772 | else |
| 8773 | EXPECT_EQ(tests[i].expected_group_name, |
| 8774 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8775 | } |
| 8776 | } |
| 8777 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8778 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8779 | HttpRequestInfo request; |
| 8780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8781 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8782 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8783 | session_deps_.proxy_service = |
| 8784 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8785 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8786 | // This simulates failure resolving all hostnames; that means we will fail |
| 8787 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8788 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8789 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8790 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8791 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8792 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8794 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8796 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8797 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8798 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8799 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8800 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8801 | } |
| 8802 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8803 | // Base test to make sure that when the load flags for a request specify to |
| 8804 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8805 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8806 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8807 | // Issue a request, asking to bypass the cache(s). |
| 8808 | HttpRequestInfo request; |
| 8809 | request.method = "GET"; |
| 8810 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8811 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8812 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8813 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8814 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8815 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8816 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8817 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8819 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8820 | // 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] | 8821 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8822 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8823 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8824 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8825 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8826 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8827 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8828 | EXPECT_EQ(OK, rv); |
| 8829 | |
| 8830 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8831 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8832 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8833 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8834 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8835 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8836 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8837 | // 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] | 8838 | // we can tell if the next lookup hit the cache, or the "network". |
| 8839 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8840 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8841 | |
| 8842 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8843 | // 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] | 8844 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8845 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8847 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8848 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8849 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8850 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8851 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8852 | |
| 8853 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8854 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8855 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8856 | } |
| 8857 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8858 | // There are multiple load flags that should trigger the host cache bypass. |
| 8859 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8860 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8861 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8862 | } |
| 8863 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8864 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8865 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8866 | } |
| 8867 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8868 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8869 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8870 | } |
| 8871 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8872 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8873 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8874 | HttpRequestInfo request; |
| 8875 | request.method = "GET"; |
| 8876 | request.url = GURL("http://www.foo.com/"); |
| 8877 | request.load_flags = 0; |
| 8878 | |
| 8879 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8880 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8881 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8882 | StaticSocketDataProvider data(NULL, 0, |
| 8883 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8885 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8887 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8888 | |
| 8889 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8892 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8893 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8894 | |
| 8895 | rv = callback.WaitForResult(); |
| 8896 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8897 | |
| 8898 | IPEndPoint endpoint; |
| 8899 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8900 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8901 | } |
| 8902 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8903 | // Check that a connection closed after the start of the headers finishes ok. |
| 8904 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8905 | HttpRequestInfo request; |
| 8906 | request.method = "GET"; |
| 8907 | request.url = GURL("http://www.foo.com/"); |
| 8908 | request.load_flags = 0; |
| 8909 | |
| 8910 | MockRead data_reads[] = { |
| 8911 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8912 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8913 | }; |
| 8914 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8915 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8916 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8917 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8918 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8919 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8920 | |
| 8921 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8922 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8924 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8925 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8926 | |
| 8927 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8928 | EXPECT_EQ(OK, rv); |
| 8929 | |
| 8930 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8931 | ASSERT_TRUE(response != NULL); |
| 8932 | |
| 8933 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8934 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8935 | |
| 8936 | std::string response_data; |
| 8937 | rv = ReadTransaction(trans.get(), &response_data); |
| 8938 | EXPECT_EQ(OK, rv); |
| 8939 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8940 | |
| 8941 | IPEndPoint endpoint; |
| 8942 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8943 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8944 | } |
| 8945 | |
| 8946 | // Make sure that a dropped connection while draining the body for auth |
| 8947 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8948 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8949 | HttpRequestInfo request; |
| 8950 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8951 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8952 | request.load_flags = 0; |
| 8953 | |
| 8954 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8955 | MockWrite( |
| 8956 | "GET / HTTP/1.1\r\n" |
| 8957 | "Host: www.example.org\r\n" |
| 8958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8959 | }; |
| 8960 | |
| 8961 | MockRead data_reads1[] = { |
| 8962 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8963 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8964 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8965 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8966 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8967 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8968 | }; |
| 8969 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8970 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8971 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8972 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8973 | |
| 8974 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8975 | // be issuing -- the final header line contains the credentials. |
| 8976 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8977 | MockWrite( |
| 8978 | "GET / HTTP/1.1\r\n" |
| 8979 | "Host: www.example.org\r\n" |
| 8980 | "Connection: keep-alive\r\n" |
| 8981 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8982 | }; |
| 8983 | |
| 8984 | // Lastly, the server responds with the actual content. |
| 8985 | MockRead data_reads2[] = { |
| 8986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8987 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8988 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8989 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8990 | }; |
| 8991 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8992 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8993 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8994 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 8995 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8997 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8998 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8999 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9000 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9002 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9004 | |
| 9005 | rv = callback1.WaitForResult(); |
| 9006 | EXPECT_EQ(OK, rv); |
| 9007 | |
| 9008 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9009 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9010 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9012 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9014 | rv = trans->RestartWithAuth( |
| 9015 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9016 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9017 | |
| 9018 | rv = callback2.WaitForResult(); |
| 9019 | EXPECT_EQ(OK, rv); |
| 9020 | |
| 9021 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9022 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9023 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9024 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9025 | } |
| 9026 | |
| 9027 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9028 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9029 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9030 | |
| 9031 | HttpRequestInfo request; |
| 9032 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9033 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9034 | request.load_flags = 0; |
| 9035 | |
| 9036 | MockRead proxy_reads[] = { |
| 9037 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9038 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9039 | }; |
| 9040 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9041 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9042 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9043 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9044 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9047 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9048 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9049 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9050 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9051 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9052 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9053 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9055 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9056 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9057 | |
| 9058 | rv = callback.WaitForResult(); |
| 9059 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9060 | } |
| 9061 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9062 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9063 | HttpRequestInfo request; |
| 9064 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9065 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9066 | request.load_flags = 0; |
| 9067 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9068 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9069 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9070 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9071 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9072 | MockRead data_reads[] = { |
| 9073 | 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] | 9074 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9075 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9076 | |
| 9077 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9078 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9080 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9082 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9084 | |
| 9085 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9086 | |
| 9087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9088 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9089 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9090 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9091 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9092 | |
| 9093 | std::string response_data; |
| 9094 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9095 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9096 | } |
| 9097 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9098 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9099 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9100 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9101 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9102 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9103 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9104 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 9105 | ScopedVector<UploadElementReader> element_readers; |
| 9106 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 9107 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 9108 | temp_file_path, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 9109 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9110 | |
| 9111 | HttpRequestInfo request; |
| 9112 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9113 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9114 | request.upload_data_stream = &upload_data_stream; |
| 9115 | request.load_flags = 0; |
| 9116 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9117 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9118 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9120 | |
| 9121 | MockRead data_reads[] = { |
| 9122 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9123 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9124 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9125 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9126 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9129 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9131 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9132 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9133 | |
| 9134 | rv = callback.WaitForResult(); |
| 9135 | EXPECT_EQ(OK, rv); |
| 9136 | |
| 9137 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9138 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9139 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9140 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9141 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9142 | |
| 9143 | std::string response_data; |
| 9144 | rv = ReadTransaction(trans.get(), &response_data); |
| 9145 | EXPECT_EQ(OK, rv); |
| 9146 | EXPECT_EQ("hello world", response_data); |
| 9147 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9148 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9149 | } |
| 9150 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9151 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9152 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9153 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9154 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9155 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9156 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9157 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9158 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 9159 | ScopedVector<UploadElementReader> element_readers; |
| 9160 | element_readers.push_back( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 9161 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 9162 | temp_file, 0, kuint64max, base::Time())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 9163 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9164 | |
| 9165 | HttpRequestInfo request; |
| 9166 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9167 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9168 | request.upload_data_stream = &upload_data_stream; |
| 9169 | request.load_flags = 0; |
| 9170 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9171 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9172 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9173 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9174 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9175 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9176 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9179 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9181 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9183 | |
| 9184 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9185 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9186 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9187 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9188 | } |
| 9189 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9190 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9191 | class FakeUploadElementReader : public UploadElementReader { |
| 9192 | public: |
| 9193 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9194 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9195 | |
| 9196 | const CompletionCallback& callback() const { return callback_; } |
| 9197 | |
| 9198 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9199 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9200 | callback_ = callback; |
| 9201 | return ERR_IO_PENDING; |
| 9202 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9203 | uint64 GetContentLength() const override { return 0; } |
| 9204 | uint64 BytesRemaining() const override { return 0; } |
| 9205 | int Read(IOBuffer* buf, |
| 9206 | int buf_length, |
| 9207 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9208 | return ERR_FAILED; |
| 9209 | } |
| 9210 | |
| 9211 | private: |
| 9212 | CompletionCallback callback_; |
| 9213 | }; |
| 9214 | |
| 9215 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
| 9216 | ScopedVector<UploadElementReader> element_readers; |
| 9217 | element_readers.push_back(fake_reader); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 9218 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9219 | |
| 9220 | HttpRequestInfo request; |
| 9221 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9222 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9223 | request.upload_data_stream = &upload_data_stream; |
| 9224 | request.load_flags = 0; |
| 9225 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9226 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9227 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9229 | |
| 9230 | StaticSocketDataProvider data; |
| 9231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9232 | |
| 9233 | TestCompletionCallback callback; |
| 9234 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9235 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9236 | base::MessageLoop::current()->RunUntilIdle(); |
| 9237 | |
| 9238 | // Transaction is pending on request body initialization. |
| 9239 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9240 | |
| 9241 | // Return Init()'s result after the transaction gets destroyed. |
| 9242 | trans.reset(); |
| 9243 | fake_reader->callback().Run(OK); // Should not crash. |
| 9244 | } |
| 9245 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9246 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9247 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9248 | HttpRequestInfo request; |
| 9249 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9250 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9251 | request.load_flags = 0; |
| 9252 | |
| 9253 | // First transaction will request a resource and receive a Basic challenge |
| 9254 | // with realm="first_realm". |
| 9255 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9256 | MockWrite( |
| 9257 | "GET / HTTP/1.1\r\n" |
| 9258 | "Host: www.example.org\r\n" |
| 9259 | "Connection: keep-alive\r\n" |
| 9260 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9261 | }; |
| 9262 | MockRead data_reads1[] = { |
| 9263 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9264 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9265 | "\r\n"), |
| 9266 | }; |
| 9267 | |
| 9268 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9269 | // for first_realm. The server will reject and provide a challenge with |
| 9270 | // second_realm. |
| 9271 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9272 | MockWrite( |
| 9273 | "GET / HTTP/1.1\r\n" |
| 9274 | "Host: www.example.org\r\n" |
| 9275 | "Connection: keep-alive\r\n" |
| 9276 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9277 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9278 | }; |
| 9279 | MockRead data_reads2[] = { |
| 9280 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9281 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9282 | "\r\n"), |
| 9283 | }; |
| 9284 | |
| 9285 | // This again fails, and goes back to first_realm. Make sure that the |
| 9286 | // entry is removed from cache. |
| 9287 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9288 | MockWrite( |
| 9289 | "GET / HTTP/1.1\r\n" |
| 9290 | "Host: www.example.org\r\n" |
| 9291 | "Connection: keep-alive\r\n" |
| 9292 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9293 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9294 | }; |
| 9295 | MockRead data_reads3[] = { |
| 9296 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9297 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9298 | "\r\n"), |
| 9299 | }; |
| 9300 | |
| 9301 | // Try one last time (with the correct password) and get the resource. |
| 9302 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9303 | MockWrite( |
| 9304 | "GET / HTTP/1.1\r\n" |
| 9305 | "Host: www.example.org\r\n" |
| 9306 | "Connection: keep-alive\r\n" |
| 9307 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9308 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9309 | }; |
| 9310 | MockRead data_reads4[] = { |
| 9311 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9312 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9313 | "Content-Length: 5\r\n" |
| 9314 | "\r\n" |
| 9315 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9316 | }; |
| 9317 | |
| 9318 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9319 | data_writes1, arraysize(data_writes1)); |
| 9320 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9321 | data_writes2, arraysize(data_writes2)); |
| 9322 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9323 | data_writes3, arraysize(data_writes3)); |
| 9324 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9325 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9326 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9327 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9328 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9329 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9331 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9332 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9333 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9334 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9336 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9337 | // Issue the first request with Authorize headers. There should be a |
| 9338 | // password prompt for first_realm waiting to be filled in after the |
| 9339 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9340 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9341 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9342 | rv = callback1.WaitForResult(); |
| 9343 | EXPECT_EQ(OK, rv); |
| 9344 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9345 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9346 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9347 | ASSERT_FALSE(challenge == NULL); |
| 9348 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9349 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9350 | EXPECT_EQ("first_realm", challenge->realm); |
| 9351 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9352 | |
| 9353 | // Issue the second request with an incorrect password. There should be a |
| 9354 | // password prompt for second_realm waiting to be filled in after the |
| 9355 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9356 | TestCompletionCallback callback2; |
| 9357 | rv = trans->RestartWithAuth( |
| 9358 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9359 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9360 | rv = callback2.WaitForResult(); |
| 9361 | EXPECT_EQ(OK, rv); |
| 9362 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9363 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9364 | challenge = response->auth_challenge.get(); |
| 9365 | ASSERT_FALSE(challenge == NULL); |
| 9366 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9367 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9368 | EXPECT_EQ("second_realm", challenge->realm); |
| 9369 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9370 | |
| 9371 | // Issue the third request with another incorrect password. There should be |
| 9372 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9373 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9374 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9375 | TestCompletionCallback callback3; |
| 9376 | rv = trans->RestartWithAuth( |
| 9377 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9378 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9379 | rv = callback3.WaitForResult(); |
| 9380 | EXPECT_EQ(OK, rv); |
| 9381 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9382 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9383 | challenge = response->auth_challenge.get(); |
| 9384 | ASSERT_FALSE(challenge == NULL); |
| 9385 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9386 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9387 | EXPECT_EQ("first_realm", challenge->realm); |
| 9388 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9389 | |
| 9390 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9391 | TestCompletionCallback callback4; |
| 9392 | rv = trans->RestartWithAuth( |
| 9393 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9394 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9395 | rv = callback4.WaitForResult(); |
| 9396 | EXPECT_EQ(OK, rv); |
| 9397 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9398 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9399 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9400 | } |
| 9401 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9402 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 9403 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9404 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9405 | |
| 9406 | std::string alternative_service_http_header = |
| 9407 | GetAlternativeServiceHttpHeader(); |
| 9408 | |
| 9409 | MockRead data_reads[] = { |
| 9410 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9411 | MockRead(alternative_service_http_header.c_str()), |
| 9412 | MockRead("\r\n"), |
| 9413 | MockRead("hello world"), |
| 9414 | MockRead(SYNCHRONOUS, OK), |
| 9415 | }; |
| 9416 | |
| 9417 | HttpRequestInfo request; |
| 9418 | request.method = "GET"; |
| 9419 | request.url = GURL("http://www.example.org/"); |
| 9420 | request.load_flags = 0; |
| 9421 | |
| 9422 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9423 | |
| 9424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9425 | |
| 9426 | TestCompletionCallback callback; |
| 9427 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9428 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9429 | scoped_ptr<HttpTransaction> trans( |
| 9430 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9431 | |
| 9432 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9433 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9434 | |
| 9435 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9436 | HttpServerProperties& http_server_properties = |
| 9437 | *session->http_server_properties(); |
| 9438 | AlternativeServiceVector alternative_service_vector = |
| 9439 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9440 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9441 | |
| 9442 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9443 | |
| 9444 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9445 | ASSERT_TRUE(response != NULL); |
| 9446 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9447 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9448 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9449 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9450 | |
| 9451 | std::string response_data; |
| 9452 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9453 | EXPECT_EQ("hello world", response_data); |
| 9454 | |
| 9455 | alternative_service_vector = |
| 9456 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9457 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9458 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9459 | alternative_service_vector[0].protocol); |
| 9460 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9461 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9462 | } |
| 9463 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9464 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 9465 | // is false. |
| 9466 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 9467 | session_deps_.next_protos = SpdyNextProtos(); |
| 9468 | session_deps_.use_alternative_services = false; |
| 9469 | |
| 9470 | std::string alternative_service_http_header = |
| 9471 | GetAlternativeServiceHttpHeader(); |
| 9472 | |
| 9473 | MockRead data_reads[] = { |
| 9474 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9475 | MockRead(alternative_service_http_header.c_str()), |
| 9476 | MockRead("\r\n"), |
| 9477 | MockRead("hello world"), |
| 9478 | MockRead(SYNCHRONOUS, OK), |
| 9479 | }; |
| 9480 | |
| 9481 | HttpRequestInfo request; |
| 9482 | request.method = "GET"; |
| 9483 | request.url = GURL("http://www.example.org/"); |
| 9484 | request.load_flags = 0; |
| 9485 | |
| 9486 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9487 | |
| 9488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9489 | |
| 9490 | TestCompletionCallback callback; |
| 9491 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9492 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9493 | scoped_ptr<HttpTransaction> trans( |
| 9494 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9495 | |
| 9496 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9498 | |
| 9499 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9500 | HttpServerProperties& http_server_properties = |
| 9501 | *session->http_server_properties(); |
| 9502 | AlternativeServiceVector alternative_service_vector = |
| 9503 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9504 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9505 | |
| 9506 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9507 | |
| 9508 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9509 | ASSERT_TRUE(response != nullptr); |
| 9510 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9511 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9512 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9513 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9514 | |
| 9515 | std::string response_data; |
| 9516 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9517 | EXPECT_EQ("hello world", response_data); |
| 9518 | |
| 9519 | alternative_service_vector = |
| 9520 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9521 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9522 | } |
| 9523 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9524 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 9525 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9526 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9527 | |
| 9528 | MockRead data_reads[] = { |
| 9529 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9530 | MockRead("Alt-Svc: "), |
| 9531 | MockRead(GetAlternateProtocolFromParam()), |
| 9532 | MockRead("=\"www.example.com:443\";p=1.0,"), |
| 9533 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 9534 | MockRead("hello world"), |
| 9535 | MockRead(SYNCHRONOUS, OK), |
| 9536 | }; |
| 9537 | |
| 9538 | HttpRequestInfo request; |
| 9539 | request.method = "GET"; |
| 9540 | request.url = GURL("http://www.example.org/"); |
| 9541 | request.load_flags = 0; |
| 9542 | |
| 9543 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9544 | |
| 9545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9546 | |
| 9547 | TestCompletionCallback callback; |
| 9548 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9549 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9550 | scoped_ptr<HttpTransaction> trans( |
| 9551 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9552 | |
| 9553 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9554 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9555 | |
| 9556 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9557 | HttpServerProperties& http_server_properties = |
| 9558 | *session->http_server_properties(); |
| 9559 | AlternativeServiceVector alternative_service_vector = |
| 9560 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9561 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9562 | |
| 9563 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9564 | |
| 9565 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9566 | ASSERT_TRUE(response != NULL); |
| 9567 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9568 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9569 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9570 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9571 | |
| 9572 | std::string response_data; |
| 9573 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9574 | EXPECT_EQ("hello world", response_data); |
| 9575 | |
| 9576 | alternative_service_vector = |
| 9577 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9578 | ASSERT_EQ(2u, alternative_service_vector.size()); |
| 9579 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9580 | alternative_service_vector[0].protocol); |
| 9581 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9582 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9583 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9584 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9585 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9586 | } |
| 9587 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9588 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9589 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9590 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9591 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9592 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9593 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9594 | std::string alternate_protocol_http_header = |
| 9595 | GetAlternateProtocolHttpHeader(); |
| 9596 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9597 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9598 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9599 | MockRead(alternate_protocol_http_header.c_str()), |
| 9600 | MockRead("\r\n"), |
| 9601 | MockRead("hello world"), |
| 9602 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9603 | }; |
| 9604 | |
| 9605 | HttpRequestInfo request; |
| 9606 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9607 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9608 | request.load_flags = 0; |
| 9609 | |
| 9610 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9611 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9612 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9614 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9615 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9616 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9617 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9618 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9620 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9621 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9622 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9623 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9624 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9625 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9626 | AlternativeServiceVector alternative_service_vector = |
| 9627 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9628 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9629 | |
| 9630 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9631 | |
| 9632 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9633 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9634 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9635 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9636 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9637 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9638 | |
| 9639 | std::string response_data; |
| 9640 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9641 | EXPECT_EQ("hello world", response_data); |
| 9642 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9643 | alternative_service_vector = |
| 9644 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9645 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9646 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 9647 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9648 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9649 | } |
| 9650 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9651 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9652 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9653 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9654 | |
| 9655 | MockRead data_reads[] = { |
| 9656 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9657 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9658 | MockRead("hello world"), |
| 9659 | MockRead(SYNCHRONOUS, OK), |
| 9660 | }; |
| 9661 | |
| 9662 | HttpRequestInfo request; |
| 9663 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9664 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9665 | request.load_flags = 0; |
| 9666 | |
| 9667 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9668 | |
| 9669 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9670 | |
| 9671 | TestCompletionCallback callback; |
| 9672 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9673 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9674 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9675 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9676 | HttpServerProperties& http_server_properties = |
| 9677 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9678 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9679 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9680 | http_server_properties.SetAlternativeService( |
| 9681 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9682 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9683 | AlternativeServiceVector alternative_service_vector = |
| 9684 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9685 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9686 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9687 | |
| 9688 | scoped_ptr<HttpTransaction> trans( |
| 9689 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9690 | |
| 9691 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9692 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9693 | |
| 9694 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9695 | |
| 9696 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9697 | ASSERT_TRUE(response != NULL); |
| 9698 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9699 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9700 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9701 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9702 | |
| 9703 | std::string response_data; |
| 9704 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9705 | EXPECT_EQ("hello world", response_data); |
| 9706 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9707 | alternative_service_vector = |
| 9708 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9709 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9710 | } |
| 9711 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9712 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9713 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9714 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9715 | |
| 9716 | std::string alternative_service_http_header = |
| 9717 | GetAlternativeServiceHttpHeader(); |
| 9718 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9719 | |
| 9720 | MockRead data_reads[] = { |
| 9721 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9722 | MockRead(alternative_service_http_header.c_str()), |
| 9723 | MockRead(alternate_protocol_http_header.c_str()), |
| 9724 | MockRead("\r\n"), |
| 9725 | MockRead("hello world"), |
| 9726 | MockRead(SYNCHRONOUS, OK), |
| 9727 | }; |
| 9728 | |
| 9729 | HttpRequestInfo request; |
| 9730 | request.method = "GET"; |
| 9731 | request.url = GURL("http://www.example.org/"); |
| 9732 | request.load_flags = 0; |
| 9733 | |
| 9734 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9735 | |
| 9736 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9737 | |
| 9738 | TestCompletionCallback callback; |
| 9739 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9740 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9741 | scoped_ptr<HttpTransaction> trans( |
| 9742 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9743 | |
| 9744 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9746 | |
| 9747 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9748 | HttpServerProperties& http_server_properties = |
| 9749 | *session->http_server_properties(); |
| 9750 | AlternativeServiceVector alternative_service_vector = |
| 9751 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9752 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9753 | |
| 9754 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9755 | |
| 9756 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9757 | ASSERT_TRUE(response != NULL); |
| 9758 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9759 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9760 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9761 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9762 | |
| 9763 | std::string response_data; |
| 9764 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9765 | EXPECT_EQ("hello world", response_data); |
| 9766 | |
| 9767 | alternative_service_vector = |
| 9768 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9769 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9770 | EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 9771 | alternative_service_vector[0].protocol); |
| 9772 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9773 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9774 | } |
| 9775 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9776 | // When |use_alternative_services| is false, do not observe alternative service |
| 9777 | // entries that point to a different host. |
| 9778 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9779 | session_deps_.use_alternative_services = false; |
| 9780 | |
| 9781 | HttpRequestInfo request; |
| 9782 | request.method = "GET"; |
| 9783 | request.url = GURL("http://www.example.org/"); |
| 9784 | request.load_flags = 0; |
| 9785 | |
| 9786 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9787 | StaticSocketDataProvider first_data; |
| 9788 | first_data.set_connect_data(mock_connect); |
| 9789 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9790 | |
| 9791 | MockRead data_reads[] = { |
| 9792 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9793 | MockRead(ASYNC, OK), |
| 9794 | }; |
| 9795 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9796 | nullptr, 0); |
| 9797 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9798 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9799 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9800 | |
| 9801 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9802 | session->http_server_properties(); |
| 9803 | AlternativeService alternative_service( |
| 9804 | AlternateProtocolFromNextProto(GetParam()), "different.example.org", 80); |
| 9805 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9806 | http_server_properties->SetAlternativeService( |
| 9807 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9808 | |
| 9809 | scoped_ptr<HttpTransaction> trans( |
| 9810 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9811 | TestCompletionCallback callback; |
| 9812 | |
| 9813 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9814 | // The connetion to origin was refused, and the alternative service should not |
| 9815 | // be used (even though mock data are there), therefore the request should |
| 9816 | // fail. |
| 9817 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9818 | } |
| 9819 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9820 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9821 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9822 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9823 | |
| 9824 | HttpRequestInfo request; |
| 9825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9826 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9827 | request.load_flags = 0; |
| 9828 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9829 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9830 | StaticSocketDataProvider first_data; |
| 9831 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9832 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9833 | |
| 9834 | MockRead data_reads[] = { |
| 9835 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9836 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9837 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9838 | }; |
| 9839 | StaticSocketDataProvider second_data( |
| 9840 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9841 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9842 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9843 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9844 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9845 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9846 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9847 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9848 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9849 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9850 | const AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9851 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9852 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9853 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9854 | http_server_properties->SetAlternativeService( |
| 9855 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9856 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9857 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9858 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9859 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9861 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9863 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9864 | |
| 9865 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9866 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9867 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9868 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9869 | |
| 9870 | std::string response_data; |
| 9871 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9872 | EXPECT_EQ("hello world", response_data); |
| 9873 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9874 | const AlternativeServiceVector alternative_service_vector = |
| 9875 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9876 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9877 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9878 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9879 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9880 | } |
| 9881 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9882 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9883 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9884 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9885 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9886 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9887 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9888 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9889 | |
| 9890 | HttpRequestInfo restricted_port_request; |
| 9891 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9892 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9893 | restricted_port_request.load_flags = 0; |
| 9894 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9895 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9896 | StaticSocketDataProvider first_data; |
| 9897 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9898 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9899 | |
| 9900 | MockRead data_reads[] = { |
| 9901 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9902 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9903 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9904 | }; |
| 9905 | StaticSocketDataProvider second_data( |
| 9906 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9907 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9908 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9909 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9910 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9911 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9912 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9913 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9914 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9915 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9916 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9917 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9918 | http_server_properties->SetAlternativeService( |
| 9919 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9920 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9921 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9922 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9923 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9924 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9926 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9927 | &restricted_port_request, |
| 9928 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9930 | // Invalid change to unrestricted port should fail. |
| 9931 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9932 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9933 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9934 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 9935 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 9936 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9937 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9938 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9939 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9940 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9941 | |
| 9942 | HttpRequestInfo restricted_port_request; |
| 9943 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9944 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9945 | restricted_port_request.load_flags = 0; |
| 9946 | |
| 9947 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9948 | StaticSocketDataProvider first_data; |
| 9949 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9950 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9951 | |
| 9952 | MockRead data_reads[] = { |
| 9953 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9954 | MockRead("hello world"), |
| 9955 | MockRead(ASYNC, OK), |
| 9956 | }; |
| 9957 | StaticSocketDataProvider second_data( |
| 9958 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9959 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9960 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 9961 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9962 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9963 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9964 | session->http_server_properties(); |
| 9965 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9966 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9967 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9968 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9969 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9970 | http_server_properties->SetAlternativeService( |
| 9971 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9972 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9973 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9974 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9975 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9976 | TestCompletionCallback callback; |
| 9977 | |
| 9978 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9979 | &restricted_port_request, |
| 9980 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 9981 | // Change to unrestricted port should succeed. |
| 9982 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9983 | } |
| 9984 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9985 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9986 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9987 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9988 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9989 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9990 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9991 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9992 | |
| 9993 | HttpRequestInfo restricted_port_request; |
| 9994 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9995 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9996 | restricted_port_request.load_flags = 0; |
| 9997 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9998 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9999 | StaticSocketDataProvider first_data; |
| 10000 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10001 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10002 | |
| 10003 | MockRead data_reads[] = { |
| 10004 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10005 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10006 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10007 | }; |
| 10008 | StaticSocketDataProvider second_data( |
| 10009 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10010 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10011 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10012 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10013 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10014 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10015 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10016 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10017 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10018 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10019 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10020 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10021 | http_server_properties->SetAlternativeService( |
| 10022 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10023 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10024 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10025 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10026 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10027 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10029 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10030 | &restricted_port_request, |
| 10031 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10033 | // Valid change to restricted port should pass. |
| 10034 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10035 | } |
| 10036 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10037 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10038 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10039 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10040 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10041 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10042 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10043 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10044 | |
| 10045 | HttpRequestInfo unrestricted_port_request; |
| 10046 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10047 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10048 | unrestricted_port_request.load_flags = 0; |
| 10049 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10050 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10051 | StaticSocketDataProvider first_data; |
| 10052 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10053 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10054 | |
| 10055 | MockRead data_reads[] = { |
| 10056 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10057 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10058 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10059 | }; |
| 10060 | StaticSocketDataProvider second_data( |
| 10061 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10062 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10063 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10064 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10065 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10066 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10067 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10068 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10069 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10070 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10071 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10072 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10073 | http_server_properties->SetAlternativeService( |
| 10074 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10075 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10076 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10077 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10079 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10081 | int rv = trans->Start( |
| 10082 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10084 | // Valid change to restricted port should pass. |
| 10085 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10086 | } |
| 10087 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10088 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10089 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10090 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10091 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10092 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10093 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10094 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10095 | |
| 10096 | HttpRequestInfo unrestricted_port_request; |
| 10097 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10098 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10099 | unrestricted_port_request.load_flags = 0; |
| 10100 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10101 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10102 | StaticSocketDataProvider first_data; |
| 10103 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10104 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10105 | |
| 10106 | MockRead data_reads[] = { |
| 10107 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10108 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10109 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10110 | }; |
| 10111 | StaticSocketDataProvider second_data( |
| 10112 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10113 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10114 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10115 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10116 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10117 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10118 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10119 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10120 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10121 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10122 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10123 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10124 | http_server_properties->SetAlternativeService( |
| 10125 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10126 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10127 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10128 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10129 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10130 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10132 | int rv = trans->Start( |
| 10133 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10134 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10135 | // Valid change to an unrestricted port should pass. |
| 10136 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10137 | } |
| 10138 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10139 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10140 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10141 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10142 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10143 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10144 | |
| 10145 | HttpRequestInfo request; |
| 10146 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10147 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10148 | request.load_flags = 0; |
| 10149 | |
| 10150 | // The alternate protocol request will error out before we attempt to connect, |
| 10151 | // so only the standard HTTP request will try to connect. |
| 10152 | MockRead data_reads[] = { |
| 10153 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10154 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10155 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10156 | }; |
| 10157 | StaticSocketDataProvider data( |
| 10158 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10160 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10161 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10162 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10163 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10164 | session->http_server_properties(); |
| 10165 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10166 | AlternativeService alternative_service( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10167 | AlternateProtocolFromNextProto(GetParam()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10168 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10169 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10170 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10171 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10172 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10173 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10174 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10175 | TestCompletionCallback callback; |
| 10176 | |
| 10177 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10178 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10179 | // The HTTP request should succeed. |
| 10180 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10181 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10182 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10183 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10184 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10185 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10186 | |
| 10187 | std::string response_data; |
| 10188 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10189 | EXPECT_EQ("hello world", response_data); |
| 10190 | } |
| 10191 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10192 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10193 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10194 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10195 | |
| 10196 | HttpRequestInfo request; |
| 10197 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10198 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10199 | request.load_flags = 0; |
| 10200 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10201 | std::string alternate_protocol_http_header = |
| 10202 | GetAlternateProtocolHttpHeader(); |
| 10203 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10204 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10205 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10206 | MockRead(alternate_protocol_http_header.c_str()), |
| 10207 | MockRead("\r\n"), |
| 10208 | MockRead("hello world"), |
| 10209 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10210 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10211 | |
| 10212 | StaticSocketDataProvider first_transaction( |
| 10213 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10214 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10215 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10216 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10217 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10218 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10219 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10220 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10221 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10222 | scoped_ptr<SpdyFrame> req( |
| 10223 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10224 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10225 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10226 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10227 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10228 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10229 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10230 | }; |
| 10231 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10232 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10233 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10234 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10235 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10236 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10237 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10238 | NULL, 0, NULL, 0); |
| 10239 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10240 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10241 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10242 | &hanging_non_alternate_protocol_socket); |
| 10243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10244 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10245 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10246 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10247 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10248 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10250 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10251 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10252 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10253 | |
| 10254 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10255 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10256 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10257 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10258 | |
| 10259 | std::string response_data; |
| 10260 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10261 | EXPECT_EQ("hello world", response_data); |
| 10262 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10263 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10265 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10266 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10267 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10268 | |
| 10269 | response = trans->GetResponseInfo(); |
| 10270 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10271 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10272 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10273 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10274 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10275 | |
| 10276 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10277 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10278 | } |
| 10279 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10280 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10281 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10282 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10283 | |
| 10284 | HttpRequestInfo request; |
| 10285 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10286 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10287 | request.load_flags = 0; |
| 10288 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10289 | std::string alternate_protocol_http_header = |
| 10290 | GetAlternateProtocolHttpHeader(); |
| 10291 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10292 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10293 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10294 | MockRead(alternate_protocol_http_header.c_str()), |
| 10295 | MockRead("\r\n"), |
| 10296 | MockRead("hello world"), |
| 10297 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10298 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10299 | }; |
| 10300 | |
| 10301 | StaticSocketDataProvider first_transaction( |
| 10302 | data_reads, arraysize(data_reads), NULL, 0); |
| 10303 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10304 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10305 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10306 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10307 | StaticSocketDataProvider hanging_socket( |
| 10308 | NULL, 0, NULL, 0); |
| 10309 | hanging_socket.set_connect_data(never_finishing_connect); |
| 10310 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10311 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10312 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 10313 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10314 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10315 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10316 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10317 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10318 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10319 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10320 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10321 | scoped_ptr<SpdyFrame> req1( |
| 10322 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 10323 | scoped_ptr<SpdyFrame> req2( |
| 10324 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10325 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10326 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10327 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10328 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10329 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10330 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10331 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10332 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10333 | CreateMockRead(*resp1, 2), |
| 10334 | CreateMockRead(*data1, 3), |
| 10335 | CreateMockRead(*resp2, 4), |
| 10336 | CreateMockRead(*data2, 5), |
| 10337 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10338 | }; |
| 10339 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10340 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10341 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10342 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10343 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10344 | |
| 10345 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10346 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10347 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10348 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10349 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10350 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10352 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10354 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10355 | |
| 10356 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10357 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10358 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10359 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10360 | |
| 10361 | std::string response_data; |
| 10362 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10363 | EXPECT_EQ("hello world", response_data); |
| 10364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10365 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10366 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10367 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10370 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10371 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10372 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10373 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10374 | |
| 10375 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10376 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10377 | |
| 10378 | response = trans2.GetResponseInfo(); |
| 10379 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10380 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10381 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10382 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10383 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10384 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10385 | EXPECT_EQ("hello!", response_data); |
| 10386 | |
| 10387 | response = trans3.GetResponseInfo(); |
| 10388 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10389 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10390 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10391 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10392 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10393 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10394 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10395 | } |
| 10396 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10397 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10398 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10399 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10400 | |
| 10401 | HttpRequestInfo request; |
| 10402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10404 | request.load_flags = 0; |
| 10405 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10406 | std::string alternate_protocol_http_header = |
| 10407 | GetAlternateProtocolHttpHeader(); |
| 10408 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10409 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10410 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10411 | MockRead(alternate_protocol_http_header.c_str()), |
| 10412 | MockRead("\r\n"), |
| 10413 | MockRead("hello world"), |
| 10414 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10415 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10416 | }; |
| 10417 | |
| 10418 | StaticSocketDataProvider first_transaction( |
| 10419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10420 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10421 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10422 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10423 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10424 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10425 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10426 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10427 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10428 | NULL, 0, NULL, 0); |
| 10429 | hanging_alternate_protocol_socket.set_connect_data( |
| 10430 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10431 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10432 | &hanging_alternate_protocol_socket); |
| 10433 | |
| 10434 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10435 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10437 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10438 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10439 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10440 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10445 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10446 | |
| 10447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10448 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10449 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10450 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10451 | |
| 10452 | std::string response_data; |
| 10453 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10454 | EXPECT_EQ("hello world", response_data); |
| 10455 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10456 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10458 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10459 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10460 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10461 | |
| 10462 | response = trans->GetResponseInfo(); |
| 10463 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10464 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10465 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10466 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10467 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10468 | |
| 10469 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10470 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10471 | } |
| 10472 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10473 | class CapturingProxyResolver : public ProxyResolver { |
| 10474 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10475 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10476 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10477 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10478 | int GetProxyForURL(const GURL& url, |
| 10479 | ProxyInfo* results, |
| 10480 | const CompletionCallback& callback, |
| 10481 | RequestHandle* request, |
| 10482 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10483 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10484 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10485 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10486 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10487 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10488 | } |
| 10489 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10490 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10491 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10492 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 10493 | NOTREACHED(); |
| 10494 | return LOAD_STATE_IDLE; |
| 10495 | } |
| 10496 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10497 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10498 | |
| 10499 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10500 | std::vector<GURL> resolved_; |
| 10501 | |
| 10502 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10503 | }; |
| 10504 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10505 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10506 | public: |
| 10507 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10508 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10509 | |
| 10510 | int CreateProxyResolver( |
| 10511 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10512 | scoped_ptr<ProxyResolver>* resolver, |
| 10513 | const net::CompletionCallback& callback, |
| 10514 | scoped_ptr<Request>* request) override { |
| 10515 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10516 | return OK; |
| 10517 | } |
| 10518 | |
| 10519 | private: |
| 10520 | ProxyResolver* resolver_; |
| 10521 | }; |
| 10522 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10523 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10524 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10525 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10526 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10527 | |
| 10528 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10529 | proxy_config.set_auto_detect(true); |
| 10530 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 10531 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10532 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10533 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 10534 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10535 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10536 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 10537 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10538 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10539 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10540 | |
| 10541 | HttpRequestInfo request; |
| 10542 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10543 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10544 | request.load_flags = 0; |
| 10545 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10546 | std::string alternate_protocol_http_header = |
| 10547 | GetAlternateProtocolHttpHeader(); |
| 10548 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10549 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10550 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10551 | MockRead(alternate_protocol_http_header.c_str()), |
| 10552 | MockRead("\r\n"), |
| 10553 | MockRead("hello world"), |
| 10554 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10555 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10556 | }; |
| 10557 | |
| 10558 | StaticSocketDataProvider first_transaction( |
| 10559 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10560 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10561 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10562 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10563 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10564 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10565 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10567 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10568 | scoped_ptr<SpdyFrame> req( |
| 10569 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10570 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10571 | MockWrite(ASYNC, 0, |
| 10572 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10573 | "Host: www.example.org\r\n" |
| 10574 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10575 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10576 | }; |
| 10577 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10578 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10579 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10580 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10581 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10582 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10583 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10584 | CreateMockRead(*resp.get(), 3), |
| 10585 | CreateMockRead(*data.get(), 4), |
| 10586 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10587 | }; |
| 10588 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10589 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10590 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10591 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10592 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10593 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10594 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10595 | NULL, 0, NULL, 0); |
| 10596 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10597 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10598 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10599 | &hanging_non_alternate_protocol_socket); |
| 10600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10601 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10602 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10603 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10604 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10607 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10609 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10610 | |
| 10611 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10612 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10613 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10614 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10615 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10616 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10617 | |
| 10618 | std::string response_data; |
| 10619 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10620 | EXPECT_EQ("hello world", response_data); |
| 10621 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10622 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10624 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10625 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10626 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10627 | |
| 10628 | response = trans->GetResponseInfo(); |
| 10629 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10630 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10631 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10632 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10633 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10634 | |
| 10635 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10636 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10637 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10638 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10639 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10640 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10641 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10642 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10643 | LoadTimingInfo load_timing_info; |
| 10644 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10645 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10646 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10647 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10648 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10649 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10650 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10651 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10652 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10653 | |
| 10654 | HttpRequestInfo request; |
| 10655 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10656 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10657 | request.load_flags = 0; |
| 10658 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10659 | std::string alternate_protocol_http_header = |
| 10660 | GetAlternateProtocolHttpHeader(); |
| 10661 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10662 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10663 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10664 | MockRead(alternate_protocol_http_header.c_str()), |
| 10665 | MockRead("\r\n"), |
| 10666 | MockRead("hello world"), |
| 10667 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10668 | }; |
| 10669 | |
| 10670 | StaticSocketDataProvider first_transaction( |
| 10671 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10672 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10673 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10674 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10675 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10676 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10677 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10679 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10680 | scoped_ptr<SpdyFrame> req( |
| 10681 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10682 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10683 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10684 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10685 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10686 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10687 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10688 | }; |
| 10689 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10690 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10691 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10692 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10693 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10694 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10695 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10696 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10697 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10698 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10699 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10701 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10703 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10704 | |
| 10705 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10706 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10707 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10708 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10709 | |
| 10710 | std::string response_data; |
| 10711 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10712 | EXPECT_EQ("hello world", response_data); |
| 10713 | |
| 10714 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10715 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10716 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10717 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10718 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 10719 | CreateSecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10720 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10721 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10723 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10724 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10725 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10726 | |
| 10727 | response = trans->GetResponseInfo(); |
| 10728 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10729 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10730 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10731 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10732 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10733 | |
| 10734 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10735 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10736 | } |
| 10737 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10738 | // GenerateAuthToken is a mighty big test. |
| 10739 | // It tests all permutation of GenerateAuthToken behavior: |
| 10740 | // - Synchronous and Asynchronous completion. |
| 10741 | // - OK or error on completion. |
| 10742 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10743 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10744 | // - Non-authenticating and authenticating backend. |
| 10745 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10746 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10747 | // problems generating an auth token for an authenticating proxy, we don't |
| 10748 | // need to test all permutations of the backend server). |
| 10749 | // |
| 10750 | // The test proceeds by going over each of the configuration cases, and |
| 10751 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10752 | // specifies both the configuration for the test as well as the expectations |
| 10753 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10754 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10755 | static const char kServer[] = "http://www.example.com"; |
| 10756 | static const char kSecureServer[] = "https://www.example.com"; |
| 10757 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10758 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10759 | |
| 10760 | enum AuthTiming { |
| 10761 | AUTH_NONE, |
| 10762 | AUTH_SYNC, |
| 10763 | AUTH_ASYNC, |
| 10764 | }; |
| 10765 | |
| 10766 | const MockWrite kGet( |
| 10767 | "GET / HTTP/1.1\r\n" |
| 10768 | "Host: www.example.com\r\n" |
| 10769 | "Connection: keep-alive\r\n\r\n"); |
| 10770 | const MockWrite kGetProxy( |
| 10771 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10772 | "Host: www.example.com\r\n" |
| 10773 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10774 | const MockWrite kGetAuth( |
| 10775 | "GET / HTTP/1.1\r\n" |
| 10776 | "Host: www.example.com\r\n" |
| 10777 | "Connection: keep-alive\r\n" |
| 10778 | "Authorization: auth_token\r\n\r\n"); |
| 10779 | const MockWrite kGetProxyAuth( |
| 10780 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10781 | "Host: www.example.com\r\n" |
| 10782 | "Proxy-Connection: keep-alive\r\n" |
| 10783 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10784 | const MockWrite kGetAuthThroughProxy( |
| 10785 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10786 | "Host: www.example.com\r\n" |
| 10787 | "Proxy-Connection: keep-alive\r\n" |
| 10788 | "Authorization: auth_token\r\n\r\n"); |
| 10789 | const MockWrite kGetAuthWithProxyAuth( |
| 10790 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10791 | "Host: www.example.com\r\n" |
| 10792 | "Proxy-Connection: keep-alive\r\n" |
| 10793 | "Proxy-Authorization: auth_token\r\n" |
| 10794 | "Authorization: auth_token\r\n\r\n"); |
| 10795 | const MockWrite kConnect( |
| 10796 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10797 | "Host: www.example.com\r\n" |
| 10798 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10799 | const MockWrite kConnectProxyAuth( |
| 10800 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 10801 | "Host: www.example.com\r\n" |
| 10802 | "Proxy-Connection: keep-alive\r\n" |
| 10803 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10804 | |
| 10805 | const MockRead kSuccess( |
| 10806 | "HTTP/1.1 200 OK\r\n" |
| 10807 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10808 | "Content-Length: 3\r\n\r\n" |
| 10809 | "Yes"); |
| 10810 | const MockRead kFailure( |
| 10811 | "Should not be called."); |
| 10812 | const MockRead kServerChallenge( |
| 10813 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10814 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10815 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10816 | "Content-Length: 14\r\n\r\n" |
| 10817 | "Unauthorized\r\n"); |
| 10818 | const MockRead kProxyChallenge( |
| 10819 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10820 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10821 | "Proxy-Connection: close\r\n" |
| 10822 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10823 | "Content-Length: 14\r\n\r\n" |
| 10824 | "Unauthorized\r\n"); |
| 10825 | const MockRead kProxyConnected( |
| 10826 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10827 | |
| 10828 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10829 | // no constructors, but the C++ compiler on Windows warns about |
| 10830 | // unspecified data in compound literals. So, moved to using constructors, |
| 10831 | // and TestRound's created with the default constructor should not be used. |
| 10832 | struct TestRound { |
| 10833 | TestRound() |
| 10834 | : expected_rv(ERR_UNEXPECTED), |
| 10835 | extra_write(NULL), |
| 10836 | extra_read(NULL) { |
| 10837 | } |
| 10838 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10839 | int expected_rv_arg) |
| 10840 | : write(write_arg), |
| 10841 | read(read_arg), |
| 10842 | expected_rv(expected_rv_arg), |
| 10843 | extra_write(NULL), |
| 10844 | extra_read(NULL) { |
| 10845 | } |
| 10846 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10847 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10848 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10849 | : write(write_arg), |
| 10850 | read(read_arg), |
| 10851 | expected_rv(expected_rv_arg), |
| 10852 | extra_write(extra_write_arg), |
| 10853 | extra_read(extra_read_arg) { |
| 10854 | } |
| 10855 | MockWrite write; |
| 10856 | MockRead read; |
| 10857 | int expected_rv; |
| 10858 | const MockWrite* extra_write; |
| 10859 | const MockRead* extra_read; |
| 10860 | }; |
| 10861 | |
| 10862 | static const int kNoSSL = 500; |
| 10863 | |
| 10864 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10865 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10866 | AuthTiming proxy_auth_timing; |
| 10867 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10868 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10869 | AuthTiming server_auth_timing; |
| 10870 | int server_auth_rv; |
| 10871 | int num_auth_rounds; |
| 10872 | int first_ssl_round; |
| 10873 | TestRound rounds[3]; |
| 10874 | } test_configs[] = { |
| 10875 | // Non-authenticating HTTP server with a direct connection. |
| 10876 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10877 | { TestRound(kGet, kSuccess, OK)}}, |
| 10878 | // Authenticating HTTP server with a direct connection. |
| 10879 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10880 | { TestRound(kGet, kServerChallenge, OK), |
| 10881 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10882 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10883 | { TestRound(kGet, kServerChallenge, OK), |
| 10884 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10885 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10886 | { TestRound(kGet, kServerChallenge, OK), |
| 10887 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10888 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10889 | { TestRound(kGet, kServerChallenge, OK), |
| 10890 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10891 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10892 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10893 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10894 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10895 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10896 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10897 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10898 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10899 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10900 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10901 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10902 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10903 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10904 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10905 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10906 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10907 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10908 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10909 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10910 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10911 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10912 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10913 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10914 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10915 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10916 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10917 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10918 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10919 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10920 | // Authenticating HTTP server through an authenticating proxy. |
| 10921 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10922 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10923 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10924 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10925 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10926 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10927 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10928 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10929 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10930 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10931 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10932 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10933 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10934 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10935 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10936 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10937 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10938 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10939 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10940 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10941 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10942 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10943 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10944 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10945 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 10946 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10947 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10948 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10949 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 10950 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10951 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10952 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10953 | // Non-authenticating HTTPS server with a direct connection. |
| 10954 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10955 | { TestRound(kGet, kSuccess, OK)}}, |
| 10956 | // Authenticating HTTPS server with a direct connection. |
| 10957 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10958 | { TestRound(kGet, kServerChallenge, OK), |
| 10959 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10960 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10961 | { TestRound(kGet, kServerChallenge, OK), |
| 10962 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10963 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10964 | { TestRound(kGet, kServerChallenge, OK), |
| 10965 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10966 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10967 | { TestRound(kGet, kServerChallenge, OK), |
| 10968 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10969 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 10970 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 10971 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10972 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 10973 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 10974 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10975 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10976 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 10977 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10978 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10979 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 10980 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10981 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10982 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 10983 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 10984 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10985 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 10986 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10987 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10988 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10989 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10990 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10991 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10992 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 10993 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10994 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 10995 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10996 | { TestRound(kConnect, kProxyChallenge, OK), |
| 10997 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 10998 | // Authenticating HTTPS server through an authenticating proxy. |
| 10999 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11000 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11001 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11002 | &kGet, &kServerChallenge), |
| 11003 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11004 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11005 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11006 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11007 | &kGet, &kServerChallenge), |
| 11008 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11009 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11010 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11011 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11012 | &kGet, &kServerChallenge), |
| 11013 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11014 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11015 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11016 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11017 | &kGet, &kServerChallenge), |
| 11018 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11019 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11020 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11021 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11022 | &kGet, &kServerChallenge), |
| 11023 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11024 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11025 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11026 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11027 | &kGet, &kServerChallenge), |
| 11028 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11029 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11030 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11031 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11032 | &kGet, &kServerChallenge), |
| 11033 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11034 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11035 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11036 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11037 | &kGet, &kServerChallenge), |
| 11038 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11039 | }; |
| 11040 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11041 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11042 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11043 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11044 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11045 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11046 | |
| 11047 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11048 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11049 | for (int n = 0; n < 2; n++) { |
| 11050 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11051 | std::string auth_challenge = "Mock realm=proxy"; |
| 11052 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11053 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11054 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11055 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11056 | origin, BoundNetLog()); |
| 11057 | auth_handler->SetGenerateExpectation( |
| 11058 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11059 | test_config.proxy_auth_rv); |
| 11060 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11061 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11062 | } |
| 11063 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11064 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11065 | std::string auth_challenge = "Mock realm=server"; |
| 11066 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11067 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11068 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11069 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11070 | origin, BoundNetLog()); |
| 11071 | auth_handler->SetGenerateExpectation( |
| 11072 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11073 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11074 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11075 | } |
| 11076 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11077 | session_deps_.proxy_service = |
| 11078 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11079 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11080 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11081 | } |
| 11082 | |
| 11083 | HttpRequestInfo request; |
| 11084 | request.method = "GET"; |
| 11085 | request.url = GURL(test_config.server_url); |
| 11086 | request.load_flags = 0; |
| 11087 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11088 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11090 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11091 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11092 | |
| 11093 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11094 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11095 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11096 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11097 | |
| 11098 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11099 | mock_reads.back().push_back(read_write_round.read); |
| 11100 | mock_writes.back().push_back(read_write_round.write); |
| 11101 | |
| 11102 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11103 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11104 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11105 | mock_reads.push_back(std::vector<MockRead>()); |
| 11106 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11107 | } |
| 11108 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11109 | if (read_write_round.extra_read) { |
| 11110 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11111 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11112 | if (read_write_round.extra_write) { |
| 11113 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11114 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11115 | |
| 11116 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11117 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11118 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11119 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11120 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11121 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11122 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 11123 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 11124 | data_providers.push_back(new StaticSocketDataProvider( |
| 11125 | vector_as_array(&mock_reads[i]), mock_reads[i].size(), |
| 11126 | vector_as_array(&mock_writes[i]), mock_writes[i].size())); |
| 11127 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11128 | data_providers.back()); |
| 11129 | } |
| 11130 | |
| 11131 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11132 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11133 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11134 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11135 | int rv; |
| 11136 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11137 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11138 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11139 | rv = trans.RestartWithAuth( |
| 11140 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11141 | } |
| 11142 | if (rv == ERR_IO_PENDING) |
| 11143 | rv = callback.WaitForResult(); |
| 11144 | |
| 11145 | // Compare results with expected data. |
| 11146 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11147 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11148 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11149 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11150 | continue; |
| 11151 | } |
| 11152 | if (round + 1 < test_config.num_auth_rounds) { |
| 11153 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11154 | } else { |
| 11155 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11156 | } |
| 11157 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11158 | } |
| 11159 | } |
| 11160 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11161 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11162 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11163 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11164 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11165 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11166 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11167 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11168 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11169 | |
| 11170 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11171 | auth_handler->set_connection_based(true); |
| 11172 | std::string auth_challenge = "Mock realm=server"; |
| 11173 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11174 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11175 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11176 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11177 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11178 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11179 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11180 | int rv = OK; |
| 11181 | const HttpResponseInfo* response = NULL; |
| 11182 | HttpRequestInfo request; |
| 11183 | request.method = "GET"; |
| 11184 | request.url = origin; |
| 11185 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11186 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11187 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11188 | |
| 11189 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11190 | // to validate that the TCP socket is not released to the pool between |
| 11191 | // each round of multi-round authentication. |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11192 | HttpNetworkSessionPeer session_peer(session); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11193 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11194 | 50, // Max sockets for pool |
| 11195 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11196 | session_deps_.host_resolver.get(), |
| 11197 | session_deps_.socket_factory.get(), |
| 11198 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11199 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11200 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11201 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 11202 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11203 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11204 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11205 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11206 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11207 | |
| 11208 | const MockWrite kGet( |
| 11209 | "GET / HTTP/1.1\r\n" |
| 11210 | "Host: www.example.com\r\n" |
| 11211 | "Connection: keep-alive\r\n\r\n"); |
| 11212 | const MockWrite kGetAuth( |
| 11213 | "GET / HTTP/1.1\r\n" |
| 11214 | "Host: www.example.com\r\n" |
| 11215 | "Connection: keep-alive\r\n" |
| 11216 | "Authorization: auth_token\r\n\r\n"); |
| 11217 | |
| 11218 | const MockRead kServerChallenge( |
| 11219 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11220 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11221 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11222 | "Content-Length: 14\r\n\r\n" |
| 11223 | "Unauthorized\r\n"); |
| 11224 | const MockRead kSuccess( |
| 11225 | "HTTP/1.1 200 OK\r\n" |
| 11226 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11227 | "Content-Length: 3\r\n\r\n" |
| 11228 | "Yes"); |
| 11229 | |
| 11230 | MockWrite writes[] = { |
| 11231 | // First round |
| 11232 | kGet, |
| 11233 | // Second round |
| 11234 | kGetAuth, |
| 11235 | // Third round |
| 11236 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11237 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11238 | kGetAuth, |
| 11239 | // Competing request |
| 11240 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11241 | }; |
| 11242 | MockRead reads[] = { |
| 11243 | // First round |
| 11244 | kServerChallenge, |
| 11245 | // Second round |
| 11246 | kServerChallenge, |
| 11247 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11248 | kServerChallenge, |
| 11249 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11250 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11251 | // Competing response |
| 11252 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11253 | }; |
| 11254 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11255 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11256 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11257 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11258 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11259 | |
| 11260 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11261 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11262 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11263 | if (rv == ERR_IO_PENDING) |
| 11264 | rv = callback.WaitForResult(); |
| 11265 | EXPECT_EQ(OK, rv); |
| 11266 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11267 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11268 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11269 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11270 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11271 | // In between rounds, another request comes in for the same domain. |
| 11272 | // It should not be able to grab the TCP socket that trans has already |
| 11273 | // claimed. |
| 11274 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11276 | TestCompletionCallback callback_compete; |
| 11277 | rv = trans_compete->Start( |
| 11278 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11279 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11280 | // callback_compete.WaitForResult at this point would stall forever, |
| 11281 | // since the HttpNetworkTransaction does not release the request back to |
| 11282 | // the pool until after authentication completes. |
| 11283 | |
| 11284 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11285 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11286 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11287 | if (rv == ERR_IO_PENDING) |
| 11288 | rv = callback.WaitForResult(); |
| 11289 | EXPECT_EQ(OK, rv); |
| 11290 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11291 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11292 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11293 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11294 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11295 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11296 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11297 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11298 | if (rv == ERR_IO_PENDING) |
| 11299 | rv = callback.WaitForResult(); |
| 11300 | EXPECT_EQ(OK, rv); |
| 11301 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11302 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11303 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11304 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11305 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11306 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11307 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11308 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11309 | if (rv == ERR_IO_PENDING) |
| 11310 | rv = callback.WaitForResult(); |
| 11311 | EXPECT_EQ(OK, rv); |
| 11312 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11313 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11314 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11315 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11316 | |
| 11317 | // Read the body since the fourth round was successful. This will also |
| 11318 | // release the socket back to the pool. |
| 11319 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11320 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11321 | if (rv == ERR_IO_PENDING) |
| 11322 | rv = callback.WaitForResult(); |
| 11323 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11324 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11325 | EXPECT_EQ(0, rv); |
| 11326 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11327 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11328 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11329 | |
| 11330 | // The competing request can now finish. Wait for the headers and then |
| 11331 | // read the body. |
| 11332 | rv = callback_compete.WaitForResult(); |
| 11333 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11334 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11335 | if (rv == ERR_IO_PENDING) |
| 11336 | rv = callback.WaitForResult(); |
| 11337 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11338 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11339 | EXPECT_EQ(0, rv); |
| 11340 | |
| 11341 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11342 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11343 | } |
| 11344 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11345 | // This tests the case that a request is issued via http instead of spdy after |
| 11346 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11347 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11348 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11349 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 11350 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11351 | session_deps_.next_protos = next_protos; |
| 11352 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11353 | HttpRequestInfo request; |
| 11354 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11355 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11356 | request.load_flags = 0; |
| 11357 | |
| 11358 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11359 | MockWrite( |
| 11360 | "GET / HTTP/1.1\r\n" |
| 11361 | "Host: www.example.org\r\n" |
| 11362 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11363 | }; |
| 11364 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11365 | std::string alternate_protocol_http_header = |
| 11366 | GetAlternateProtocolHttpHeader(); |
| 11367 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11368 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11369 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11370 | MockRead(alternate_protocol_http_header.c_str()), |
| 11371 | MockRead("\r\n"), |
| 11372 | MockRead("hello world"), |
| 11373 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11374 | }; |
| 11375 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11376 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11377 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11378 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11380 | |
| 11381 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11382 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11383 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11385 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11386 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11387 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11388 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11389 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11391 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11392 | |
| 11393 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11394 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11395 | |
| 11396 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11397 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11398 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11399 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11400 | |
| 11401 | std::string response_data; |
| 11402 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11403 | EXPECT_EQ("hello world", response_data); |
| 11404 | |
| 11405 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11406 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11407 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11408 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11409 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11410 | // immediate server closing of the socket. |
| 11411 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11412 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11413 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11414 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11415 | |
| 11416 | HttpRequestInfo request; |
| 11417 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11418 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11419 | request.load_flags = 0; |
| 11420 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11421 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11422 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11424 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11425 | scoped_ptr<SpdyFrame> req( |
| 11426 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11427 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11428 | |
| 11429 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11430 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11431 | }; |
| 11432 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11433 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11434 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11435 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11437 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11438 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11439 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11440 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11445 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11446 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11447 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11448 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11449 | // it gets it. This is needed since the auth handler may get destroyed |
| 11450 | // before we get a chance to query it. |
| 11451 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11452 | public: |
| 11453 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11454 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11455 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11456 | |
| 11457 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11458 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11459 | const HttpRequestInfo* request, |
| 11460 | const CompletionCallback& callback, |
| 11461 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11462 | *url_ = request->url; |
| 11463 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11464 | credentials, request, callback, auth_token); |
| 11465 | } |
| 11466 | |
| 11467 | private: |
| 11468 | GURL* url_; |
| 11469 | }; |
| 11470 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11471 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11472 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11473 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11474 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11475 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11476 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11477 | session_deps_.proxy_service = |
| 11478 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11479 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11480 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11481 | GURL request_url; |
| 11482 | { |
| 11483 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11484 | new HttpAuthHandlerMock::Factory(); |
| 11485 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11486 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11487 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11488 | auth_factory->set_do_init_from_challenge(true); |
| 11489 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11490 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11491 | |
| 11492 | HttpRequestInfo request; |
| 11493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11494 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11495 | request.load_flags = 0; |
| 11496 | |
| 11497 | // First round goes unauthenticated through the proxy. |
| 11498 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11499 | MockWrite( |
| 11500 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11501 | "Host: www.example.org\r\n" |
| 11502 | "Proxy-Connection: keep-alive\r\n" |
| 11503 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11504 | }; |
| 11505 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11506 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11507 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11508 | MockRead("Alternate-Protocol: 443:"), |
| 11509 | MockRead(GetAlternateProtocolFromParam()), |
| 11510 | MockRead("\r\n"), |
| 11511 | MockRead("Proxy-Connection: close\r\n"), |
| 11512 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11513 | }; |
| 11514 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11515 | data_writes_1, arraysize(data_writes_1)); |
| 11516 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11517 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11518 | // Alternate-Protocol announcement in the first round. It fails due |
| 11519 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11520 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11521 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11522 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11523 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11524 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11525 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11526 | // to obtain a new one. |
| 11527 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11528 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 11529 | // simply returned another 407 so the unit test could skip the SSL connection |
| 11530 | // establishment and SPDY framing issues. Alas, the |
| 11531 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11532 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11533 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11534 | scoped_ptr<SpdyFrame> req( |
| 11535 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11536 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11537 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11538 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11539 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11540 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11541 | MockWrite(ASYNC, 0, |
| 11542 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11543 | "Host: www.example.org\r\n" |
| 11544 | "Proxy-Connection: keep-alive\r\n" |
| 11545 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11546 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11547 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11548 | MockWrite(ASYNC, 2, |
| 11549 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11550 | "Host: www.example.org\r\n" |
| 11551 | "Proxy-Connection: keep-alive\r\n" |
| 11552 | "Proxy-Authorization: auth_token\r\n" |
| 11553 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11554 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11555 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11556 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11557 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11558 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11559 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11560 | MockRead(ASYNC, 1, |
| 11561 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11562 | "Proxy-Authenticate: Mock\r\n" |
| 11563 | "Content-Length: 0\r\n" |
| 11564 | "Proxy-Connection: keep-alive\r\n" |
| 11565 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11566 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11567 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11568 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11569 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11570 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11571 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11572 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11573 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11574 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11575 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11576 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11577 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11578 | ssl.SetNextProto(GetParam()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11579 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11580 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11581 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11582 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11583 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11584 | NULL, 0, NULL, 0); |
| 11585 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11586 | never_finishing_connect); |
| 11587 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11588 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11589 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11591 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11592 | &hanging_non_alternate_protocol_socket); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11593 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11594 | |
| 11595 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11596 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11597 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11598 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11599 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11601 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11602 | |
| 11603 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11604 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11605 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11606 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11607 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11609 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11610 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11611 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11612 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11613 | |
| 11614 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11615 | TestCompletionCallback callback_3; |
| 11616 | rv = trans_2->RestartWithAuth( |
| 11617 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11618 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11619 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11620 | |
| 11621 | // After all that work, these two lines (or actually, just the scheme) are |
| 11622 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11623 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11624 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11625 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11626 | LoadTimingInfo load_timing_info; |
| 11627 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11628 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11629 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11630 | } |
| 11631 | |
| 11632 | // Test that if we cancel the transaction as the connection is completing, that |
| 11633 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11634 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11635 | // Setup everything about the connection to complete synchronously, so that |
| 11636 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11637 | // for is the callback from the HttpStreamRequest. |
| 11638 | // Then cancel the transaction. |
| 11639 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11640 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11641 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11642 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11643 | MockRead(SYNCHRONOUS, "hello world"), |
| 11644 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11645 | }; |
| 11646 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11647 | HttpRequestInfo request; |
| 11648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11649 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11650 | request.load_flags = 0; |
| 11651 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11652 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11653 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11654 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11655 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11656 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11657 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11658 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11659 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11661 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11662 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11663 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11664 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11666 | trans.reset(); // Cancel the transaction here. |
| 11667 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11668 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11669 | } |
| 11670 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11671 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11672 | // stream is drained properly and added back to the socket pool. The main |
| 11673 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11674 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11675 | // deleted. |
| 11676 | // See http://crbug.com/368418 |
| 11677 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11678 | MockRead data_reads[] = { |
| 11679 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11680 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11681 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11682 | MockRead(ASYNC, "1"), |
| 11683 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11684 | // HttpNetworkTransaction has been deleted. |
| 11685 | MockRead(ASYNC, "2"), |
| 11686 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11687 | }; |
| 11688 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11690 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11691 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11692 | |
| 11693 | { |
| 11694 | HttpRequestInfo request; |
| 11695 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11696 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11697 | request.load_flags = 0; |
| 11698 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11699 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11700 | TestCompletionCallback callback; |
| 11701 | |
| 11702 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11704 | callback.WaitForResult(); |
| 11705 | |
| 11706 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11707 | ASSERT_TRUE(response != NULL); |
| 11708 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11709 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11710 | |
| 11711 | // The transaction and HttpRequestInfo are deleted. |
| 11712 | } |
| 11713 | |
| 11714 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11715 | base::MessageLoop::current()->RunUntilIdle(); |
| 11716 | |
| 11717 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11718 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11719 | } |
| 11720 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11721 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11722 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11723 | session_deps_.proxy_service = |
| 11724 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11725 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11726 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11727 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11728 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11729 | HttpRequestInfo request; |
| 11730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11731 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11732 | |
| 11733 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11734 | MockWrite( |
| 11735 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11736 | "Host: www.example.org\r\n" |
| 11737 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11738 | }; |
| 11739 | |
| 11740 | MockRead data_reads1[] = { |
| 11741 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11742 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11743 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11744 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11745 | }; |
| 11746 | |
| 11747 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11748 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11751 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11752 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11753 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11754 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11755 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11756 | trans->SetBeforeProxyHeadersSentCallback( |
| 11757 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11758 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11760 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11762 | |
| 11763 | rv = callback1.WaitForResult(); |
| 11764 | EXPECT_EQ(OK, rv); |
| 11765 | |
| 11766 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11767 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11768 | |
| 11769 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11770 | EXPECT_EQ(200, response->headers->response_code()); |
| 11771 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11772 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11773 | EXPECT_TRUE( |
| 11774 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11775 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11776 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11777 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11778 | |
| 11779 | LoadTimingInfo load_timing_info; |
| 11780 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11781 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11782 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11783 | } |
| 11784 | |
| 11785 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11786 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11787 | session_deps_.proxy_service = |
| 11788 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11789 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11790 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11791 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11792 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11793 | HttpRequestInfo request; |
| 11794 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11795 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11796 | |
| 11797 | // Since we have proxy, should try to establish tunnel. |
| 11798 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11799 | MockWrite( |
| 11800 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11801 | "Host: www.example.org\r\n" |
| 11802 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11803 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11804 | MockWrite( |
| 11805 | "GET / HTTP/1.1\r\n" |
| 11806 | "Host: www.example.org\r\n" |
| 11807 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11808 | }; |
| 11809 | |
| 11810 | MockRead data_reads1[] = { |
| 11811 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11812 | |
| 11813 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11814 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11815 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11816 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11817 | }; |
| 11818 | |
| 11819 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11820 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11821 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11822 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11823 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11825 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11826 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11827 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11828 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11830 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11832 | |
| 11833 | rv = callback1.WaitForResult(); |
| 11834 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11835 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11836 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11837 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11838 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11839 | NetLog::PHASE_NONE); |
| 11840 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11841 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11842 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11843 | NetLog::PHASE_NONE); |
| 11844 | |
| 11845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11846 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11847 | |
| 11848 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11849 | EXPECT_EQ(200, response->headers->response_code()); |
| 11850 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11851 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11852 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11853 | EXPECT_TRUE( |
| 11854 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11855 | |
| 11856 | LoadTimingInfo load_timing_info; |
| 11857 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11858 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11859 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11860 | } |
| 11861 | |
| 11862 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 11863 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11864 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11865 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11866 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11867 | session_deps_.net_log = log.bound().net_log(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11868 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11869 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11870 | HttpRequestInfo request; |
| 11871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11872 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11873 | |
| 11874 | // Since we have proxy, should try to establish tunnel. |
| 11875 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11876 | MockWrite( |
| 11877 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11878 | "Host: www.example.org\r\n" |
| 11879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11880 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11881 | MockWrite( |
| 11882 | "GET / HTTP/1.1\r\n" |
| 11883 | "Host: www.example.org\r\n" |
| 11884 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11885 | }; |
| 11886 | |
| 11887 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11888 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11889 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11890 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11891 | }; |
| 11892 | |
| 11893 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11894 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11896 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11899 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11900 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11901 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11902 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11904 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11906 | |
| 11907 | rv = callback1.WaitForResult(); |
| 11908 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11909 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11910 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11911 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11912 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11913 | NetLog::PHASE_NONE); |
| 11914 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11915 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11916 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11917 | NetLog::PHASE_NONE); |
| 11918 | } |
| 11919 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11920 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11921 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11922 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11923 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11924 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11925 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11926 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11927 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11928 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11929 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11930 | }; |
| 11931 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11932 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11933 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11934 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11935 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11936 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11937 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11938 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11939 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11940 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11941 | |
| 11942 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11943 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11944 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11945 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11946 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11947 | CreateInsecureSpdySession(session, key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11948 | |
| 11949 | HttpRequestInfo request; |
| 11950 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11951 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11952 | request.load_flags = 0; |
| 11953 | |
| 11954 | // This is the important line that marks this as a preconnect. |
| 11955 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 11956 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11957 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11958 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11959 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 11960 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11961 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11962 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11963 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 11964 | } |
| 11965 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11966 | // Given a net error, cause that error to be returned from the first Write() |
| 11967 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11968 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11969 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11970 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11971 | request_info.url = GURL("https://www.example.com/"); |
| 11972 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11973 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11974 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11975 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11976 | MockWrite data_writes[] = { |
| 11977 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11978 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11979 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11982 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 11983 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11984 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11987 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 11988 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 11989 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11990 | rv = callback.WaitForResult(); |
| 11991 | ASSERT_EQ(error, rv); |
| 11992 | } |
| 11993 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11994 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 11995 | // Just check a grab bag of cert errors. |
| 11996 | static const int kErrors[] = { |
| 11997 | ERR_CERT_COMMON_NAME_INVALID, |
| 11998 | ERR_CERT_AUTHORITY_INVALID, |
| 11999 | ERR_CERT_DATE_INVALID, |
| 12000 | }; |
| 12001 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12002 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12003 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12004 | } |
| 12005 | } |
| 12006 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12007 | // Ensure that a client certificate is removed from the SSL client auth |
| 12008 | // cache when: |
| 12009 | // 1) No proxy is involved. |
| 12010 | // 2) TLS False Start is disabled. |
| 12011 | // 3) The initial TLS handshake requests a client certificate. |
| 12012 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12013 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12014 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12015 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12016 | request_info.url = GURL("https://www.example.com/"); |
| 12017 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12018 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12019 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12020 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12021 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12022 | |
| 12023 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12024 | // CertificateRequest is received for the first time, the handshake will |
| 12025 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12026 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12027 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12028 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12029 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12030 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12031 | |
| 12032 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12033 | // False Start is not being used, the result of the SSL handshake will be |
| 12034 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12035 | // matches the result of a server sending a handshake_failure alert, |
| 12036 | // rather than a Finished message, because it requires a client |
| 12037 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12038 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12039 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12041 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12042 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12043 | |
| 12044 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12045 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12046 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12047 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12048 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12049 | // requiring a client certificate, this fallback handshake should also |
| 12050 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12051 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12052 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12054 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12055 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12056 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12057 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12058 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12059 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12060 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12061 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12062 | // requiring a client certificate, this fallback handshake should also |
| 12063 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12064 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12065 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12066 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12067 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12068 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12069 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12070 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12071 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12073 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12074 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12075 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12076 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12077 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12078 | |
| 12079 | // Complete the SSL handshake, which should abort due to requiring a |
| 12080 | // client certificate. |
| 12081 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12082 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12083 | |
| 12084 | // Indicate that no certificate should be supplied. From the perspective |
| 12085 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12086 | // certificate, so this is the same as supply a |
| 12087 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12088 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12089 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12090 | |
| 12091 | // Ensure the certificate was added to the client auth cache before |
| 12092 | // allowing the connection to continue restarting. |
| 12093 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12094 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 12095 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12096 | ASSERT_EQ(NULL, client_cert.get()); |
| 12097 | |
| 12098 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12099 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12100 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12101 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12102 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12103 | |
| 12104 | // Ensure that the client certificate is removed from the cache on a |
| 12105 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12106 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12107 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12108 | } |
| 12109 | |
| 12110 | // Ensure that a client certificate is removed from the SSL client auth |
| 12111 | // cache when: |
| 12112 | // 1) No proxy is involved. |
| 12113 | // 2) TLS False Start is enabled. |
| 12114 | // 3) The initial TLS handshake requests a client certificate. |
| 12115 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12116 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12117 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12118 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12119 | request_info.url = GURL("https://www.example.com/"); |
| 12120 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12121 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12122 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12123 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12124 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12125 | |
| 12126 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12127 | // return successfully after reading up to the peer's Certificate message. |
| 12128 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12129 | // enqueue application data to be sent in the same packet as the |
| 12130 | // ChangeCipherSpec and Finished messages. |
| 12131 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12132 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12133 | // Finished messages. If there was an error negotiating with the peer, |
| 12134 | // such as due to the peer requiring a client certificate when none was |
| 12135 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12136 | // called. |
| 12137 | |
| 12138 | // Like the non-False Start case, when a client certificate is requested by |
| 12139 | // the peer, the handshake is aborted during the Connect() call. |
| 12140 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12141 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12142 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12144 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12145 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12146 | |
| 12147 | // When a client certificate is supplied, Connect() will not be aborted |
| 12148 | // when the peer requests the certificate. Instead, the handshake will |
| 12149 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12150 | // the socket. The handshake messages are not processed until Read() is |
| 12151 | // called, which then detects that the handshake was aborted, due to the |
| 12152 | // peer sending a handshake_failure because it requires a client |
| 12153 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12154 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12155 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12156 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12157 | MockRead data2_reads[] = { |
| 12158 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12159 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12160 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12161 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12162 | |
| 12163 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12164 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12165 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12166 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12167 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12169 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12170 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12171 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12172 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12173 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12174 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12175 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12177 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12178 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12179 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12180 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12181 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12182 | ssl_data5.cert_request_info = cert_request.get(); |
| 12183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12184 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12185 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12186 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12187 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12188 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12189 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12190 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12191 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12192 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12193 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12194 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12195 | |
| 12196 | // Complete the SSL handshake, which should abort due to requiring a |
| 12197 | // client certificate. |
| 12198 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12199 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12200 | |
| 12201 | // Indicate that no certificate should be supplied. From the perspective |
| 12202 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12203 | // certificate, so this is the same as supply a |
| 12204 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12205 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12206 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12207 | |
| 12208 | // Ensure the certificate was added to the client auth cache before |
| 12209 | // allowing the connection to continue restarting. |
| 12210 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12211 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 12212 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12213 | ASSERT_EQ(NULL, client_cert.get()); |
| 12214 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12215 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12216 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12217 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12218 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12219 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12220 | |
| 12221 | // Ensure that the client certificate is removed from the cache on a |
| 12222 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12223 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12224 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12225 | } |
| 12226 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12227 | // Ensure that a client certificate is removed from the SSL client auth |
| 12228 | // cache when: |
| 12229 | // 1) An HTTPS proxy is involved. |
| 12230 | // 3) The HTTPS proxy requests a client certificate. |
| 12231 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12232 | // proxy. |
| 12233 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12234 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12235 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12236 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12237 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12238 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12239 | |
| 12240 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12241 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12242 | |
| 12243 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12244 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12245 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12246 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12247 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12248 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12250 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12252 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12253 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12254 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12255 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12256 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12257 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12258 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12259 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12260 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12261 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12262 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12264 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12265 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12266 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12267 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12268 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12269 | requests[0].url = GURL("https://www.example.com/"); |
| 12270 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12271 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12272 | |
| 12273 | requests[1].url = GURL("http://www.example.com/"); |
| 12274 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12275 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12276 | |
| 12277 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12278 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12279 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12280 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12282 | |
| 12283 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12284 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12285 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12286 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12287 | |
| 12288 | // Complete the SSL handshake, which should abort due to requiring a |
| 12289 | // client certificate. |
| 12290 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12291 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12292 | |
| 12293 | // Indicate that no certificate should be supplied. From the perspective |
| 12294 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12295 | // certificate, so this is the same as supply a |
| 12296 | // legitimate-but-unacceptable certificate. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12297 | rv = trans->RestartWithCertificate(NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12298 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12299 | |
| 12300 | // Ensure the certificate was added to the client auth cache before |
| 12301 | // allowing the connection to continue restarting. |
| 12302 | scoped_refptr<X509Certificate> client_cert; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12303 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 12304 | HostPortPair("proxy", 70), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12305 | ASSERT_EQ(NULL, client_cert.get()); |
| 12306 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12307 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12308 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12309 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12310 | |
| 12311 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12312 | // then consume ssl_data3, which should also fail. The result code is |
| 12313 | // checked against what ssl_data3 should return. |
| 12314 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12315 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12316 | |
| 12317 | // Now that the new handshake has failed, ensure that the client |
| 12318 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12319 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12320 | HostPortPair("proxy", 70), &client_cert)); |
| 12321 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 12322 | HostPortPair("www.example.com", 443), &client_cert)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12323 | } |
| 12324 | } |
| 12325 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12326 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12327 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12328 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12329 | |
| 12330 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12331 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12332 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12333 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12334 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12335 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12336 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12337 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12339 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12340 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12341 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12342 | scoped_ptr<SpdyFrame> host2_req( |
| 12343 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12344 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12345 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12346 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12347 | scoped_ptr<SpdyFrame> host1_resp( |
| 12348 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12349 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12350 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12351 | scoped_ptr<SpdyFrame> host2_resp( |
| 12352 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12353 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12354 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12355 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12356 | CreateMockRead(*host1_resp, 1), |
| 12357 | CreateMockRead(*host1_resp_body, 2), |
| 12358 | CreateMockRead(*host2_resp, 4), |
| 12359 | CreateMockRead(*host2_resp_body, 5), |
| 12360 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12361 | }; |
| 12362 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12363 | IPAddressNumber ip; |
| 12364 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12365 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12366 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12367 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12368 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12369 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12370 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12371 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12372 | HttpRequestInfo request1; |
| 12373 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12374 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12375 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12376 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12378 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12379 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12380 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12381 | |
| 12382 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12383 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12384 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12385 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12386 | |
| 12387 | std::string response_data; |
| 12388 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12389 | EXPECT_EQ("hello!", response_data); |
| 12390 | |
| 12391 | // Preload www.gmail.com into HostCache. |
| 12392 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12393 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12394 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12395 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12396 | DEFAULT_PRIORITY, |
| 12397 | &ignored, |
| 12398 | callback.callback(), |
| 12399 | NULL, |
| 12400 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12401 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12402 | rv = callback.WaitForResult(); |
| 12403 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12404 | |
| 12405 | HttpRequestInfo request2; |
| 12406 | request2.method = "GET"; |
| 12407 | request2.url = GURL("https://www.gmail.com/"); |
| 12408 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12409 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12410 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12411 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12412 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12413 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12414 | |
| 12415 | response = trans2.GetResponseInfo(); |
| 12416 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12417 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12418 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12419 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12420 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12421 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12422 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12423 | } |
| 12424 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12425 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12426 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12427 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12428 | |
| 12429 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12430 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12431 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12432 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12433 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12434 | |
| 12435 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12436 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12438 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12439 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12440 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12441 | scoped_ptr<SpdyFrame> host2_req( |
| 12442 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12443 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12444 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12445 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12446 | scoped_ptr<SpdyFrame> host1_resp( |
| 12447 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12448 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12449 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12450 | scoped_ptr<SpdyFrame> host2_resp( |
| 12451 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12452 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12453 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12454 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12455 | CreateMockRead(*host1_resp, 1), |
| 12456 | CreateMockRead(*host1_resp_body, 2), |
| 12457 | CreateMockRead(*host2_resp, 4), |
| 12458 | CreateMockRead(*host2_resp_body, 5), |
| 12459 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12460 | }; |
| 12461 | |
| 12462 | IPAddressNumber ip; |
| 12463 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12464 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12465 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12466 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12467 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12468 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12469 | |
| 12470 | TestCompletionCallback callback; |
| 12471 | HttpRequestInfo request1; |
| 12472 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12473 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12474 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12475 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12476 | |
| 12477 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 12478 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12479 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12480 | |
| 12481 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12482 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12483 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12484 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12485 | |
| 12486 | std::string response_data; |
| 12487 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12488 | EXPECT_EQ("hello!", response_data); |
| 12489 | |
| 12490 | HttpRequestInfo request2; |
| 12491 | request2.method = "GET"; |
| 12492 | request2.url = GURL("https://www.gmail.com/"); |
| 12493 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12494 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12495 | |
| 12496 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 12497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12498 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12499 | |
| 12500 | response = trans2.GetResponseInfo(); |
| 12501 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12502 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12503 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12504 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12505 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12506 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12507 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12508 | } |
| 12509 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12510 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12511 | public: |
| 12512 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12513 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12514 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12515 | |
| 12516 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12517 | |
| 12518 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12519 | int Resolve(const RequestInfo& info, |
| 12520 | RequestPriority priority, |
| 12521 | AddressList* addresses, |
| 12522 | const CompletionCallback& callback, |
| 12523 | RequestHandle* out_req, |
| 12524 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12525 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12526 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12527 | } |
| 12528 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12529 | int ResolveFromCache(const RequestInfo& info, |
| 12530 | AddressList* addresses, |
| 12531 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12532 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12533 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12534 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12535 | return rv; |
| 12536 | } |
| 12537 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12538 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12539 | host_resolver_.CancelRequest(req); |
| 12540 | } |
| 12541 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12542 | MockCachingHostResolver* GetMockHostResolver() { |
| 12543 | return &host_resolver_; |
| 12544 | } |
| 12545 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12546 | private: |
| 12547 | MockCachingHostResolver host_resolver_; |
| 12548 | const HostPortPair host_port_; |
| 12549 | }; |
| 12550 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12551 | TEST_P(HttpNetworkTransactionTest, |
| 12552 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12553 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12554 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12555 | |
| 12556 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12557 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12558 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12559 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12560 | params.host_resolver = &host_resolver; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12561 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12562 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12563 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12564 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12565 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12566 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12568 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12569 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12570 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12571 | scoped_ptr<SpdyFrame> host2_req( |
| 12572 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12573 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12574 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12575 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12576 | scoped_ptr<SpdyFrame> host1_resp( |
| 12577 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12578 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12579 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12580 | scoped_ptr<SpdyFrame> host2_resp( |
| 12581 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12582 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12583 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12584 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12585 | CreateMockRead(*host1_resp, 1), |
| 12586 | CreateMockRead(*host1_resp_body, 2), |
| 12587 | CreateMockRead(*host2_resp, 4), |
| 12588 | CreateMockRead(*host2_resp_body, 5), |
| 12589 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12590 | }; |
| 12591 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12592 | IPAddressNumber ip; |
| 12593 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12594 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12595 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12596 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12597 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12598 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12599 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12600 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12601 | HttpRequestInfo request1; |
| 12602 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12603 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12604 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12605 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12607 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12609 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12610 | |
| 12611 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12612 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12613 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12614 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12615 | |
| 12616 | std::string response_data; |
| 12617 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12618 | EXPECT_EQ("hello!", response_data); |
| 12619 | |
| 12620 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12621 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12622 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12623 | rv = host_resolver.Resolve(resolve_info, |
| 12624 | DEFAULT_PRIORITY, |
| 12625 | &ignored, |
| 12626 | callback.callback(), |
| 12627 | NULL, |
| 12628 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12629 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12630 | rv = callback.WaitForResult(); |
| 12631 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12632 | |
| 12633 | HttpRequestInfo request2; |
| 12634 | request2.method = "GET"; |
| 12635 | request2.url = GURL("https://www.gmail.com/"); |
| 12636 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12637 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12639 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12641 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12642 | |
| 12643 | response = trans2.GetResponseInfo(); |
| 12644 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12645 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12646 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12647 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12648 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12649 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12650 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12651 | } |
| 12652 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12653 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12654 | const std::string https_url = "https://www.example.org:8080/"; |
| 12655 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12656 | |
| 12657 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12658 | scoped_ptr<SpdyFrame> req1( |
| 12659 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12660 | |
| 12661 | MockWrite writes1[] = { |
| 12662 | CreateMockWrite(*req1, 0), |
| 12663 | }; |
| 12664 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12665 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12666 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12667 | MockRead reads1[] = { |
| 12668 | CreateMockRead(*resp1, 1), |
| 12669 | CreateMockRead(*body1, 2), |
| 12670 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12671 | }; |
| 12672 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12673 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12674 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12675 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12676 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12677 | |
| 12678 | // HTTP GET for the HTTP URL |
| 12679 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12680 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12681 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12682 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12683 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12684 | }; |
| 12685 | |
| 12686 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12687 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12688 | MockRead(ASYNC, 2, "hello"), |
| 12689 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12690 | }; |
| 12691 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12692 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12693 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12694 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12695 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12696 | ssl.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12697 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12699 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12700 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12701 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12702 | |
| 12703 | // Start the first transaction to set up the SpdySession |
| 12704 | HttpRequestInfo request1; |
| 12705 | request1.method = "GET"; |
| 12706 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12707 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12708 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12709 | TestCompletionCallback callback1; |
| 12710 | EXPECT_EQ(ERR_IO_PENDING, |
| 12711 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12712 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12713 | |
| 12714 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12715 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12716 | |
| 12717 | // Now, start the HTTP request |
| 12718 | HttpRequestInfo request2; |
| 12719 | request2.method = "GET"; |
| 12720 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12721 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12722 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12723 | TestCompletionCallback callback2; |
| 12724 | EXPECT_EQ(ERR_IO_PENDING, |
| 12725 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12726 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12727 | |
| 12728 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12729 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12730 | } |
| 12731 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12732 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12733 | public: |
| 12734 | void Run(bool pooling, bool valid) { |
| 12735 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12736 | 443); |
| 12737 | HostPortPair alternative("www.example.org", 443); |
| 12738 | |
| 12739 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12740 | scoped_refptr<X509Certificate> cert( |
| 12741 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12742 | ASSERT_TRUE(cert.get()); |
| 12743 | bool common_name_fallback_used; |
| 12744 | EXPECT_EQ(valid, |
| 12745 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12746 | EXPECT_TRUE( |
| 12747 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12748 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12749 | ssl.SetNextProto(GetParam()); |
| 12750 | ssl.cert = cert; |
| 12751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12752 | |
| 12753 | // If pooling, then start a request to alternative first to create a |
| 12754 | // SpdySession. |
| 12755 | std::string url0 = "https://www.example.org:443"; |
| 12756 | // Second request to origin, which has an alternative service, and could |
| 12757 | // open a connection to the alternative host or pool to the existing one. |
| 12758 | std::string url1("https://"); |
| 12759 | url1.append(origin.host()); |
| 12760 | url1.append(":443"); |
| 12761 | |
| 12762 | scoped_ptr<SpdyFrame> req0; |
| 12763 | scoped_ptr<SpdyFrame> req1; |
| 12764 | scoped_ptr<SpdyFrame> resp0; |
| 12765 | scoped_ptr<SpdyFrame> body0; |
| 12766 | scoped_ptr<SpdyFrame> resp1; |
| 12767 | scoped_ptr<SpdyFrame> body1; |
| 12768 | std::vector<MockWrite> writes; |
| 12769 | std::vector<MockRead> reads; |
| 12770 | |
| 12771 | if (pooling) { |
| 12772 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
| 12773 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12774 | |
| 12775 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12776 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12777 | |
| 12778 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12779 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12780 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12781 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12782 | |
| 12783 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12784 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12785 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12786 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12787 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12788 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12789 | } else { |
| 12790 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12791 | |
| 12792 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12793 | |
| 12794 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12795 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12796 | |
| 12797 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12798 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12799 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12800 | } |
| 12801 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12802 | SequencedSocketData data(vector_as_array(&reads), reads.size(), |
| 12803 | vector_as_array(&writes), writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12804 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12805 | |
| 12806 | // Connection to the origin fails. |
| 12807 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12808 | StaticSocketDataProvider data_refused; |
| 12809 | data_refused.set_connect_data(mock_connect); |
| 12810 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12811 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12812 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12813 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12814 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12815 | session->http_server_properties(); |
| 12816 | AlternativeService alternative_service( |
| 12817 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12818 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12819 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12820 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12821 | |
| 12822 | // First request to alternative. |
| 12823 | if (pooling) { |
| 12824 | scoped_ptr<HttpTransaction> trans0( |
| 12825 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12826 | HttpRequestInfo request0; |
| 12827 | request0.method = "GET"; |
| 12828 | request0.url = GURL(url0); |
| 12829 | request0.load_flags = 0; |
| 12830 | TestCompletionCallback callback0; |
| 12831 | |
| 12832 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12833 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12834 | rv = callback0.WaitForResult(); |
| 12835 | EXPECT_EQ(OK, rv); |
| 12836 | } |
| 12837 | |
| 12838 | // Second request to origin. |
| 12839 | scoped_ptr<HttpTransaction> trans1( |
| 12840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12841 | HttpRequestInfo request1; |
| 12842 | request1.method = "GET"; |
| 12843 | request1.url = GURL(url1); |
| 12844 | request1.load_flags = 0; |
| 12845 | TestCompletionCallback callback1; |
| 12846 | |
| 12847 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12848 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12849 | base::MessageLoop::current()->RunUntilIdle(); |
| 12850 | if (data.IsReadPaused()) { |
| 12851 | data.CompleteRead(); |
| 12852 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12853 | rv = callback1.WaitForResult(); |
| 12854 | if (valid) { |
| 12855 | EXPECT_EQ(OK, rv); |
| 12856 | } else { |
| 12857 | if (pooling) { |
| 12858 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 12859 | } else { |
| 12860 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 12861 | } |
| 12862 | } |
| 12863 | } |
| 12864 | }; |
| 12865 | |
| 12866 | INSTANTIATE_TEST_CASE_P(NextProto, |
| 12867 | AltSvcCertificateVerificationTest, |
| 12868 | testing::Values(kProtoSPDY31, |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 12869 | kProtoHTTP2)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12870 | |
| 12871 | // The alternative service host must exhibit a certificate that is valid for the |
| 12872 | // origin host. Test that this is enforced when pooling to an existing |
| 12873 | // connection. |
| 12874 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 12875 | Run(true, true); |
| 12876 | } |
| 12877 | |
| 12878 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 12879 | Run(true, false); |
| 12880 | } |
| 12881 | |
| 12882 | // The alternative service host must exhibit a certificate that is valid for the |
| 12883 | // origin host. Test that this is enforced when opening a new connection. |
| 12884 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 12885 | Run(false, true); |
| 12886 | } |
| 12887 | |
| 12888 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 12889 | Run(false, false); |
| 12890 | } |
| 12891 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12892 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 12893 | // with the alternative server. That connection should not be used. |
| 12894 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 12895 | HostPortPair origin("origin.example.org", 443); |
| 12896 | HostPortPair alternative("alternative.example.org", 443); |
| 12897 | |
| 12898 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12899 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12900 | ssl.SetNextProto(kProtoHTTP11); |
| 12901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12902 | |
| 12903 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12904 | // negotiated. |
| 12905 | StaticSocketDataProvider data; |
| 12906 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12907 | |
| 12908 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 12909 | // negotiated. In order to test this, a failed connection to the origin is |
| 12910 | // mocked. This way the request relies on the alternate Job. |
| 12911 | StaticSocketDataProvider data_refused; |
| 12912 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12913 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12914 | |
| 12915 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12916 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12917 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12918 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12919 | session->http_server_properties(); |
| 12920 | AlternativeService alternative_service( |
| 12921 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12922 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12923 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12924 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 12925 | |
| 12926 | scoped_ptr<HttpTransaction> trans( |
| 12927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12928 | HttpRequestInfo request; |
| 12929 | request.method = "GET"; |
| 12930 | request.url = GURL("https://origin.example.org:443"); |
| 12931 | request.load_flags = 0; |
| 12932 | TestCompletionCallback callback; |
| 12933 | |
| 12934 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 12935 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 12936 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 12937 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 12938 | } |
| 12939 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12940 | // A request to a server with an alternative service fires two Jobs: one to the |
| 12941 | // origin, and an alternate one to the alternative server. If the former |
| 12942 | // succeeds, the request should succeed, even if the latter fails because |
| 12943 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 12944 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 12945 | HostPortPair origin("origin.example.org", 443); |
| 12946 | HostPortPair alternative("alternative.example.org", 443); |
| 12947 | |
| 12948 | // Negotiate HTTP/1.1 with alternative. |
| 12949 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 12950 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 12951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 12952 | |
| 12953 | // No data should be read from the alternative, because HTTP/1.1 is |
| 12954 | // negotiated. |
| 12955 | StaticSocketDataProvider data; |
| 12956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12957 | |
| 12958 | // Negotiate HTTP/1.1 with origin. |
| 12959 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 12960 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 12961 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 12962 | |
| 12963 | MockWrite http_writes[] = { |
| 12964 | MockWrite( |
| 12965 | "GET / HTTP/1.1\r\n" |
| 12966 | "Host: origin.example.org\r\n" |
| 12967 | "Connection: keep-alive\r\n\r\n"), |
| 12968 | MockWrite( |
| 12969 | "GET /second HTTP/1.1\r\n" |
| 12970 | "Host: origin.example.org\r\n" |
| 12971 | "Connection: keep-alive\r\n\r\n"), |
| 12972 | }; |
| 12973 | |
| 12974 | MockRead http_reads[] = { |
| 12975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12976 | MockRead("Content-Type: text/html\r\n"), |
| 12977 | MockRead("Content-Length: 6\r\n\r\n"), |
| 12978 | MockRead("foobar"), |
| 12979 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12980 | MockRead("Content-Type: text/html\r\n"), |
| 12981 | MockRead("Content-Length: 7\r\n\r\n"), |
| 12982 | MockRead("another"), |
| 12983 | }; |
| 12984 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 12985 | http_writes, arraysize(http_writes)); |
| 12986 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12987 | |
| 12988 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12989 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 12990 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12991 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12992 | session->http_server_properties(); |
| 12993 | AlternativeService alternative_service( |
| 12994 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12995 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12996 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12997 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 12998 | |
| 12999 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13000 | HttpRequestInfo request1; |
| 13001 | request1.method = "GET"; |
| 13002 | request1.url = GURL("https://origin.example.org:443"); |
| 13003 | request1.load_flags = 0; |
| 13004 | TestCompletionCallback callback1; |
| 13005 | |
| 13006 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13007 | rv = callback1.GetResult(rv); |
| 13008 | EXPECT_EQ(OK, rv); |
| 13009 | |
| 13010 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13011 | ASSERT_TRUE(response1 != nullptr); |
| 13012 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13013 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13014 | |
| 13015 | std::string response_data1; |
| 13016 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13017 | EXPECT_EQ("foobar", response_data1); |
| 13018 | |
| 13019 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13020 | // for alternative service. |
| 13021 | EXPECT_TRUE( |
| 13022 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13023 | |
| 13024 | // Since |alternative_service| is broken, a second transaction to origin |
| 13025 | // should not start an alternate Job. It should pool to existing connection |
| 13026 | // to origin. |
| 13027 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13028 | HttpRequestInfo request2; |
| 13029 | request2.method = "GET"; |
| 13030 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13031 | request2.load_flags = 0; |
| 13032 | TestCompletionCallback callback2; |
| 13033 | |
| 13034 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13035 | rv = callback2.GetResult(rv); |
| 13036 | EXPECT_EQ(OK, rv); |
| 13037 | |
| 13038 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13039 | ASSERT_TRUE(response2 != nullptr); |
| 13040 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13041 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13042 | |
| 13043 | std::string response_data2; |
| 13044 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13045 | EXPECT_EQ("another", response_data2); |
| 13046 | } |
| 13047 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13048 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13049 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13050 | // used. |
| 13051 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13052 | HostPortPair origin("origin.example.org", 443); |
| 13053 | HostPortPair alternative("alternative.example.org", 443); |
| 13054 | std::string origin_url = "https://origin.example.org:443"; |
| 13055 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13056 | |
| 13057 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13058 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13059 | ssl.SetNextProto(kProtoHTTP11); |
| 13060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13061 | |
| 13062 | // HTTP/1.1 data for |request1| and |request2|. |
| 13063 | MockWrite http_writes[] = { |
| 13064 | MockWrite( |
| 13065 | "GET / HTTP/1.1\r\n" |
| 13066 | "Host: alternative.example.org\r\n" |
| 13067 | "Connection: keep-alive\r\n\r\n"), |
| 13068 | MockWrite( |
| 13069 | "GET / HTTP/1.1\r\n" |
| 13070 | "Host: alternative.example.org\r\n" |
| 13071 | "Connection: keep-alive\r\n\r\n"), |
| 13072 | }; |
| 13073 | |
| 13074 | MockRead http_reads[] = { |
| 13075 | MockRead( |
| 13076 | "HTTP/1.1 200 OK\r\n" |
| 13077 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13078 | "Content-Length: 40\r\n\r\n" |
| 13079 | "first HTTP/1.1 response from alternative"), |
| 13080 | MockRead( |
| 13081 | "HTTP/1.1 200 OK\r\n" |
| 13082 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13083 | "Content-Length: 41\r\n\r\n" |
| 13084 | "second HTTP/1.1 response from alternative"), |
| 13085 | }; |
| 13086 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13087 | http_writes, arraysize(http_writes)); |
| 13088 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13089 | |
| 13090 | // This test documents that an alternate Job should not pool to an already |
| 13091 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13092 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13093 | StaticSocketDataProvider data_refused; |
| 13094 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13095 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13096 | |
| 13097 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13098 | session_deps_.use_alternative_services = true; |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13099 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13100 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13101 | session->http_server_properties(); |
| 13102 | AlternativeService alternative_service( |
| 13103 | AlternateProtocolFromNextProto(GetParam()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13104 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13105 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13106 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13107 | |
| 13108 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13109 | scoped_ptr<HttpTransaction> trans1( |
| 13110 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13111 | HttpRequestInfo request1; |
| 13112 | request1.method = "GET"; |
| 13113 | request1.url = GURL(alternative_url); |
| 13114 | request1.load_flags = 0; |
| 13115 | TestCompletionCallback callback1; |
| 13116 | |
| 13117 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13118 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13119 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13120 | ASSERT_TRUE(response1); |
| 13121 | ASSERT_TRUE(response1->headers.get()); |
| 13122 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13123 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13124 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13125 | std::string response_data1; |
| 13126 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13127 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13128 | |
| 13129 | // Request for origin.example.org, which has an alternative service. This |
| 13130 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13131 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13132 | // open other connections to alternative server. The Job to origin fails, so |
| 13133 | // this request fails. |
| 13134 | scoped_ptr<HttpTransaction> trans2( |
| 13135 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13136 | HttpRequestInfo request2; |
| 13137 | request2.method = "GET"; |
| 13138 | request2.url = GURL(origin_url); |
| 13139 | request2.load_flags = 0; |
| 13140 | TestCompletionCallback callback2; |
| 13141 | |
| 13142 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13143 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13144 | |
| 13145 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13146 | // socket is still open and in the pool. |
| 13147 | scoped_ptr<HttpTransaction> trans3( |
| 13148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13149 | HttpRequestInfo request3; |
| 13150 | request3.method = "GET"; |
| 13151 | request3.url = GURL(alternative_url); |
| 13152 | request3.load_flags = 0; |
| 13153 | TestCompletionCallback callback3; |
| 13154 | |
| 13155 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13156 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13157 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13158 | ASSERT_TRUE(response3); |
| 13159 | ASSERT_TRUE(response3->headers.get()); |
| 13160 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13161 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13162 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13163 | std::string response_data3; |
| 13164 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13165 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13166 | } |
| 13167 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13168 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13169 | const std::string https_url = "https://www.example.org:8080/"; |
| 13170 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13171 | |
| 13172 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13173 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13174 | scoped_ptr<SpdyFrame> connect( |
| 13175 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13176 | scoped_ptr<SpdyFrame> req1( |
| 13177 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13178 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13179 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13180 | |
| 13181 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13182 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13183 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13184 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13185 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13186 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13187 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13188 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13189 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13190 | |
| 13191 | MockWrite writes1[] = { |
| 13192 | CreateMockWrite(*connect, 0), |
| 13193 | CreateMockWrite(*wrapped_req1, 2), |
| 13194 | CreateMockWrite(*req2, 5), |
| 13195 | }; |
| 13196 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13197 | scoped_ptr<SpdyFrame> conn_resp( |
| 13198 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13199 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13200 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13201 | scoped_ptr<SpdyFrame> wrapped_resp1( |
| 13202 | spdy_util_.ConstructWrappedSpdyFrame(resp1, 1)); |
| 13203 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 13204 | spdy_util_.ConstructWrappedSpdyFrame(body1, 1)); |
| 13205 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13206 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13207 | MockRead reads1[] = { |
| 13208 | CreateMockRead(*conn_resp, 1), |
| 13209 | CreateMockRead(*wrapped_resp1, 3), |
| 13210 | CreateMockRead(*wrapped_body1, 4), |
| 13211 | CreateMockRead(*resp2, 6), |
| 13212 | CreateMockRead(*body2, 7), |
| 13213 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 13214 | }; |
| 13215 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13216 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 13217 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13218 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13219 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13220 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13221 | session_deps_.proxy_service = |
| 13222 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13223 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13224 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13225 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13226 | ssl1.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13227 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13228 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13229 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13230 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13231 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13232 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13233 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13234 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13235 | |
| 13236 | // Start the first transaction to set up the SpdySession |
| 13237 | HttpRequestInfo request1; |
| 13238 | request1.method = "GET"; |
| 13239 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13240 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13241 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13242 | TestCompletionCallback callback1; |
| 13243 | EXPECT_EQ(ERR_IO_PENDING, |
| 13244 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13245 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13246 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13247 | |
| 13248 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13249 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13250 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13251 | LoadTimingInfo load_timing_info1; |
| 13252 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13253 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13254 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13255 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13256 | // Now, start the HTTP request |
| 13257 | HttpRequestInfo request2; |
| 13258 | request2.method = "GET"; |
| 13259 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13260 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13261 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13262 | TestCompletionCallback callback2; |
| 13263 | EXPECT_EQ(ERR_IO_PENDING, |
| 13264 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13265 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13266 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13267 | |
| 13268 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13269 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13270 | |
| 13271 | LoadTimingInfo load_timing_info2; |
| 13272 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13273 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13274 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13275 | // HTTP requests over a SPDY session should have a different connection |
| 13276 | // socket_log_id than requests over a tunnel. |
| 13277 | 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] | 13278 | } |
| 13279 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13280 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13281 | // that we do not pool other origins that resolve to the same IP when |
| 13282 | // the certificate does not match the new origin. |
| 13283 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13284 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13285 | const std::string url1 = "http://www.example.org/"; |
| 13286 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13287 | const std::string ip_addr = "1.2.3.4"; |
| 13288 | |
| 13289 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13290 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13291 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13292 | scoped_ptr<SpdyFrame> req1( |
| 13293 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13294 | |
| 13295 | MockWrite writes1[] = { |
| 13296 | CreateMockWrite(*req1, 0), |
| 13297 | }; |
| 13298 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13299 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13300 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13301 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13302 | CreateMockRead(*resp1, 1), |
| 13303 | CreateMockRead(*body1, 2), |
| 13304 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13305 | }; |
| 13306 | |
| 13307 | scoped_ptr<DeterministicSocketData> data1( |
| 13308 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 13309 | writes1, arraysize(writes1))); |
| 13310 | IPAddressNumber ip; |
| 13311 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 13312 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13313 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 13314 | data1->set_connect_data(connect_data1); |
| 13315 | |
| 13316 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13317 | scoped_ptr<SpdyFrame> req2( |
| 13318 | spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13319 | |
| 13320 | MockWrite writes2[] = { |
| 13321 | CreateMockWrite(*req2, 0), |
| 13322 | }; |
| 13323 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13324 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13325 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13326 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13327 | CreateMockRead(*resp2, 1), |
| 13328 | CreateMockRead(*body2, 2), |
| 13329 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13330 | }; |
| 13331 | |
| 13332 | scoped_ptr<DeterministicSocketData> data2( |
| 13333 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 13334 | writes2, arraysize(writes2))); |
| 13335 | MockConnect connect_data2(ASYNC, OK); |
| 13336 | data2->set_connect_data(connect_data2); |
| 13337 | |
| 13338 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13339 | // all others direct. |
| 13340 | ProxyConfig proxy_config; |
| 13341 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13342 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13343 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13344 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13345 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13346 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 13347 | ssl1.SetNextProto(GetParam()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13348 | // Load a valid cert. Note, that this does not need to |
| 13349 | // be valid for proxy because the MockSSLClientSocket does |
| 13350 | // not actually verify it. But SpdySession will use this |
| 13351 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13352 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13353 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13354 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13355 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13356 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13357 | |
| 13358 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13359 | ssl2.SetNextProto(GetParam()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13360 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13361 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13362 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13363 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13364 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13365 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13366 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13367 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13368 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13369 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13370 | |
| 13371 | // Start the first transaction to set up the SpdySession |
| 13372 | HttpRequestInfo request1; |
| 13373 | request1.method = "GET"; |
| 13374 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13375 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13376 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13377 | TestCompletionCallback callback1; |
| 13378 | ASSERT_EQ(ERR_IO_PENDING, |
| 13379 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 13380 | data1->RunFor(3); |
| 13381 | |
| 13382 | ASSERT_TRUE(callback1.have_result()); |
| 13383 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13384 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13385 | |
| 13386 | // Now, start the HTTP request |
| 13387 | HttpRequestInfo request2; |
| 13388 | request2.method = "GET"; |
| 13389 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13390 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13391 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13392 | TestCompletionCallback callback2; |
| 13393 | EXPECT_EQ(ERR_IO_PENDING, |
| 13394 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13395 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13396 | data2->RunFor(3); |
| 13397 | |
| 13398 | ASSERT_TRUE(callback2.have_result()); |
| 13399 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13400 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13401 | } |
| 13402 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13403 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13404 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13405 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13406 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13407 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13408 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13409 | |
| 13410 | MockRead reads1[] = { |
| 13411 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13412 | }; |
| 13413 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13414 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13415 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13416 | scoped_ptr<SpdyFrame> req2( |
| 13417 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13418 | MockWrite writes2[] = { |
| 13419 | CreateMockWrite(*req2, 0), |
| 13420 | }; |
| 13421 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13422 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13423 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13424 | MockRead reads2[] = { |
| 13425 | CreateMockRead(*resp2, 1), |
| 13426 | CreateMockRead(*body2, 2), |
| 13427 | MockRead(ASYNC, OK, 3) // EOF |
| 13428 | }; |
| 13429 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13430 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13431 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13432 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13433 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13434 | ssl1.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13436 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13437 | |
| 13438 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13439 | ssl2.SetNextProto(GetParam()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13441 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13442 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13443 | scoped_refptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13444 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13445 | |
| 13446 | // Start the first transaction to set up the SpdySession and verify that |
| 13447 | // connection was closed. |
| 13448 | HttpRequestInfo request1; |
| 13449 | request1.method = "GET"; |
| 13450 | request1.url = GURL(https_url); |
| 13451 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13452 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13453 | TestCompletionCallback callback1; |
| 13454 | EXPECT_EQ(ERR_IO_PENDING, |
| 13455 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13456 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 13457 | |
| 13458 | // Now, start the second request and make sure it succeeds. |
| 13459 | HttpRequestInfo request2; |
| 13460 | request2.method = "GET"; |
| 13461 | request2.url = GURL(https_url); |
| 13462 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13463 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13464 | TestCompletionCallback callback2; |
| 13465 | EXPECT_EQ(ERR_IO_PENDING, |
| 13466 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13467 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13468 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13469 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13470 | } |
| 13471 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13472 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 13473 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13474 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13475 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13476 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13477 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13478 | |
| 13479 | // Use two different hosts with different IPs so they don't get pooled. |
| 13480 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13481 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13482 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13483 | |
| 13484 | SSLSocketDataProvider ssl1(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13485 | ssl1.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13486 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13487 | ssl2.SetNextProto(GetParam()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13490 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13491 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13492 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 13493 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13494 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13495 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13496 | scoped_ptr<SpdyFrame> host1_resp( |
| 13497 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13498 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13499 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13500 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13501 | CreateMockRead(*host1_resp, 1), |
| 13502 | CreateMockRead(*host1_resp_body, 2), |
| 13503 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13504 | }; |
| 13505 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13506 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 13507 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13508 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13509 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13510 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13511 | scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13512 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 13513 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13514 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13515 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13516 | scoped_ptr<SpdyFrame> host2_resp( |
| 13517 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13518 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 13519 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13520 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13521 | CreateMockRead(*host2_resp, 1), |
| 13522 | CreateMockRead(*host2_resp_body, 2), |
| 13523 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13524 | }; |
| 13525 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13526 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 13527 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13528 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13529 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13530 | |
| 13531 | MockWrite http_write[] = { |
| 13532 | MockWrite("GET / HTTP/1.1\r\n" |
| 13533 | "Host: www.a.com\r\n" |
| 13534 | "Connection: keep-alive\r\n\r\n"), |
| 13535 | }; |
| 13536 | |
| 13537 | MockRead http_read[] = { |
| 13538 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13539 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13540 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13541 | MockRead("hello!"), |
| 13542 | }; |
| 13543 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13544 | http_write, arraysize(http_write)); |
| 13545 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13546 | |
| 13547 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13548 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13549 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13550 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13551 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13552 | |
| 13553 | TestCompletionCallback callback; |
| 13554 | HttpRequestInfo request1; |
| 13555 | request1.method = "GET"; |
| 13556 | request1.url = GURL("https://www.a.com/"); |
| 13557 | request1.load_flags = 0; |
| 13558 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13559 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13560 | |
| 13561 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 13562 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13563 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13564 | |
| 13565 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13566 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13567 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13568 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13569 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13570 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13571 | |
| 13572 | std::string response_data; |
| 13573 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13574 | EXPECT_EQ("hello!", response_data); |
| 13575 | trans.reset(); |
| 13576 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13577 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13578 | |
| 13579 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13580 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13581 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13582 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13583 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13584 | HttpRequestInfo request2; |
| 13585 | request2.method = "GET"; |
| 13586 | request2.url = GURL("https://www.b.com/"); |
| 13587 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13588 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13589 | |
| 13590 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13591 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13592 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13593 | |
| 13594 | response = trans->GetResponseInfo(); |
| 13595 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13596 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13597 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13598 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13599 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13600 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13601 | EXPECT_EQ("hello!", response_data); |
| 13602 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13603 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13604 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13605 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13606 | |
| 13607 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13608 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13609 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13610 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13611 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13612 | HttpRequestInfo request3; |
| 13613 | request3.method = "GET"; |
| 13614 | request3.url = GURL("http://www.a.com/"); |
| 13615 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13616 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13617 | |
| 13618 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13619 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13620 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13621 | |
| 13622 | response = trans->GetResponseInfo(); |
| 13623 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13624 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13625 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13626 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13627 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13628 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13629 | EXPECT_EQ("hello!", response_data); |
| 13630 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13631 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13632 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13633 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13634 | } |
| 13635 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13636 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13637 | HttpRequestInfo request; |
| 13638 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13639 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13640 | request.load_flags = 0; |
| 13641 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13642 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13643 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13644 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13645 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13646 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13647 | StaticSocketDataProvider data; |
| 13648 | data.set_connect_data(mock_connect); |
| 13649 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13650 | |
| 13651 | TestCompletionCallback callback; |
| 13652 | |
| 13653 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13654 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13655 | |
| 13656 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13657 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13658 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13659 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13660 | HttpRequestHeaders request_headers; |
| 13661 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13662 | |
| 13663 | ConnectionAttempts attempts; |
| 13664 | trans->GetConnectionAttempts(&attempts); |
| 13665 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13666 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13667 | |
| 13668 | IPEndPoint endpoint; |
| 13669 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13670 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13671 | } |
| 13672 | |
| 13673 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13674 | HttpRequestInfo request; |
| 13675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13676 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13677 | request.load_flags = 0; |
| 13678 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13679 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13680 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13681 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13682 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13683 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13684 | StaticSocketDataProvider data; |
| 13685 | data.set_connect_data(mock_connect); |
| 13686 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13687 | |
| 13688 | TestCompletionCallback callback; |
| 13689 | |
| 13690 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13691 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13692 | |
| 13693 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13694 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13695 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13696 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13697 | HttpRequestHeaders request_headers; |
| 13698 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13699 | |
| 13700 | ConnectionAttempts attempts; |
| 13701 | trans->GetConnectionAttempts(&attempts); |
| 13702 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13703 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13704 | |
| 13705 | IPEndPoint endpoint; |
| 13706 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13707 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13708 | } |
| 13709 | |
| 13710 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13711 | HttpRequestInfo request; |
| 13712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13713 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13714 | request.load_flags = 0; |
| 13715 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13716 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13717 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13718 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13719 | |
| 13720 | MockWrite data_writes[] = { |
| 13721 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13722 | }; |
| 13723 | MockRead data_reads[] = { |
| 13724 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13725 | }; |
| 13726 | |
| 13727 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13728 | data_writes, arraysize(data_writes)); |
| 13729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13730 | |
| 13731 | TestCompletionCallback callback; |
| 13732 | |
| 13733 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13734 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13735 | |
| 13736 | rv = callback.WaitForResult(); |
| 13737 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13738 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13739 | HttpRequestHeaders request_headers; |
| 13740 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13741 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13742 | } |
| 13743 | |
| 13744 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13745 | HttpRequestInfo request; |
| 13746 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13747 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13748 | request.load_flags = 0; |
| 13749 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13750 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13751 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13752 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13753 | |
| 13754 | MockWrite data_writes[] = { |
| 13755 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13756 | }; |
| 13757 | MockRead data_reads[] = { |
| 13758 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13759 | }; |
| 13760 | |
| 13761 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13762 | data_writes, arraysize(data_writes)); |
| 13763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13764 | |
| 13765 | TestCompletionCallback callback; |
| 13766 | |
| 13767 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13768 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13769 | |
| 13770 | rv = callback.WaitForResult(); |
| 13771 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13772 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13773 | HttpRequestHeaders request_headers; |
| 13774 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13775 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13776 | } |
| 13777 | |
| 13778 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13779 | HttpRequestInfo request; |
| 13780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13781 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13782 | request.load_flags = 0; |
| 13783 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13784 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13785 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13786 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13787 | |
| 13788 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13789 | MockWrite( |
| 13790 | "GET / HTTP/1.1\r\n" |
| 13791 | "Host: www.example.org\r\n" |
| 13792 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13793 | }; |
| 13794 | MockRead data_reads[] = { |
| 13795 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13796 | }; |
| 13797 | |
| 13798 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13799 | data_writes, arraysize(data_writes)); |
| 13800 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13801 | |
| 13802 | TestCompletionCallback callback; |
| 13803 | |
| 13804 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13805 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13806 | |
| 13807 | rv = callback.WaitForResult(); |
| 13808 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13809 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13810 | HttpRequestHeaders request_headers; |
| 13811 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13812 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13813 | } |
| 13814 | |
| 13815 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13816 | HttpRequestInfo request; |
| 13817 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13818 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13819 | request.load_flags = 0; |
| 13820 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13821 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13822 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13823 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13824 | |
| 13825 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13826 | MockWrite( |
| 13827 | "GET / HTTP/1.1\r\n" |
| 13828 | "Host: www.example.org\r\n" |
| 13829 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13830 | }; |
| 13831 | MockRead data_reads[] = { |
| 13832 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13833 | }; |
| 13834 | |
| 13835 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13836 | data_writes, arraysize(data_writes)); |
| 13837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13838 | |
| 13839 | TestCompletionCallback callback; |
| 13840 | |
| 13841 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13843 | |
| 13844 | rv = callback.WaitForResult(); |
| 13845 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13846 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13847 | HttpRequestHeaders request_headers; |
| 13848 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13849 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13850 | } |
| 13851 | |
| 13852 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 13853 | HttpRequestInfo request; |
| 13854 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13855 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13856 | request.load_flags = 0; |
| 13857 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 13858 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 13859 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13860 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13862 | |
| 13863 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13864 | MockWrite( |
| 13865 | "GET / HTTP/1.1\r\n" |
| 13866 | "Host: www.example.org\r\n" |
| 13867 | "Connection: keep-alive\r\n" |
| 13868 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13869 | }; |
| 13870 | MockRead data_reads[] = { |
| 13871 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13872 | "Content-Length: 5\r\n\r\n" |
| 13873 | "hello"), |
| 13874 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 13875 | }; |
| 13876 | |
| 13877 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13878 | data_writes, arraysize(data_writes)); |
| 13879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13880 | |
| 13881 | TestCompletionCallback callback; |
| 13882 | |
| 13883 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13884 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13885 | |
| 13886 | rv = callback.WaitForResult(); |
| 13887 | EXPECT_EQ(OK, rv); |
| 13888 | |
| 13889 | HttpRequestHeaders request_headers; |
| 13890 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13891 | std::string foo; |
| 13892 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 13893 | EXPECT_EQ("bar", foo); |
| 13894 | } |
| 13895 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13896 | namespace { |
| 13897 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13898 | // Fake HttpStream that simply records calls to SetPriority(). |
| 13899 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13900 | public base::SupportsWeakPtr<FakeStream> { |
| 13901 | public: |
| 13902 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13903 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13904 | |
| 13905 | RequestPriority priority() const { return priority_; } |
| 13906 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13907 | int InitializeStream(const HttpRequestInfo* request_info, |
| 13908 | RequestPriority priority, |
| 13909 | const BoundNetLog& net_log, |
| 13910 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13911 | return ERR_IO_PENDING; |
| 13912 | } |
| 13913 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13914 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 13915 | HttpResponseInfo* response, |
| 13916 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13917 | ADD_FAILURE(); |
| 13918 | return ERR_UNEXPECTED; |
| 13919 | } |
| 13920 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13921 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13922 | ADD_FAILURE(); |
| 13923 | return ERR_UNEXPECTED; |
| 13924 | } |
| 13925 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13926 | int ReadResponseBody(IOBuffer* buf, |
| 13927 | int buf_len, |
| 13928 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13929 | ADD_FAILURE(); |
| 13930 | return ERR_UNEXPECTED; |
| 13931 | } |
| 13932 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13933 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13934 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13935 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13936 | ADD_FAILURE(); |
| 13937 | return false; |
| 13938 | } |
| 13939 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13940 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13941 | ADD_FAILURE(); |
| 13942 | return false; |
| 13943 | } |
| 13944 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13945 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13946 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 13947 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13948 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 13949 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 13950 | ADD_FAILURE(); |
| 13951 | return 0; |
| 13952 | } |
| 13953 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 13954 | int64_t GetTotalSentBytes() const override { |
| 13955 | ADD_FAILURE(); |
| 13956 | return 0; |
| 13957 | } |
| 13958 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13959 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13960 | ADD_FAILURE(); |
| 13961 | return false; |
| 13962 | } |
| 13963 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13964 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 13965 | |
| 13966 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13967 | ADD_FAILURE(); |
| 13968 | } |
| 13969 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13970 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 13971 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13972 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13973 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13974 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13975 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 13976 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 13977 | |
| 13978 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 13979 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13980 | private: |
| 13981 | RequestPriority priority_; |
| 13982 | |
| 13983 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 13984 | }; |
| 13985 | |
| 13986 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 13987 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 13988 | class FakeStreamRequest : public HttpStreamRequest, |
| 13989 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 13990 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 13991 | FakeStreamRequest(RequestPriority priority, |
| 13992 | HttpStreamRequest::Delegate* delegate) |
| 13993 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 13994 | delegate_(delegate), |
| 13995 | websocket_stream_create_helper_(NULL) {} |
| 13996 | |
| 13997 | FakeStreamRequest(RequestPriority priority, |
| 13998 | HttpStreamRequest::Delegate* delegate, |
| 13999 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14000 | : priority_(priority), |
| 14001 | delegate_(delegate), |
| 14002 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14003 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14004 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14005 | |
| 14006 | RequestPriority priority() const { return priority_; } |
| 14007 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14008 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14009 | websocket_stream_create_helper() const { |
| 14010 | return websocket_stream_create_helper_; |
| 14011 | } |
| 14012 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14013 | // Create a new FakeStream and pass it to the request's |
| 14014 | // delegate. Returns a weak pointer to the FakeStream. |
| 14015 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14016 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14017 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14018 | // immediately delete |fake_stream|. |
| 14019 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14020 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14021 | return weak_stream; |
| 14022 | } |
| 14023 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14024 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14025 | ADD_FAILURE(); |
| 14026 | return ERR_UNEXPECTED; |
| 14027 | } |
| 14028 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14029 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14030 | ADD_FAILURE(); |
| 14031 | return LoadState(); |
| 14032 | } |
| 14033 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14034 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14035 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14036 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14037 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14038 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14039 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14040 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14041 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14042 | const ConnectionAttempts& connection_attempts() const override { |
| 14043 | static ConnectionAttempts no_attempts; |
| 14044 | return no_attempts; |
| 14045 | } |
| 14046 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14047 | private: |
| 14048 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14049 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14050 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14051 | |
| 14052 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14053 | }; |
| 14054 | |
| 14055 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14056 | class FakeStreamFactory : public HttpStreamFactory { |
| 14057 | public: |
| 14058 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14059 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14060 | |
| 14061 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14062 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14063 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14064 | return last_stream_request_; |
| 14065 | } |
| 14066 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14067 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14068 | RequestPriority priority, |
| 14069 | const SSLConfig& server_ssl_config, |
| 14070 | const SSLConfig& proxy_ssl_config, |
| 14071 | HttpStreamRequest::Delegate* delegate, |
| 14072 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14073 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14074 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14075 | return fake_request; |
| 14076 | } |
| 14077 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14078 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14079 | const HttpRequestInfo& info, |
| 14080 | RequestPriority priority, |
| 14081 | const SSLConfig& server_ssl_config, |
| 14082 | const SSLConfig& proxy_ssl_config, |
| 14083 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14084 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14085 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14086 | FakeStreamRequest* fake_request = |
| 14087 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14088 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14089 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14090 | } |
| 14091 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14092 | void PreconnectStreams(int num_streams, |
| 14093 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14094 | const SSLConfig& server_ssl_config, |
| 14095 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14096 | ADD_FAILURE(); |
| 14097 | } |
| 14098 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14099 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14100 | ADD_FAILURE(); |
| 14101 | return NULL; |
| 14102 | } |
| 14103 | |
| 14104 | private: |
| 14105 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14106 | |
| 14107 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14108 | }; |
| 14109 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14110 | // TODO(ricea): Maybe unify this with the one in |
| 14111 | // url_request_http_job_unittest.cc ? |
| 14112 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14113 | public: |
| 14114 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14115 | bool using_proxy) |
| 14116 | : state_(connection.release(), using_proxy) {} |
| 14117 | |
| 14118 | // Fake implementation of HttpStreamBase methods. |
| 14119 | // This ends up being quite "real" because this object has to really send data |
| 14120 | // on the mock socket. It might be easier to use the real implementation, but |
| 14121 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14122 | // difficult. |
| 14123 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14124 | RequestPriority priority, |
| 14125 | const BoundNetLog& net_log, |
| 14126 | const CompletionCallback& callback) override { |
| 14127 | state_.Initialize(request_info, priority, net_log, callback); |
| 14128 | return OK; |
| 14129 | } |
| 14130 | |
| 14131 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14132 | HttpResponseInfo* response, |
| 14133 | const CompletionCallback& callback) override { |
| 14134 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14135 | response, callback); |
| 14136 | } |
| 14137 | |
| 14138 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14139 | return parser()->ReadResponseHeaders(callback); |
| 14140 | } |
| 14141 | |
| 14142 | int ReadResponseBody(IOBuffer* buf, |
| 14143 | int buf_len, |
| 14144 | const CompletionCallback& callback) override { |
| 14145 | NOTREACHED(); |
| 14146 | return ERR_IO_PENDING; |
| 14147 | } |
| 14148 | |
| 14149 | void Close(bool not_reusable) override { |
| 14150 | if (parser()) |
| 14151 | parser()->Close(true); |
| 14152 | } |
| 14153 | |
| 14154 | bool IsResponseBodyComplete() const override { |
| 14155 | NOTREACHED(); |
| 14156 | return false; |
| 14157 | } |
| 14158 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14159 | bool IsConnectionReused() const override { |
| 14160 | NOTREACHED(); |
| 14161 | return false; |
| 14162 | } |
| 14163 | void SetConnectionReused() override { NOTREACHED(); } |
| 14164 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14165 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14166 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14167 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14168 | NOTREACHED(); |
| 14169 | return 0; |
| 14170 | } |
| 14171 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14172 | int64_t GetTotalSentBytes() const override { |
| 14173 | NOTREACHED(); |
| 14174 | return 0; |
| 14175 | } |
| 14176 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14177 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14178 | NOTREACHED(); |
| 14179 | return false; |
| 14180 | } |
| 14181 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14182 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14183 | |
| 14184 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14185 | NOTREACHED(); |
| 14186 | } |
| 14187 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14188 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14189 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14190 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14191 | |
| 14192 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14193 | |
| 14194 | UploadProgress GetUploadProgress() const override { |
| 14195 | NOTREACHED(); |
| 14196 | return UploadProgress(); |
| 14197 | } |
| 14198 | |
| 14199 | HttpStream* RenewStreamForAuth() override { |
| 14200 | NOTREACHED(); |
| 14201 | return nullptr; |
| 14202 | } |
| 14203 | |
| 14204 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14205 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14206 | NOTREACHED(); |
| 14207 | return scoped_ptr<WebSocketStream>(); |
| 14208 | } |
| 14209 | |
| 14210 | private: |
| 14211 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14212 | HttpBasicState state_; |
| 14213 | |
| 14214 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14215 | }; |
| 14216 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14217 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14218 | // worth doing. |
| 14219 | class FakeWebSocketStreamCreateHelper : |
| 14220 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14221 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14222 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14223 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14224 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14225 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 14226 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14227 | } |
| 14228 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14229 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14230 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14231 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14232 | NOTREACHED(); |
| 14233 | return NULL; |
| 14234 | }; |
| 14235 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14236 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14237 | |
| 14238 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14239 | NOTREACHED(); |
| 14240 | return scoped_ptr<WebSocketStream>(); |
| 14241 | } |
| 14242 | }; |
| 14243 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14244 | } // namespace |
| 14245 | |
| 14246 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14247 | // stream request on start. |
| 14248 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14249 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14250 | HttpNetworkSessionPeer peer(session); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14251 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14252 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14253 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14254 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14255 | |
| 14256 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14257 | |
| 14258 | HttpRequestInfo request; |
| 14259 | TestCompletionCallback callback; |
| 14260 | EXPECT_EQ(ERR_IO_PENDING, |
| 14261 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14262 | |
| 14263 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14264 | fake_factory->last_stream_request(); |
| 14265 | ASSERT_TRUE(fake_request != NULL); |
| 14266 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14267 | } |
| 14268 | |
| 14269 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14270 | // updates to its stream request. |
| 14271 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14272 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14273 | HttpNetworkSessionPeer peer(session); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14274 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14275 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14276 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14277 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14278 | |
| 14279 | HttpRequestInfo request; |
| 14280 | TestCompletionCallback callback; |
| 14281 | EXPECT_EQ(ERR_IO_PENDING, |
| 14282 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14283 | |
| 14284 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14285 | fake_factory->last_stream_request(); |
| 14286 | ASSERT_TRUE(fake_request != NULL); |
| 14287 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14288 | |
| 14289 | trans.SetPriority(LOWEST); |
| 14290 | ASSERT_TRUE(fake_request != NULL); |
| 14291 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14292 | } |
| 14293 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14294 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14295 | // updates to its stream. |
| 14296 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14297 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14298 | HttpNetworkSessionPeer peer(session); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14299 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14300 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14301 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14302 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14303 | |
| 14304 | HttpRequestInfo request; |
| 14305 | TestCompletionCallback callback; |
| 14306 | EXPECT_EQ(ERR_IO_PENDING, |
| 14307 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14308 | |
| 14309 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14310 | fake_factory->last_stream_request(); |
| 14311 | ASSERT_TRUE(fake_request != NULL); |
| 14312 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14313 | ASSERT_TRUE(fake_stream != NULL); |
| 14314 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14315 | |
| 14316 | trans.SetPriority(LOWEST); |
| 14317 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14318 | } |
| 14319 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14320 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14321 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14322 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14323 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14324 | std::string test_cases[] = {"ws://www.example.org/", |
| 14325 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14326 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14327 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14328 | HttpNetworkSessionPeer peer(session); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14329 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14330 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14331 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14332 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14333 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14334 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14335 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14336 | &websocket_stream_create_helper); |
| 14337 | |
| 14338 | HttpRequestInfo request; |
| 14339 | TestCompletionCallback callback; |
| 14340 | request.method = "GET"; |
| 14341 | request.url = GURL(test_cases[i]); |
| 14342 | |
| 14343 | EXPECT_EQ(ERR_IO_PENDING, |
| 14344 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14345 | |
| 14346 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14347 | fake_factory->last_stream_request(); |
| 14348 | ASSERT_TRUE(fake_request != NULL); |
| 14349 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14350 | fake_request->websocket_stream_create_helper()); |
| 14351 | } |
| 14352 | } |
| 14353 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14354 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14355 | // if the transport socket pool is stalled on the global socket limit. |
| 14356 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14357 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14358 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14359 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14360 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14361 | |
| 14362 | // Set up SSL request. |
| 14363 | |
| 14364 | HttpRequestInfo ssl_request; |
| 14365 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14366 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14367 | |
| 14368 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14369 | MockWrite( |
| 14370 | "GET / HTTP/1.1\r\n" |
| 14371 | "Host: www.example.org\r\n" |
| 14372 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14373 | }; |
| 14374 | MockRead ssl_reads[] = { |
| 14375 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14376 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14377 | MockRead("hello world"), |
| 14378 | MockRead(SYNCHRONOUS, OK), |
| 14379 | }; |
| 14380 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14381 | ssl_writes, arraysize(ssl_writes)); |
| 14382 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14383 | |
| 14384 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14386 | |
| 14387 | // Set up HTTP request. |
| 14388 | |
| 14389 | HttpRequestInfo http_request; |
| 14390 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14391 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14392 | |
| 14393 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14394 | MockWrite( |
| 14395 | "GET / HTTP/1.1\r\n" |
| 14396 | "Host: www.example.org\r\n" |
| 14397 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14398 | }; |
| 14399 | MockRead http_reads[] = { |
| 14400 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14401 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14402 | MockRead("falafel"), |
| 14403 | MockRead(SYNCHRONOUS, OK), |
| 14404 | }; |
| 14405 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14406 | http_writes, arraysize(http_writes)); |
| 14407 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14408 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14409 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14410 | |
| 14411 | // Start the SSL request. |
| 14412 | TestCompletionCallback ssl_callback; |
| 14413 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14414 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14415 | ASSERT_EQ(ERR_IO_PENDING, |
| 14416 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14417 | BoundNetLog())); |
| 14418 | |
| 14419 | // Start the HTTP request. Pool should stall. |
| 14420 | TestCompletionCallback http_callback; |
| 14421 | scoped_ptr<HttpTransaction> http_trans( |
| 14422 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14423 | ASSERT_EQ(ERR_IO_PENDING, |
| 14424 | http_trans->Start(&http_request, http_callback.callback(), |
| 14425 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14426 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14427 | |
| 14428 | // Wait for response from SSL request. |
| 14429 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 14430 | std::string response_data; |
| 14431 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 14432 | EXPECT_EQ("hello world", response_data); |
| 14433 | |
| 14434 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14435 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14436 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14437 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14438 | |
| 14439 | // The HTTP request can now complete. |
| 14440 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14441 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14442 | EXPECT_EQ("falafel", response_data); |
| 14443 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14444 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14445 | } |
| 14446 | |
| 14447 | // Tests that when a SSL connection is established but there's no corresponding |
| 14448 | // request that needs it, the new socket is closed if the transport socket pool |
| 14449 | // is stalled on the global socket limit. |
| 14450 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 14451 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14452 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14453 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14454 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14455 | |
| 14456 | // Set up an ssl request. |
| 14457 | |
| 14458 | HttpRequestInfo ssl_request; |
| 14459 | ssl_request.method = "GET"; |
| 14460 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14461 | |
| 14462 | // No data will be sent on the SSL socket. |
| 14463 | StaticSocketDataProvider ssl_data; |
| 14464 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14465 | |
| 14466 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14468 | |
| 14469 | // Set up HTTP request. |
| 14470 | |
| 14471 | HttpRequestInfo http_request; |
| 14472 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14473 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14474 | |
| 14475 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14476 | MockWrite( |
| 14477 | "GET / HTTP/1.1\r\n" |
| 14478 | "Host: www.example.org\r\n" |
| 14479 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14480 | }; |
| 14481 | MockRead http_reads[] = { |
| 14482 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14483 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14484 | MockRead("falafel"), |
| 14485 | MockRead(SYNCHRONOUS, OK), |
| 14486 | }; |
| 14487 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14488 | http_writes, arraysize(http_writes)); |
| 14489 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14490 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14491 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14492 | |
| 14493 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14494 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14495 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 14496 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14497 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 14498 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 14499 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14500 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14501 | |
| 14502 | // Start the HTTP request. Pool should stall. |
| 14503 | TestCompletionCallback http_callback; |
| 14504 | scoped_ptr<HttpTransaction> http_trans( |
| 14505 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14506 | ASSERT_EQ(ERR_IO_PENDING, |
| 14507 | http_trans->Start(&http_request, http_callback.callback(), |
| 14508 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14509 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14510 | |
| 14511 | // The SSL connection will automatically be closed once the connection is |
| 14512 | // established, to let the HTTP request start. |
| 14513 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14514 | std::string response_data; |
| 14515 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14516 | EXPECT_EQ("falafel", response_data); |
| 14517 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14518 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14519 | } |
| 14520 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14521 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
| 14522 | ScopedVector<UploadElementReader> element_readers; |
| 14523 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14524 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14525 | |
| 14526 | HttpRequestInfo request; |
| 14527 | request.method = "POST"; |
| 14528 | request.url = GURL("http://www.foo.com/"); |
| 14529 | request.upload_data_stream = &upload_data_stream; |
| 14530 | request.load_flags = 0; |
| 14531 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14532 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14533 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14534 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14535 | // Send headers successfully, but get an error while sending the body. |
| 14536 | MockWrite data_writes[] = { |
| 14537 | MockWrite("POST / HTTP/1.1\r\n" |
| 14538 | "Host: www.foo.com\r\n" |
| 14539 | "Connection: keep-alive\r\n" |
| 14540 | "Content-Length: 3\r\n\r\n"), |
| 14541 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14542 | }; |
| 14543 | |
| 14544 | MockRead data_reads[] = { |
| 14545 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14546 | MockRead("hello world"), |
| 14547 | MockRead(SYNCHRONOUS, OK), |
| 14548 | }; |
| 14549 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14550 | arraysize(data_writes)); |
| 14551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14552 | |
| 14553 | TestCompletionCallback callback; |
| 14554 | |
| 14555 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14556 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14557 | |
| 14558 | rv = callback.WaitForResult(); |
| 14559 | EXPECT_EQ(OK, rv); |
| 14560 | |
| 14561 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14562 | ASSERT_TRUE(response != NULL); |
| 14563 | |
| 14564 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14565 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14566 | |
| 14567 | std::string response_data; |
| 14568 | rv = ReadTransaction(trans.get(), &response_data); |
| 14569 | EXPECT_EQ(OK, rv); |
| 14570 | EXPECT_EQ("hello world", response_data); |
| 14571 | } |
| 14572 | |
| 14573 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14574 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 14575 | TEST_P(HttpNetworkTransactionTest, |
| 14576 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14577 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14578 | MockWrite data_writes[] = { |
| 14579 | MockWrite("GET / HTTP/1.1\r\n" |
| 14580 | "Host: www.foo.com\r\n" |
| 14581 | "Connection: keep-alive\r\n\r\n"), |
| 14582 | MockWrite("POST / HTTP/1.1\r\n" |
| 14583 | "Host: www.foo.com\r\n" |
| 14584 | "Connection: keep-alive\r\n" |
| 14585 | "Content-Length: 3\r\n\r\n"), |
| 14586 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14587 | }; |
| 14588 | |
| 14589 | MockRead data_reads[] = { |
| 14590 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14591 | "Content-Length: 14\r\n\r\n"), |
| 14592 | MockRead("first response"), |
| 14593 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14594 | "Content-Length: 15\r\n\r\n"), |
| 14595 | MockRead("second response"), |
| 14596 | MockRead(SYNCHRONOUS, OK), |
| 14597 | }; |
| 14598 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14599 | arraysize(data_writes)); |
| 14600 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14601 | |
| 14602 | TestCompletionCallback callback; |
| 14603 | HttpRequestInfo request1; |
| 14604 | request1.method = "GET"; |
| 14605 | request1.url = GURL("http://www.foo.com/"); |
| 14606 | request1.load_flags = 0; |
| 14607 | |
| 14608 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14610 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14612 | |
| 14613 | rv = callback.WaitForResult(); |
| 14614 | EXPECT_EQ(OK, rv); |
| 14615 | |
| 14616 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14617 | ASSERT_TRUE(response1 != NULL); |
| 14618 | |
| 14619 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14620 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14621 | |
| 14622 | std::string response_data1; |
| 14623 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14624 | EXPECT_EQ(OK, rv); |
| 14625 | EXPECT_EQ("first response", response_data1); |
| 14626 | // Delete the transaction to release the socket back into the socket pool. |
| 14627 | trans1.reset(); |
| 14628 | |
| 14629 | ScopedVector<UploadElementReader> element_readers; |
| 14630 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14631 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14632 | |
| 14633 | HttpRequestInfo request2; |
| 14634 | request2.method = "POST"; |
| 14635 | request2.url = GURL("http://www.foo.com/"); |
| 14636 | request2.upload_data_stream = &upload_data_stream; |
| 14637 | request2.load_flags = 0; |
| 14638 | |
| 14639 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14640 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14641 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14642 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14643 | |
| 14644 | rv = callback.WaitForResult(); |
| 14645 | EXPECT_EQ(OK, rv); |
| 14646 | |
| 14647 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14648 | ASSERT_TRUE(response2 != NULL); |
| 14649 | |
| 14650 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14651 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14652 | |
| 14653 | std::string response_data2; |
| 14654 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14655 | EXPECT_EQ(OK, rv); |
| 14656 | EXPECT_EQ("second response", response_data2); |
| 14657 | } |
| 14658 | |
| 14659 | TEST_P(HttpNetworkTransactionTest, |
| 14660 | PostReadsErrorResponseAfterResetPartialBodySent) { |
| 14661 | ScopedVector<UploadElementReader> element_readers; |
| 14662 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14663 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14664 | |
| 14665 | HttpRequestInfo request; |
| 14666 | request.method = "POST"; |
| 14667 | request.url = GURL("http://www.foo.com/"); |
| 14668 | request.upload_data_stream = &upload_data_stream; |
| 14669 | request.load_flags = 0; |
| 14670 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14671 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14672 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14673 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14674 | // Send headers successfully, but get an error while sending the body. |
| 14675 | MockWrite data_writes[] = { |
| 14676 | MockWrite("POST / HTTP/1.1\r\n" |
| 14677 | "Host: www.foo.com\r\n" |
| 14678 | "Connection: keep-alive\r\n" |
| 14679 | "Content-Length: 3\r\n\r\n" |
| 14680 | "fo"), |
| 14681 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14682 | }; |
| 14683 | |
| 14684 | MockRead data_reads[] = { |
| 14685 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14686 | MockRead("hello world"), |
| 14687 | MockRead(SYNCHRONOUS, OK), |
| 14688 | }; |
| 14689 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14690 | arraysize(data_writes)); |
| 14691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14692 | |
| 14693 | TestCompletionCallback callback; |
| 14694 | |
| 14695 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14696 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14697 | |
| 14698 | rv = callback.WaitForResult(); |
| 14699 | EXPECT_EQ(OK, rv); |
| 14700 | |
| 14701 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14702 | ASSERT_TRUE(response != NULL); |
| 14703 | |
| 14704 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14705 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14706 | |
| 14707 | std::string response_data; |
| 14708 | rv = ReadTransaction(trans.get(), &response_data); |
| 14709 | EXPECT_EQ(OK, rv); |
| 14710 | EXPECT_EQ("hello world", response_data); |
| 14711 | } |
| 14712 | |
| 14713 | // This tests the more common case than the previous test, where headers and |
| 14714 | // body are not merged into a single request. |
| 14715 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
| 14716 | ScopedVector<UploadElementReader> element_readers; |
| 14717 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14718 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14719 | |
| 14720 | HttpRequestInfo request; |
| 14721 | request.method = "POST"; |
| 14722 | request.url = GURL("http://www.foo.com/"); |
| 14723 | request.upload_data_stream = &upload_data_stream; |
| 14724 | request.load_flags = 0; |
| 14725 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14726 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14727 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14728 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14729 | // Send headers successfully, but get an error while sending the body. |
| 14730 | MockWrite data_writes[] = { |
| 14731 | MockWrite("POST / HTTP/1.1\r\n" |
| 14732 | "Host: www.foo.com\r\n" |
| 14733 | "Connection: keep-alive\r\n" |
| 14734 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14735 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14736 | }; |
| 14737 | |
| 14738 | MockRead data_reads[] = { |
| 14739 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14740 | MockRead("hello world"), |
| 14741 | MockRead(SYNCHRONOUS, OK), |
| 14742 | }; |
| 14743 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14744 | arraysize(data_writes)); |
| 14745 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14746 | |
| 14747 | TestCompletionCallback callback; |
| 14748 | |
| 14749 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14750 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14751 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14752 | // they can't be merged with the body in a single send. Not currently |
| 14753 | // necessary since a chunked body is never merged with headers, but this makes |
| 14754 | // the test more future proof. |
| 14755 | base::RunLoop().RunUntilIdle(); |
| 14756 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14757 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14758 | |
| 14759 | rv = callback.WaitForResult(); |
| 14760 | EXPECT_EQ(OK, rv); |
| 14761 | |
| 14762 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14763 | ASSERT_TRUE(response != NULL); |
| 14764 | |
| 14765 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14766 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14767 | |
| 14768 | std::string response_data; |
| 14769 | rv = ReadTransaction(trans.get(), &response_data); |
| 14770 | EXPECT_EQ(OK, rv); |
| 14771 | EXPECT_EQ("hello world", response_data); |
| 14772 | } |
| 14773 | |
| 14774 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
| 14775 | ScopedVector<UploadElementReader> element_readers; |
| 14776 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14777 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14778 | |
| 14779 | HttpRequestInfo request; |
| 14780 | request.method = "POST"; |
| 14781 | request.url = GURL("http://www.foo.com/"); |
| 14782 | request.upload_data_stream = &upload_data_stream; |
| 14783 | request.load_flags = 0; |
| 14784 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14785 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14786 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14787 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14788 | |
| 14789 | MockWrite data_writes[] = { |
| 14790 | MockWrite("POST / HTTP/1.1\r\n" |
| 14791 | "Host: www.foo.com\r\n" |
| 14792 | "Connection: keep-alive\r\n" |
| 14793 | "Content-Length: 3\r\n\r\n"), |
| 14794 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14795 | }; |
| 14796 | |
| 14797 | MockRead data_reads[] = { |
| 14798 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14799 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14800 | MockRead("hello world"), |
| 14801 | MockRead(SYNCHRONOUS, OK), |
| 14802 | }; |
| 14803 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14804 | arraysize(data_writes)); |
| 14805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14806 | |
| 14807 | TestCompletionCallback callback; |
| 14808 | |
| 14809 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14810 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14811 | |
| 14812 | rv = callback.WaitForResult(); |
| 14813 | EXPECT_EQ(OK, rv); |
| 14814 | |
| 14815 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14816 | ASSERT_TRUE(response != NULL); |
| 14817 | |
| 14818 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14819 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14820 | |
| 14821 | std::string response_data; |
| 14822 | rv = ReadTransaction(trans.get(), &response_data); |
| 14823 | EXPECT_EQ(OK, rv); |
| 14824 | EXPECT_EQ("hello world", response_data); |
| 14825 | } |
| 14826 | |
| 14827 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
| 14828 | ScopedVector<UploadElementReader> element_readers; |
| 14829 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14830 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14831 | |
| 14832 | HttpRequestInfo request; |
| 14833 | request.method = "POST"; |
| 14834 | request.url = GURL("http://www.foo.com/"); |
| 14835 | request.upload_data_stream = &upload_data_stream; |
| 14836 | request.load_flags = 0; |
| 14837 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14838 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14839 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14841 | // Send headers successfully, but get an error while sending the body. |
| 14842 | MockWrite data_writes[] = { |
| 14843 | MockWrite("POST / HTTP/1.1\r\n" |
| 14844 | "Host: www.foo.com\r\n" |
| 14845 | "Connection: keep-alive\r\n" |
| 14846 | "Content-Length: 3\r\n\r\n"), |
| 14847 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14848 | }; |
| 14849 | |
| 14850 | MockRead data_reads[] = { |
| 14851 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 14852 | MockRead("hello world"), |
| 14853 | MockRead(SYNCHRONOUS, OK), |
| 14854 | }; |
| 14855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14856 | arraysize(data_writes)); |
| 14857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14858 | |
| 14859 | TestCompletionCallback callback; |
| 14860 | |
| 14861 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14863 | |
| 14864 | rv = callback.WaitForResult(); |
| 14865 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14866 | } |
| 14867 | |
| 14868 | TEST_P(HttpNetworkTransactionTest, |
| 14869 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
| 14870 | ScopedVector<UploadElementReader> element_readers; |
| 14871 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14872 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14873 | |
| 14874 | HttpRequestInfo request; |
| 14875 | request.method = "POST"; |
| 14876 | request.url = GURL("http://www.foo.com/"); |
| 14877 | request.upload_data_stream = &upload_data_stream; |
| 14878 | request.load_flags = 0; |
| 14879 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14880 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14881 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14883 | // Send headers successfully, but get an error while sending the body. |
| 14884 | MockWrite data_writes[] = { |
| 14885 | MockWrite("POST / HTTP/1.1\r\n" |
| 14886 | "Host: www.foo.com\r\n" |
| 14887 | "Connection: keep-alive\r\n" |
| 14888 | "Content-Length: 3\r\n\r\n"), |
| 14889 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14890 | }; |
| 14891 | |
| 14892 | MockRead data_reads[] = { |
| 14893 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14894 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 14895 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 14896 | MockRead("Content-Length: 0\r\n\r\n"), |
| 14897 | MockRead(SYNCHRONOUS, OK), |
| 14898 | }; |
| 14899 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14900 | arraysize(data_writes)); |
| 14901 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14902 | |
| 14903 | TestCompletionCallback callback; |
| 14904 | |
| 14905 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14906 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14907 | |
| 14908 | rv = callback.WaitForResult(); |
| 14909 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14910 | } |
| 14911 | |
| 14912 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
| 14913 | ScopedVector<UploadElementReader> element_readers; |
| 14914 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14915 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14916 | |
| 14917 | HttpRequestInfo request; |
| 14918 | request.method = "POST"; |
| 14919 | request.url = GURL("http://www.foo.com/"); |
| 14920 | request.upload_data_stream = &upload_data_stream; |
| 14921 | request.load_flags = 0; |
| 14922 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14923 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14924 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14925 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14926 | // Send headers successfully, but get an error while sending the body. |
| 14927 | MockWrite data_writes[] = { |
| 14928 | MockWrite("POST / HTTP/1.1\r\n" |
| 14929 | "Host: www.foo.com\r\n" |
| 14930 | "Connection: keep-alive\r\n" |
| 14931 | "Content-Length: 3\r\n\r\n"), |
| 14932 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14933 | }; |
| 14934 | |
| 14935 | MockRead data_reads[] = { |
| 14936 | MockRead("HTTP 0.9 rocks!"), |
| 14937 | MockRead(SYNCHRONOUS, OK), |
| 14938 | }; |
| 14939 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14940 | arraysize(data_writes)); |
| 14941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14942 | |
| 14943 | TestCompletionCallback callback; |
| 14944 | |
| 14945 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14946 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14947 | |
| 14948 | rv = callback.WaitForResult(); |
| 14949 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14950 | } |
| 14951 | |
| 14952 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
| 14953 | ScopedVector<UploadElementReader> element_readers; |
| 14954 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14955 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14956 | |
| 14957 | HttpRequestInfo request; |
| 14958 | request.method = "POST"; |
| 14959 | request.url = GURL("http://www.foo.com/"); |
| 14960 | request.upload_data_stream = &upload_data_stream; |
| 14961 | request.load_flags = 0; |
| 14962 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 14963 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14964 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14965 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14966 | // Send headers successfully, but get an error while sending the body. |
| 14967 | MockWrite data_writes[] = { |
| 14968 | MockWrite("POST / HTTP/1.1\r\n" |
| 14969 | "Host: www.foo.com\r\n" |
| 14970 | "Connection: keep-alive\r\n" |
| 14971 | "Content-Length: 3\r\n\r\n"), |
| 14972 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14973 | }; |
| 14974 | |
| 14975 | MockRead data_reads[] = { |
| 14976 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 14977 | MockRead(SYNCHRONOUS, OK), |
| 14978 | }; |
| 14979 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14980 | arraysize(data_writes)); |
| 14981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14982 | |
| 14983 | TestCompletionCallback callback; |
| 14984 | |
| 14985 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14986 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14987 | |
| 14988 | rv = callback.WaitForResult(); |
| 14989 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14990 | } |
| 14991 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14992 | // Verify that proxy headers are not sent to the destination server when |
| 14993 | // establishing a tunnel for a secure WebSocket connection. |
| 14994 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 14995 | HttpRequestInfo request; |
| 14996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14997 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14998 | AddWebSocketHeaders(&request.extra_headers); |
| 14999 | |
| 15000 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15001 | session_deps_.proxy_service = |
| 15002 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15003 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 15004 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15005 | |
| 15006 | // Since a proxy is configured, try to establish a tunnel. |
| 15007 | MockWrite data_writes[] = { |
| 15008 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15009 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15010 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15011 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15012 | |
| 15013 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15014 | // be issuing -- the final header line contains the credentials. |
| 15015 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15016 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15017 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15018 | "Proxy-Connection: keep-alive\r\n" |
| 15019 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15020 | |
| 15021 | MockWrite( |
| 15022 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15023 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15024 | "Connection: Upgrade\r\n" |
| 15025 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15026 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15027 | "Sec-WebSocket-Version: 13\r\n" |
| 15028 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15029 | }; |
| 15030 | |
| 15031 | // The proxy responds to the connect with a 407, using a persistent |
| 15032 | // connection. |
| 15033 | MockRead data_reads[] = { |
| 15034 | // No credentials. |
| 15035 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15036 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15037 | MockRead("Content-Length: 0\r\n"), |
| 15038 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15039 | |
| 15040 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15041 | |
| 15042 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15043 | MockRead("Upgrade: websocket\r\n"), |
| 15044 | MockRead("Connection: Upgrade\r\n"), |
| 15045 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15046 | }; |
| 15047 | |
| 15048 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15049 | arraysize(data_writes)); |
| 15050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15051 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15053 | |
| 15054 | scoped_ptr<HttpTransaction> trans( |
| 15055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15056 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15057 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15058 | &websocket_stream_create_helper); |
| 15059 | |
| 15060 | { |
| 15061 | TestCompletionCallback callback; |
| 15062 | |
| 15063 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15064 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15065 | |
| 15066 | rv = callback.WaitForResult(); |
| 15067 | EXPECT_EQ(OK, rv); |
| 15068 | } |
| 15069 | |
| 15070 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15071 | ASSERT_TRUE(response); |
| 15072 | ASSERT_TRUE(response->headers.get()); |
| 15073 | EXPECT_EQ(407, response->headers->response_code()); |
| 15074 | |
| 15075 | { |
| 15076 | TestCompletionCallback callback; |
| 15077 | |
| 15078 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15079 | callback.callback()); |
| 15080 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15081 | |
| 15082 | rv = callback.WaitForResult(); |
| 15083 | EXPECT_EQ(OK, rv); |
| 15084 | } |
| 15085 | |
| 15086 | response = trans->GetResponseInfo(); |
| 15087 | ASSERT_TRUE(response); |
| 15088 | ASSERT_TRUE(response->headers.get()); |
| 15089 | |
| 15090 | EXPECT_EQ(101, response->headers->response_code()); |
| 15091 | |
| 15092 | trans.reset(); |
| 15093 | session->CloseAllConnections(); |
| 15094 | } |
| 15095 | |
| 15096 | // Verify that proxy headers are not sent to the destination server when |
| 15097 | // establishing a tunnel for an insecure WebSocket connection. |
| 15098 | // This requires the authentication info to be injected into the auth cache |
| 15099 | // due to crbug.com/395064 |
| 15100 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15101 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15102 | HttpRequestInfo request; |
| 15103 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15104 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15105 | AddWebSocketHeaders(&request.extra_headers); |
| 15106 | |
| 15107 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15108 | session_deps_.proxy_service = |
| 15109 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15110 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 15111 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15112 | |
| 15113 | MockWrite data_writes[] = { |
| 15114 | // Try to establish a tunnel for the WebSocket connection, with |
| 15115 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15116 | // they cannot and will not use the same TCP/IP connection as the |
| 15117 | // preflight HTTP request. |
| 15118 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15119 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15120 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15121 | "Proxy-Connection: keep-alive\r\n" |
| 15122 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15123 | |
| 15124 | MockWrite( |
| 15125 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15126 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15127 | "Connection: Upgrade\r\n" |
| 15128 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15129 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15130 | "Sec-WebSocket-Version: 13\r\n" |
| 15131 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15132 | }; |
| 15133 | |
| 15134 | MockRead data_reads[] = { |
| 15135 | // HTTP CONNECT with credentials. |
| 15136 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15137 | |
| 15138 | // WebSocket connection established inside tunnel. |
| 15139 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15140 | MockRead("Upgrade: websocket\r\n"), |
| 15141 | MockRead("Connection: Upgrade\r\n"), |
| 15142 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15143 | }; |
| 15144 | |
| 15145 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15146 | arraysize(data_writes)); |
| 15147 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15148 | |
| 15149 | session->http_auth_cache()->Add( |
| 15150 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15151 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15152 | |
| 15153 | scoped_ptr<HttpTransaction> trans( |
| 15154 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15155 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15156 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15157 | &websocket_stream_create_helper); |
| 15158 | |
| 15159 | TestCompletionCallback callback; |
| 15160 | |
| 15161 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15162 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15163 | |
| 15164 | rv = callback.WaitForResult(); |
| 15165 | EXPECT_EQ(OK, rv); |
| 15166 | |
| 15167 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15168 | ASSERT_TRUE(response); |
| 15169 | ASSERT_TRUE(response->headers.get()); |
| 15170 | |
| 15171 | EXPECT_EQ(101, response->headers->response_code()); |
| 15172 | |
| 15173 | trans.reset(); |
| 15174 | session->CloseAllConnections(); |
| 15175 | } |
| 15176 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15177 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
| 15178 | ScopedVector<UploadElementReader> element_readers; |
| 15179 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 15180 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 15181 | |
| 15182 | HttpRequestInfo request; |
| 15183 | request.method = "POST"; |
| 15184 | request.url = GURL("http://www.foo.com/"); |
| 15185 | request.upload_data_stream = &upload_data_stream; |
| 15186 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 15187 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15188 | scoped_ptr<HttpTransaction> trans( |
| 15189 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15190 | MockWrite data_writes[] = { |
| 15191 | MockWrite("POST / HTTP/1.1\r\n" |
| 15192 | "Host: www.foo.com\r\n" |
| 15193 | "Connection: keep-alive\r\n" |
| 15194 | "Content-Length: 3\r\n\r\n"), |
| 15195 | MockWrite("foo"), |
| 15196 | }; |
| 15197 | |
| 15198 | MockRead data_reads[] = { |
| 15199 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15200 | MockRead(SYNCHRONOUS, OK), |
| 15201 | }; |
| 15202 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15203 | arraysize(data_writes)); |
| 15204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15205 | |
| 15206 | TestCompletionCallback callback; |
| 15207 | |
| 15208 | EXPECT_EQ(ERR_IO_PENDING, |
| 15209 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15210 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15211 | |
| 15212 | std::string response_data; |
| 15213 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15214 | |
| 15215 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15216 | trans->GetTotalSentBytes()); |
| 15217 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15218 | trans->GetTotalReceivedBytes()); |
| 15219 | } |
| 15220 | |
| 15221 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
| 15222 | ScopedVector<UploadElementReader> element_readers; |
| 15223 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 15224 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 15225 | |
| 15226 | HttpRequestInfo request; |
| 15227 | request.method = "POST"; |
| 15228 | request.url = GURL("http://www.foo.com/"); |
| 15229 | request.upload_data_stream = &upload_data_stream; |
| 15230 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 15231 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15232 | scoped_ptr<HttpTransaction> trans( |
| 15233 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15234 | MockWrite data_writes[] = { |
| 15235 | MockWrite("POST / HTTP/1.1\r\n" |
| 15236 | "Host: www.foo.com\r\n" |
| 15237 | "Connection: keep-alive\r\n" |
| 15238 | "Content-Length: 3\r\n\r\n"), |
| 15239 | MockWrite("foo"), |
| 15240 | }; |
| 15241 | |
| 15242 | MockRead data_reads[] = { |
| 15243 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15244 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15245 | MockRead(SYNCHRONOUS, OK), |
| 15246 | }; |
| 15247 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15248 | arraysize(data_writes)); |
| 15249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15250 | |
| 15251 | TestCompletionCallback callback; |
| 15252 | |
| 15253 | EXPECT_EQ(ERR_IO_PENDING, |
| 15254 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15255 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15256 | |
| 15257 | std::string response_data; |
| 15258 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15259 | |
| 15260 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15261 | trans->GetTotalSentBytes()); |
| 15262 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15263 | trans->GetTotalReceivedBytes()); |
| 15264 | } |
| 15265 | |
| 15266 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
| 15267 | ScopedVector<UploadElementReader> element_readers; |
| 15268 | element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 15269 | ChunkedUploadDataStream upload_data_stream(0); |
| 15270 | |
| 15271 | HttpRequestInfo request; |
| 15272 | request.method = "POST"; |
| 15273 | request.url = GURL("http://www.foo.com/"); |
| 15274 | request.upload_data_stream = &upload_data_stream; |
| 15275 | |
mmenke | 6b3af6e | 2015-09-12 02:06:06 | [diff] [blame] | 15276 | scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15277 | scoped_ptr<HttpTransaction> trans( |
| 15278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15279 | // Send headers successfully, but get an error while sending the body. |
| 15280 | MockWrite data_writes[] = { |
| 15281 | MockWrite("POST / HTTP/1.1\r\n" |
| 15282 | "Host: www.foo.com\r\n" |
| 15283 | "Connection: keep-alive\r\n" |
| 15284 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15285 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15286 | }; |
| 15287 | |
| 15288 | MockRead data_reads[] = { |
| 15289 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15290 | MockRead(SYNCHRONOUS, OK), |
| 15291 | }; |
| 15292 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15293 | arraysize(data_writes)); |
| 15294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15295 | |
| 15296 | TestCompletionCallback callback; |
| 15297 | |
| 15298 | EXPECT_EQ(ERR_IO_PENDING, |
| 15299 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15300 | |
| 15301 | base::RunLoop().RunUntilIdle(); |
| 15302 | upload_data_stream.AppendData("f", 1, false); |
| 15303 | |
| 15304 | base::RunLoop().RunUntilIdle(); |
| 15305 | upload_data_stream.AppendData("oo", 2, true); |
| 15306 | |
| 15307 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15308 | |
| 15309 | std::string response_data; |
| 15310 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15311 | |
| 15312 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15313 | trans->GetTotalSentBytes()); |
| 15314 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15315 | trans->GetTotalReceivedBytes()); |
| 15316 | } |
| 15317 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15318 | } // namespace net |